Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * Copyright (C) 2010 TigerVNC Team |
| 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include <config.h> |
| 22 | #endif |
| 23 | |
| 24 | #include <assert.h> |
| 25 | #include <rfb/CSecurityNone.h> |
| 26 | #include <rfb/CSecurityStack.h> |
| 27 | #include <rfb/CSecurityVeNCrypt.h> |
| 28 | #include <rfb/CSecurityVncAuth.h> |
| 29 | #include <rfb/CSecurityPlain.h> |
| 30 | #include <rdr/Exception.h> |
| 31 | #include <rfb/Security.h> |
| 32 | #ifdef HAVE_GNUTLS |
| 33 | #include <rfb/CSecurityTLS.h> |
| 34 | #endif |
| 35 | |
| 36 | using namespace rdr; |
| 37 | using namespace rfb; |
| 38 | |
| 39 | UserPasswdGetter *CSecurity::upg = NULL; |
Adam Tkac | 27b2f77 | 2010-11-18 13:33:57 +0000 | [diff] [blame] | 40 | #ifdef HAVE_GNUTLS |
| 41 | UserMsgBox *CSecurityTLS::msg = NULL; |
| 42 | #endif |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 43 | |
| 44 | StringParameter SecurityClient::secTypes |
| 45 | ("SecurityTypes", |
| 46 | "Specify which security scheme to use (None, VncAuth)", |
| 47 | #ifdef HAVE_GNUTLS |
| 48 | "VeNCrypt,X509Plain,TLSPlain,X509Vnc,TLSVnc,X509None,TLSNone,VncAuth,None", |
| 49 | #else |
| 50 | "VncAuth,None", |
| 51 | #endif |
| 52 | ConfViewer); |
| 53 | |
| 54 | CSecurity* SecurityClient::GetCSecurity(U32 secType) |
| 55 | { |
| 56 | assert (CSecurity::upg != NULL); /* (upg == NULL) means bug in the viewer */ |
Adam Tkac | 27b2f77 | 2010-11-18 13:33:57 +0000 | [diff] [blame] | 57 | #ifdef HAVE_GNUTLS |
| 58 | assert (CSecurityTLS::msg != NULL); |
| 59 | #endif |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 60 | |
| 61 | if (!IsSupported(secType)) |
| 62 | goto bail; |
| 63 | |
| 64 | switch (secType) { |
| 65 | case secTypeNone: return new CSecurityNone(); |
| 66 | case secTypeVncAuth: return new CSecurityVncAuth(); |
| 67 | case secTypeVeNCrypt: return new CSecurityVeNCrypt(this); |
| 68 | case secTypePlain: return new CSecurityPlain(); |
| 69 | #ifdef HAVE_GNUTLS |
| 70 | case secTypeTLSNone: |
| 71 | return new CSecurityStack(secTypeTLSNone, "TLS with no password", |
| 72 | new CSecurityTLS(true)); |
| 73 | case secTypeTLSVnc: |
| 74 | return new CSecurityStack(secTypeTLSVnc, "TLS with VNCAuth", |
| 75 | new CSecurityTLS(true), new CSecurityVncAuth()); |
| 76 | case secTypeTLSPlain: |
| 77 | return new CSecurityStack(secTypeTLSPlain, "TLS with Username/Password", |
| 78 | new CSecurityTLS(true), new CSecurityPlain()); |
| 79 | case secTypeX509None: |
| 80 | return new CSecurityStack(secTypeX509None, "X509 with no password", |
| 81 | new CSecurityTLS(false)); |
| 82 | case secTypeX509Vnc: |
| 83 | return new CSecurityStack(secTypeX509None, "X509 with VNCAuth", |
| 84 | new CSecurityTLS(false), new CSecurityVncAuth()); |
| 85 | case secTypeX509Plain: |
| 86 | return new CSecurityStack(secTypeX509Plain, "X509 with Username/Password", |
| 87 | new CSecurityTLS(false), new CSecurityPlain()); |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | bail: |
| 92 | throw Exception("Security type not supported"); |
| 93 | } |
| 94 | |
Adam Tkac | 27b2f77 | 2010-11-18 13:33:57 +0000 | [diff] [blame] | 95 | void SecurityClient::setDefaults() |
| 96 | { |
| 97 | #ifdef HAVE_GNUTLS |
| 98 | CSecurityTLS::setDefaults(); |
| 99 | #endif |
| 100 | } |