blob: 9bd780fc1fe37d7c4c39ad8670d5914ba6c9bf58 [file] [log] [blame]
Adam Tkacbfd66c12010-10-01 08:33:29 +00001/* 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
36using namespace rdr;
37using namespace rfb;
38
39UserPasswdGetter *CSecurity::upg = NULL;
Adam Tkac27b2f772010-11-18 13:33:57 +000040#ifdef HAVE_GNUTLS
41UserMsgBox *CSecurityTLS::msg = NULL;
42#endif
Adam Tkacbfd66c12010-10-01 08:33:29 +000043
44StringParameter SecurityClient::secTypes
45("SecurityTypes",
Pierre Ossman906800b2014-09-17 16:39:28 +020046 "Specify which security scheme to use (None, VncAuth, Plain"
47#ifdef HAVE_GNUTLS
48 ", TLSNone, TLSVnc, TLSPlain, X509None, X509Vnc, X509Plain"
49#endif
50 ")",
Adam Tkacbfd66c12010-10-01 08:33:29 +000051#ifdef HAVE_GNUTLS
DRC674bf062011-02-21 13:14:16 +000052 "X509Plain,TLSPlain,X509Vnc,TLSVnc,X509None,TLSNone,VncAuth,None",
Adam Tkacbfd66c12010-10-01 08:33:29 +000053#else
54 "VncAuth,None",
55#endif
56ConfViewer);
57
58CSecurity* SecurityClient::GetCSecurity(U32 secType)
59{
60 assert (CSecurity::upg != NULL); /* (upg == NULL) means bug in the viewer */
Adam Tkac27b2f772010-11-18 13:33:57 +000061#ifdef HAVE_GNUTLS
62 assert (CSecurityTLS::msg != NULL);
63#endif
Adam Tkacbfd66c12010-10-01 08:33:29 +000064
65 if (!IsSupported(secType))
66 goto bail;
67
68 switch (secType) {
69 case secTypeNone: return new CSecurityNone();
70 case secTypeVncAuth: return new CSecurityVncAuth();
71 case secTypeVeNCrypt: return new CSecurityVeNCrypt(this);
72 case secTypePlain: return new CSecurityPlain();
73#ifdef HAVE_GNUTLS
74 case secTypeTLSNone:
75 return new CSecurityStack(secTypeTLSNone, "TLS with no password",
76 new CSecurityTLS(true));
77 case secTypeTLSVnc:
78 return new CSecurityStack(secTypeTLSVnc, "TLS with VNCAuth",
79 new CSecurityTLS(true), new CSecurityVncAuth());
80 case secTypeTLSPlain:
81 return new CSecurityStack(secTypeTLSPlain, "TLS with Username/Password",
82 new CSecurityTLS(true), new CSecurityPlain());
83 case secTypeX509None:
84 return new CSecurityStack(secTypeX509None, "X509 with no password",
85 new CSecurityTLS(false));
86 case secTypeX509Vnc:
Pierre Ossman7d6bf112015-11-11 13:12:45 +010087 return new CSecurityStack(secTypeX509Vnc, "X509 with VNCAuth",
Adam Tkacbfd66c12010-10-01 08:33:29 +000088 new CSecurityTLS(false), new CSecurityVncAuth());
89 case secTypeX509Plain:
90 return new CSecurityStack(secTypeX509Plain, "X509 with Username/Password",
91 new CSecurityTLS(false), new CSecurityPlain());
92#endif
93 }
94
95bail:
96 throw Exception("Security type not supported");
97}
98
Adam Tkac27b2f772010-11-18 13:33:57 +000099void SecurityClient::setDefaults()
100{
101#ifdef HAVE_GNUTLS
102 CSecurityTLS::setDefaults();
103#endif
104}