blob: e9f379ba7f55b83bba349f27856ca0c47d0294cb [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18// SSecurityVncAuth - legacy VNC authentication protocol.
19// The getPasswd call can be overridden if you wish to store
20// the VncAuth password in an implementation-specific place.
21// Otherwise, the password is read from a BinaryParameter
22// called Password.
23
24#ifndef __RFB_SSECURITYVNCAUTH_H__
25#define __RFB_SSECURITYVNCAUTH_H__
26
Adam Tkac162ac352010-04-23 14:02:43 +000027#include <rfb/Configuration.h>
Michal Srb270a31c2014-11-10 15:32:00 +020028#include <rfb/Password.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029#include <rfb/SSecurity.h>
Adam Tkac5a0caed2010-04-23 13:58:10 +000030#include <rfb/Security.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000031#include <rdr/types.h>
32
33namespace rfb {
34
35 class VncAuthPasswdGetter {
36 public:
Michal Srb519784a2014-11-24 13:53:23 +020037 // getVncAuthPasswd() fills buffer of given password and readOnlyPassword.
38 // If there was no read only password in the file, readOnlyPassword buffer is null.
Michal Srb270a31c2014-11-10 15:32:00 +020039 virtual void getVncAuthPasswd(PlainPasswd *password, PlainPasswd *readOnlyPassword)=0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040 };
41
Adam Tkac162ac352010-04-23 14:02:43 +000042 class VncAuthPasswdParameter : public VncAuthPasswdGetter, BinaryParameter {
43 public:
44 VncAuthPasswdParameter(const char* name, const char* desc, StringParameter* passwdFile_);
Michal Srb270a31c2014-11-10 15:32:00 +020045 virtual void getVncAuthPasswd(PlainPasswd *password, PlainPasswd *readOnlyPassword);
Adam Tkac162ac352010-04-23 14:02:43 +000046 protected:
47 StringParameter* passwdFile;
48 };
49
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000050 class SSecurityVncAuth : public SSecurity {
51 public:
Adam Tkac162ac352010-04-23 14:02:43 +000052 SSecurityVncAuth(void);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000053 virtual bool processMsg(SConnection* sc);
54 virtual int getType() const {return secTypeVncAuth;}
55 virtual const char* getUserName() const {return 0;}
Michal Srb270a31c2014-11-10 15:32:00 +020056 virtual SConnection::AccessRights getAccessRights() const { return accessRights; }
Adam Tkac162ac352010-04-23 14:02:43 +000057 static StringParameter vncAuthPasswdFile;
58 static VncAuthPasswdParameter vncAuthPasswd;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000059 private:
Michal Srb270a31c2014-11-10 15:32:00 +020060 bool verifyResponse(const PlainPasswd &password);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000061 enum {vncAuthChallengeSize = 16};
62 rdr::U8 challenge[vncAuthChallengeSize];
63 rdr::U8 response[vncAuthChallengeSize];
64 bool sentChallenge;
65 int responsePos;
66 VncAuthPasswdGetter* pg;
Michal Srb270a31c2014-11-10 15:32:00 +020067 SConnection::AccessRights accessRights;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000068 };
69}
70#endif