2015-01-06 14:20:05 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2015-2016 Symless 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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2015-01-06 14:20:05 +00:00
|
|
|
*
|
|
|
|
* 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-29 15:40:30 +00:00
|
|
|
#include "net/XSocket.h"
|
2015-01-14 17:24:45 +00:00
|
|
|
|
|
|
|
class IEventQueue;
|
|
|
|
class SocketMultiplexer;
|
2015-01-26 13:23:11 +00:00
|
|
|
class ISocketMultiplexerJob;
|
2015-01-14 17:24:45 +00:00
|
|
|
|
|
|
|
struct Ssl;
|
2015-01-06 14:20:05 +00:00
|
|
|
|
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:
|
2016-12-28 11:50:32 +00:00
|
|
|
SecureSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer);
|
|
|
|
SecureSocket(IEventQueue* events,
|
|
|
|
SocketMultiplexer* socketMultiplexer,
|
|
|
|
ArchSocket socket);
|
|
|
|
~SecureSocket();
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// ISocket overrides
|
|
|
|
void close();
|
2015-01-29 15:40:30 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// IDataSocket overrides
|
|
|
|
virtual void connect(const NetworkAddress&);
|
|
|
|
|
|
|
|
ISocketMultiplexerJob*
|
|
|
|
newJob();
|
|
|
|
bool isFatal() const { return m_fatal; }
|
|
|
|
void isFatal(bool b) { m_fatal = b; }
|
|
|
|
bool isSecureReady();
|
|
|
|
void secureConnect();
|
|
|
|
void secureAccept();
|
|
|
|
int secureRead(void* buffer, int size, int& read);
|
|
|
|
int secureWrite(const void* buffer, int size, int& wrote);
|
|
|
|
EJobResult doRead();
|
|
|
|
EJobResult doWrite();
|
|
|
|
void initSsl(bool server);
|
|
|
|
bool loadCertificates(String& CertFile);
|
2015-01-06 14:20:05 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-28 11:50:32 +00:00
|
|
|
// SSL
|
|
|
|
void initContext(bool server);
|
|
|
|
void createSSL();
|
|
|
|
int secureAccept(int s);
|
|
|
|
int secureConnect(int s);
|
|
|
|
bool showCertificate();
|
|
|
|
void checkResult(int n, int& retry);
|
|
|
|
void showError(const char* reason = NULL);
|
|
|
|
String getError();
|
|
|
|
void disconnect();
|
|
|
|
void formatFingerprint(String& fingerprint,
|
|
|
|
bool hex = true,
|
|
|
|
bool separator = true);
|
|
|
|
bool verifyCertFingerprint();
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
ISocketMultiplexerJob*
|
|
|
|
serviceConnect(ISocketMultiplexerJob*,
|
|
|
|
bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
ISocketMultiplexerJob*
|
|
|
|
serviceAccept(ISocketMultiplexerJob*,
|
|
|
|
bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
void showSecureConnectInfo();
|
|
|
|
void showSecureLibInfo();
|
|
|
|
void showSecureCipherInfo();
|
|
|
|
|
|
|
|
void handleTCPConnected(const Event& event, void*);
|
2015-06-12 21:40:15 +00:00
|
|
|
|
2015-01-06 14:20:05 +00:00
|
|
|
private:
|
2016-12-28 11:50:32 +00:00
|
|
|
Ssl* m_ssl;
|
|
|
|
bool m_secureReady;
|
|
|
|
bool m_fatal;
|
2015-01-06 14:20:05 +00:00
|
|
|
};
|