Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* 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 | // |
| 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. |
| 22 | |
| 23 | // processMsg() is called first when the security type has been decided on, and |
| 24 | // will keep being called whenever there is data to read from the client. It |
| 25 | // should return false when it needs more data, or true when the connection has |
| 26 | // been successfully authenticated. In the event of authentication failure an |
| 27 | // AuthFailureException should be thrown - this will result in a "failed" |
| 28 | // security result being sent to the client with the str() from the exception |
| 29 | // being sent as the reason. Any other type of failure should be indicated by |
| 30 | // some other kind of exception which will cause the connection to be aborted. |
| 31 | // |
| 32 | // processMsg() must never block (or at least must never block until the client |
| 33 | // has been authenticated) - this is to prevent denial of service attacks. |
| 34 | // Note that the first time processMsg() is called, there is no guarantee that |
| 35 | // there is any data to read from the SConnection's InStream, but subsequent |
| 36 | // calls guarantee there is at least one byte which can be read without |
| 37 | // blocking. |
| 38 | // |
| 39 | // getType() should return the secType value corresponding to the SSecurity |
| 40 | // implementation. |
| 41 | // |
| 42 | |
| 43 | #ifndef __RFB_SSECURITY_H__ |
| 44 | #define __RFB_SSECURITY_H__ |
| 45 | |
| 46 | #include <rdr/types.h> |
Michal Srb | 8d1ee00 | 2014-11-10 09:15:41 +0200 | [diff] [blame] | 47 | #include <rfb/SConnection.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | #include <rfb/util.h> |
| 49 | #include <list> |
| 50 | |
| 51 | namespace rfb { |
| 52 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 53 | class SSecurity { |
| 54 | public: |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame^] | 55 | SSecurity(SConnection* sc) { this->sc = sc; } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | virtual ~SSecurity() {} |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame^] | 57 | virtual bool processMsg() = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 58 | virtual int getType() const = 0; |
| 59 | |
| 60 | // getUserName() gets the name of the user attempting authentication. The |
| 61 | // storage is owned by the SSecurity object, so a copy must be taken if |
| 62 | // necessary. Null may be returned to indicate that there is no user name |
| 63 | // for this security type. |
| 64 | virtual const char* getUserName() const = 0; |
Michal Srb | 8d1ee00 | 2014-11-10 09:15:41 +0200 | [diff] [blame] | 65 | |
| 66 | virtual SConnection::AccessRights getAccessRights() const { return SConnection::AccessDefault; } |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame^] | 67 | |
| 68 | protected: |
| 69 | SConnection* sc; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 72 | } |
| 73 | #endif |