blob: 2ca53449f801a96b058f06c9cf5b4037dd6a9a8f [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 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//
19// SSecurity - class on the server side for handling security handshaking. A
20// derived class for a particular security type overrides the processMsg()
21// method. processMsg() is called first when the security type has been
22// decided on, and will keep being called whenever there is data to read from
23// the client until either it returns false, indicating authentication/security
24// failure, or it returns with done set to true, to indicate success.
25//
26// processMsg() must never block (or at least must never block until the client
27// has been authenticated) - this is to prevent denial of service attacks.
28// Note that the first time processMsg() is called, there is no guarantee that
29// there is any data to read from the SConnection's InStream, but subsequent
30// calls guarantee there is at least one byte which can be read without
31// blocking.
32//
33// getType() should return the secType value corresponding to the SSecurity
34// implementation.
35//
36// failureMessage_.buf can be set to a string which will be passed to the client
37// if processMsg returns false, to indicate the reason for the failure.
38
39#ifndef __RFB_SSECURITY_H__
40#define __RFB_SSECURITY_H__
41
42#include <rfb/util.h>
43
44namespace rfb {
45
46 class SConnection;
47
48 class SSecurity {
49 public:
50 virtual ~SSecurity() {}
51 virtual bool processMsg(SConnection* sc, bool* done)=0;
52 virtual void destroy() { delete this; }
53 virtual int getType() const = 0;
54
55 // getUserName() gets the name of the user attempting authentication. The
56 // storage is owned by the SSecurity object, so a copy must be taken if
57 // necessary. Null may be returned to indicate that there is no user name
58 // for this security type.
59 virtual const char* getUserName() const = 0;
60
61 virtual const char* failureMessage() {return failureMessage_.buf;}
62 protected:
63 CharArray failureMessage_;
64 };
65
66 // SSecurityFactory creates new SSecurity instances for
67 // particular security types.
68 // The instances must be destroyed by calling destroy()
69 // on them when done.
70 class SSecurityFactory {
71 public:
72 virtual ~SSecurityFactory() {}
73 virtual SSecurity* getSSecurity(int secType, bool noAuth=false)=0;
74 };
75
76}
77#endif