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", |
Pierre Ossman | 906800b | 2014-09-17 16:39:28 +0200 | [diff] [blame] | 46 | "Specify which security scheme to use (None, VncAuth, Plain" |
| 47 | #ifdef HAVE_GNUTLS |
| 48 | ", TLSNone, TLSVnc, TLSPlain, X509None, X509Vnc, X509Plain" |
| 49 | #endif |
| 50 | ")", |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 51 | #ifdef HAVE_GNUTLS |
DRC | 674bf06 | 2011-02-21 13:14:16 +0000 | [diff] [blame] | 52 | "X509Plain,TLSPlain,X509Vnc,TLSVnc,X509None,TLSNone,VncAuth,None", |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 53 | #else |
| 54 | "VncAuth,None", |
| 55 | #endif |
| 56 | ConfViewer); |
| 57 | |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 58 | CSecurity* SecurityClient::GetCSecurity(CConnection* cc, U32 secType) |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 59 | { |
| 60 | assert (CSecurity::upg != NULL); /* (upg == NULL) means bug in the viewer */ |
Adam Tkac | 27b2f77 | 2010-11-18 13:33:57 +0000 | [diff] [blame] | 61 | #ifdef HAVE_GNUTLS |
| 62 | assert (CSecurityTLS::msg != NULL); |
| 63 | #endif |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 64 | |
| 65 | if (!IsSupported(secType)) |
| 66 | goto bail; |
| 67 | |
| 68 | switch (secType) { |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 69 | case secTypeNone: return new CSecurityNone(cc); |
| 70 | case secTypeVncAuth: return new CSecurityVncAuth(cc); |
| 71 | case secTypeVeNCrypt: return new CSecurityVeNCrypt(cc, this); |
| 72 | case secTypePlain: return new CSecurityPlain(cc); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 73 | #ifdef HAVE_GNUTLS |
| 74 | case secTypeTLSNone: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 75 | return new CSecurityStack(cc, secTypeTLSNone, |
| 76 | "TLS with no password", |
| 77 | new CSecurityTLS(cc, true)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 78 | case secTypeTLSVnc: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 79 | return new CSecurityStack(cc, secTypeTLSVnc, |
| 80 | "TLS with VNCAuth", |
| 81 | new CSecurityTLS(cc, true), |
| 82 | new CSecurityVncAuth(cc)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 83 | case secTypeTLSPlain: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 84 | return new CSecurityStack(cc, secTypeTLSPlain, |
| 85 | "TLS with Username/Password", |
| 86 | new CSecurityTLS(cc, true), |
| 87 | new CSecurityPlain(cc)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 88 | case secTypeX509None: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 89 | return new CSecurityStack(cc, secTypeX509None, |
| 90 | "X509 with no password", |
| 91 | new CSecurityTLS(cc, false)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 92 | case secTypeX509Vnc: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 93 | return new CSecurityStack(cc, secTypeX509Vnc, |
| 94 | "X509 with VNCAuth", |
| 95 | new CSecurityTLS(cc, false), |
| 96 | new CSecurityVncAuth(cc)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 97 | case secTypeX509Plain: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 98 | return new CSecurityStack(cc, secTypeX509Plain, |
| 99 | "X509 with Username/Password", |
| 100 | new CSecurityTLS(cc, false), |
| 101 | new CSecurityPlain(cc)); |
Adam Tkac | bfd66c1 | 2010-10-01 08:33:29 +0000 | [diff] [blame] | 102 | #endif |
| 103 | } |
| 104 | |
| 105 | bail: |
| 106 | throw Exception("Security type not supported"); |
| 107 | } |
| 108 | |
Adam Tkac | 27b2f77 | 2010-11-18 13:33:57 +0000 | [diff] [blame] | 109 | void SecurityClient::setDefaults() |
| 110 | { |
| 111 | #ifdef HAVE_GNUTLS |
| 112 | CSecurityTLS::setDefaults(); |
| 113 | #endif |
| 114 | } |