Deskflow 1.24.0.365
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
SecureSocket.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2015 - 2016 Symless Ltd.
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8#pragma once
9
10#include "net/SecurityLevel.h"
11#include "net/TCPSocket.h"
12
13#include <memory>
14#include <mutex>
15
16class Event;
17class IEventQueue;
20class QString;
21
22struct Ssl;
23
25
28class SecureSocket : public TCPSocket
29{
30public:
32 IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::AddressFamily family,
34 );
36 IEventQueue *events, SocketMultiplexer *socketMultiplexer, ArchSocket socket,
38 );
39 SecureSocket(SecureSocket const &) = delete;
41 ~SecureSocket() override;
42
45
46 // ISocket overrides
47 void close() override;
48
49 // IDataSocket overrides
50 void connect(const NetworkAddress &) override;
51
52 ISocketMultiplexerJob *newJob() override;
53 bool isFatal() const override
54 {
55 return m_fatal;
56 }
57 void isFatal(bool b)
58 {
59 m_fatal = b;
60 }
61 bool isSecureReady() const;
62 void secureConnect();
63 void secureAccept();
64 int secureRead(void *buffer, int size, int &read);
65 int secureWrite(const void *buffer, int size, int &wrote);
66 JobResult doRead() override;
67 JobResult doWrite() override;
68 void initSsl(bool server);
69 bool loadCertificates(const std::string &CertFile);
70
71private:
72 // SSL
73 void initContext(bool server);
74 void createSSL();
75 void freeSSL();
76 int secureAccept(int s);
77 int secureConnect(int s);
78 bool showCertificate() const;
79 void checkResult(int n, int &retry);
80 void disconnect();
81 bool verifyCertFingerprint(const QString &FingerprintDatabasePath) const;
82
83 ISocketMultiplexerJob *serviceConnect(ISocketMultiplexerJob *const socket, bool, bool, bool);
84
85 ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *const socket, bool, bool, bool);
86
87 void handleTCPConnected(const Event &event);
88
89private:
90 // all accesses to m_ssl must be protected by this mutex. The only function that is called
91 // from outside SocketMultiplexer thread is close(), so we mostly care about things accessed
92 // by it.
93 std::mutex ssl_mutex_;
94
95 std::unique_ptr<Ssl> m_ssl;
96 bool m_secureReady = false;
97 bool m_fatal = false;
99};
ArchSocketImpl * ArchSocket
Opaque socket type. An opaque type representing a socket.
Definition IArchNetwork.h:30
SecurityLevel
This enum is used to set how the client and server will communicate.
Definition SecurityLevel.h:14
@ Encrypted
Definition SecurityLevel.h:16
Event.
Definition Event.h:29
AddressFamily
Supported address families.
Definition IArchNetwork.h:58
Event queue interface.
Definition IEventQueue.h:29
Socket multiplexer job.
Definition ISocketMultiplexerJob.h:18
Network address type.
Definition NetworkAddress.h:17
ISocketMultiplexerJob * newJob() override
Definition SecureSocket.cpp:86
~SecureSocket() override
Definition SecureSocket.cpp:67
bool loadCertificates(const std::string &CertFile)
Definition SecureSocket.cpp:291
SecureSocket(IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::AddressFamily family, SecurityLevel securityLevel=SecurityLevel::Encrypted)
Definition SecureSocket.cpp:48
SecureSocket & operator=(SecureSocket const &)=delete
SecureSocket(SecureSocket const &)=delete
void secureConnect()
Definition SecureSocket.cpp:97
bool isSecureReady() const
Definition SecureSocket.cpp:277
int secureWrite(const void *buffer, int size, int &wrote)
Definition SecureSocket.cpp:249
void close() override
Close socket.
Definition SecureSocket.cpp:72
SecureSocket & operator=(SecureSocket &&)=delete
void secureAccept()
Definition SecureSocket.cpp:104
void initSsl(bool server)
Definition SecureSocket.cpp:282
int secureRead(void *buffer, int size, int &read)
Definition SecureSocket.cpp:222
SecureSocket(SecureSocket &&)=delete
bool isFatal() const override
Definition SecureSocket.h:53
void isFatal(bool b)
Definition SecureSocket.h:57
void connect(const NetworkAddress &) override
Connect socket.
Definition SecureSocket.cpp:78
JobResult doRead() override
Definition SecureSocket.cpp:111
JobResult doWrite() override
Definition SecureSocket.cpp:168
Socket multiplexer.
Definition SocketMultiplexer.h:24
JobResult
Definition TCPSocket.h:64
uint32_t read(void *buffer, uint32_t n) override
Read from stream.
Definition TCPSocket.cpp:117
TCPSocket(IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::AddressFamily family=IArchNetwork::AddressFamily::INet)
Definition TCPSocket.cpp:29
Definition SecureSocket.cpp:38