2015-01-06 14:20:05 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-11-28 12:51:24 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2015 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2015-01-06 14:20:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-28 12:51:24 +00:00
|
|
|
#include "net/SecurityLevel.h"
|
2015-01-14 17:24:45 +00:00
|
|
|
#include "net/TCPSocket.h"
|
2025-06-18 22:26:02 +00:00
|
|
|
|
|
|
|
|
#include <memory>
|
2024-12-17 13:48:55 +00:00
|
|
|
#include <mutex>
|
2015-01-14 17:24:45 +00:00
|
|
|
|
2025-11-06 22:19:40 +00:00
|
|
|
class Event;
|
2015-01-14 17:24:45 +00:00
|
|
|
class IEventQueue;
|
|
|
|
|
class SocketMultiplexer;
|
2015-01-26 13:23:11 +00:00
|
|
|
class ISocketMultiplexerJob;
|
2025-03-28 03:43:04 +00:00
|
|
|
class QString;
|
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-11-28 12:51:24 +00:00
|
|
|
SecureSocket(
|
2025-06-30 21:36:38 +00:00
|
|
|
IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::AddressFamily family,
|
2024-11-28 12:51:24 +00:00
|
|
|
SecurityLevel securityLevel = SecurityLevel::Encrypted
|
|
|
|
|
);
|
|
|
|
|
SecureSocket(
|
|
|
|
|
IEventQueue *events, SocketMultiplexer *socketMultiplexer, ArchSocket socket,
|
|
|
|
|
SecurityLevel securityLevel = SecurityLevel::Encrypted
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
SecureSocket(SecureSocket const &) = delete;
|
|
|
|
|
SecureSocket(SecureSocket &&) = delete;
|
2025-04-28 01:27:48 +00:00
|
|
|
~SecureSocket() override;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
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
|
2025-04-28 01:27:48 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2025-05-20 02:19:19 +00:00
|
|
|
bool isSecureReady() const;
|
2024-07-02 19:07:06 +00:00
|
|
|
void secureConnect();
|
|
|
|
|
void secureAccept();
|
|
|
|
|
int secureRead(void *buffer, int size, int &read);
|
|
|
|
|
int secureWrite(const void *buffer, int size, int &wrote);
|
2025-07-08 14:16:55 +00:00
|
|
|
JobResult doRead() override;
|
|
|
|
|
JobResult doWrite() override;
|
2024-07-02 19:07:06 +00:00
|
|
|
void initSsl(bool server);
|
2025-05-21 02:00:50 +00:00
|
|
|
bool loadCertificates(const 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-05-20 02:19:19 +00:00
|
|
|
bool verifyCertFingerprint(const QString &FingerprintDatabasePath) const;
|
2015-01-06 14:20:05 +00:00
|
|
|
|
2025-09-24 22:15:00 +00:00
|
|
|
ISocketMultiplexerJob *serviceConnect(ISocketMultiplexerJob *const socket, bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2025-09-24 22:15:00 +00:00
|
|
|
ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *const socket, bool, bool, bool);
|
2015-01-26 13:23:11 +00:00
|
|
|
|
2025-06-18 04:17:54 +00:00
|
|
|
void handleTCPConnected(const Event &event);
|
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_;
|
|
|
|
|
|
2025-06-18 22:26:02 +00:00
|
|
|
std::unique_ptr<Ssl> m_ssl;
|
2025-05-22 22:22:20 +00:00
|
|
|
bool m_secureReady = false;
|
|
|
|
|
bool m_fatal = false;
|
2024-11-28 12:51:24 +00:00
|
|
|
SecurityLevel m_securityLevel = SecurityLevel::Encrypted;
|
2015-01-06 14:20:05 +00:00
|
|
|
};
|