2015-01-06 14:20:05 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2015-2016 Symless Ltd.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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"
|
2024-12-17 13:48:55 +00:00
|
|
|
#include <mutex>
|
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
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class SecureSocket : public TCPSocket
|
|
|
|
|
{
|
2015-01-06 14:20:05 +00:00
|
|
|
public:
|
2024-10-17 18:04:35 +00:00
|
|
|
SecureSocket(IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::EAddressFamily family);
|
|
|
|
|
SecureSocket(IEventQueue *events, SocketMultiplexer *socketMultiplexer, ArchSocket socket);
|
2024-07-02 19:07:06 +00:00
|
|
|
SecureSocket(SecureSocket const &) = delete;
|
|
|
|
|
SecureSocket(SecureSocket &&) = delete;
|
|
|
|
|
~SecureSocket();
|
|
|
|
|
|
|
|
|
|
SecureSocket &operator=(SecureSocket const &) = delete;
|
|
|
|
|
SecureSocket &operator=(SecureSocket &&) = delete;
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// ISocket overrides
|
|
|
|
|
void close() override;
|
2020-11-03 10:52:56 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// IDataSocket overrides
|
2024-08-07 17:11:29 +00:00
|
|
|
virtual void connect(const NetworkAddress &) override;
|
2015-01-29 15:40:30 +00:00
|
|
|
|
2024-08-07 17:11:29 +00:00
|
|
|
ISocketMultiplexerJob *newJob() override;
|
2024-10-17 18:04:35 +00:00
|
|
|
bool isFatal() const override
|
|
|
|
|
{
|
|
|
|
|
return m_fatal;
|
|
|
|
|
}
|
|
|
|
|
void isFatal(bool b)
|
|
|
|
|
{
|
|
|
|
|
m_fatal = b;
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
bool isSecureReady();
|
|
|
|
|
void secureConnect();
|
|
|
|
|
void secureAccept();
|
|
|
|
|
int secureRead(void *buffer, int size, int &read);
|
|
|
|
|
int secureWrite(const void *buffer, int size, int &wrote);
|
2024-08-07 17:11:29 +00:00
|
|
|
EJobResult doRead() override;
|
|
|
|
|
EJobResult doWrite() override;
|
2024-07-02 19:07:06 +00:00
|
|
|
void initSsl(bool server);
|
2025-01-06 00:55:07 +00:00
|
|
|
bool loadCertificates(std::string &CertFile);
|
2015-01-06 14:20:05 +00:00
|
|
|
|
|
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
// SSL
|
|
|
|
|
void initContext(bool server);
|
|
|
|
|
void createSSL();
|
|
|
|
|
void freeSSL();
|
|
|
|
|
int secureAccept(int s);
|
|
|
|
|
int secureConnect(int s);
|
|
|
|
|
bool showCertificate() const;
|
|
|
|
|
void checkResult(int n, int &retry);
|
|
|
|
|
void disconnect();
|
2025-01-06 00:55:07 +00:00
|
|
|
void formatFingerprint(std::string &fingerprint, bool hex = true, bool separator = true);
|
2024-07-02 19:07:06 +00:00
|
|
|
bool verifyCertFingerprint();
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
ISocketMultiplexerJob *serviceConnect(ISocketMultiplexerJob *, bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *, bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void handleTCPConnected(const Event &event, void *);
|
2015-06-12 21:40:15 +00:00
|
|
|
|
2015-01-06 14:20:05 +00:00
|
|
|
private:
|
2024-12-17 13:48:55 +00:00
|
|
|
// all accesses to m_ssl must be protected by this mutex. The only function that is called
|
|
|
|
|
// from outside SocketMultiplexer thread is close(), so we mostly care about things accessed
|
|
|
|
|
// by it.
|
|
|
|
|
std::mutex ssl_mutex_;
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
Ssl *m_ssl;
|
|
|
|
|
bool m_secureReady;
|
|
|
|
|
bool m_fatal;
|
2015-01-06 14:20:05 +00:00
|
|
|
};
|