barrier/src/lib/plugin/ns/SecureSocket.h

96 lines
2.5 KiB
C
Raw Normal View History

/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2015-2016 Symless Ltd.
*
* 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 LICENSE 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
#include "net/TCPSocket.h"
#include "net/XSocket.h"
class IEventQueue;
class SocketMultiplexer;
2015-01-26 13:23:11 +00:00
class ISocketMultiplexerJob;
struct Ssl;
//! Secure socket
/*!
A secure socket using SSL.
*/
class SecureSocket : public TCPSocket {
public:
SecureSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer);
SecureSocket(IEventQueue* events,
SocketMultiplexer* socketMultiplexer,
ArchSocket socket);
~SecureSocket();
// ISocket overrides
void close();
// IDataSocket overrides
virtual void connect(const NetworkAddress&);
ISocketMultiplexerJob*
newJob();
2015-01-26 13:23:11 +00:00
void secureConnect();
void secureAccept();
EJobResult doRead();
EJobResult doWrite();
bool isFatal() const { return m_fatal; }
void isFatal(bool b) { m_fatal = b; }
2015-01-26 13:23:11 +00:00
bool isSecureReady();
int secureRead(void* buffer, int size, int& read);
int secureWrite(const void* buffer, int size, int& wrote);
void initSsl(bool server);
2015-04-14 13:03:43 +00:00
bool loadCertificates(String& CertFile);
private:
// 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);
2015-04-14 12:44:10 +00:00
String getError();
void disconnect();
void formatFingerprint(String& fingerprint,
bool hex = true,
bool separator = true);
bool verifyCertFingerprint();
2015-01-26 13:23:11 +00:00
ISocketMultiplexerJob*
serviceConnect(ISocketMultiplexerJob*,
bool, bool, bool);
ISocketMultiplexerJob*
serviceAccept(ISocketMultiplexerJob*,
bool, bool, bool);
void showSecureConnectInfo();
void showSecureLibInfo();
void showSecureCipherInfo();
void handleTCPConnected(const Event& event, void*);
private:
Ssl* m_ssl;
2015-01-26 13:23:11 +00:00
bool m_secureReady;
bool m_fatal;
};