2015-01-06 14:20:05 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2015-01-09 13:46:35 +00:00
|
|
|
* Copyright (C) 2015 Synergy Si Ltd.
|
2015-01-06 14:20:05 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-14 17:24:45 +00:00
|
|
|
#include "net/TCPSocket.h"
|
2015-01-06 14:20:05 +00:00
|
|
|
#include "base/XBase.h"
|
2015-01-14 17:24:45 +00:00
|
|
|
|
|
|
|
class IEventQueue;
|
|
|
|
class SocketMultiplexer;
|
|
|
|
|
|
|
|
struct Ssl;
|
2015-01-06 14:20:05 +00:00
|
|
|
|
|
|
|
//! Generic socket exception
|
|
|
|
XBASE_SUBCLASS(XSecureSocket, XBase);
|
|
|
|
|
2015-01-14 17:24:45 +00:00
|
|
|
|
|
|
|
//! Secure socket
|
2015-01-06 14:20:05 +00:00
|
|
|
/*!
|
2015-01-14 17:24:45 +00:00
|
|
|
A secure socket using SSL.
|
2015-01-06 14:20:05 +00:00
|
|
|
*/
|
2015-01-14 17:24:45 +00:00
|
|
|
class SecureSocket : public TCPSocket {
|
2015-01-06 14:20:05 +00:00
|
|
|
public:
|
2015-01-14 17:24:45 +00:00
|
|
|
SecureSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer);
|
|
|
|
SecureSocket(IEventQueue* events,
|
|
|
|
SocketMultiplexer* socketMultiplexer,
|
|
|
|
ArchSocket socket);
|
2015-01-09 13:46:35 +00:00
|
|
|
~SecureSocket();
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2015-01-14 17:24:45 +00:00
|
|
|
// IStream overrides
|
|
|
|
virtual UInt32 read(void* buffer, UInt32 n);
|
|
|
|
virtual void write(const void* buffer, UInt32 n);
|
|
|
|
virtual bool isReady() const;
|
|
|
|
|
|
|
|
void connectSecureSocket();
|
|
|
|
void acceptSecureSocket();
|
|
|
|
void initSsl(bool server);
|
2015-01-06 14:20:05 +00:00
|
|
|
void loadCertificates(const char* CertFile);
|
|
|
|
|
|
|
|
private:
|
2015-01-14 17:24:45 +00:00
|
|
|
void onConnected();
|
|
|
|
|
|
|
|
// SSL
|
|
|
|
void initContext(bool server);
|
|
|
|
void createSSL();
|
|
|
|
void secureAccept(int s);
|
|
|
|
void secureConnect(int s);
|
2015-01-06 14:20:05 +00:00
|
|
|
void showCertificate();
|
|
|
|
bool checkResult(int n);
|
|
|
|
void showError();
|
|
|
|
void throwError(const char* reason);
|
|
|
|
bool getError();
|
|
|
|
|
|
|
|
private:
|
2015-01-09 13:46:35 +00:00
|
|
|
Ssl* m_ssl;
|
2015-01-06 14:20:05 +00:00
|
|
|
bool m_ready;
|
|
|
|
char* m_error;
|
|
|
|
};
|