libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
sslsocket.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_TLS
13#include <promeki/namespace.h>
14#include <promeki/tcpsocket.h>
15#include <promeki/sslcontext.h>
16#include <promeki/error.h>
17#include <promeki/string.h>
18#include <promeki/list.h>
19#include <promeki/stringlist.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
56class SslSocket : public TcpSocket {
57 PROMEKI_OBJECT(SslSocket, TcpSocket)
58 public:
60 using List = ::promeki::List<SslSocket *>;
61
63 explicit SslSocket(ObjectBase *parent = nullptr);
64
66 ~SslSocket() override;
67
76 void setSslContext(SslContext ctx);
77
79 SslContext sslContext() const { return _ctx; }
80
94 Error startEncryption(const String &hostname = String());
95
104 Error startServerEncryption();
105
121 Error continueHandshake();
122
124 bool isEncrypted() const { return _state == Encrypted; }
125
132 String peerCertificateSubject() const;
133
134 // ----------------------------------------------------
135 // IODevice overrides — proxy through mbedtls_ssl_*
136 // ----------------------------------------------------
137
138 int64_t read(void *data, int64_t maxSize) override;
139 int64_t write(const void *data, int64_t maxSize) override;
140 int64_t bytesAvailable() const override;
141 Error close() override;
142
144 PROMEKI_SIGNAL(encrypted);
145
158 PROMEKI_SIGNAL(sslErrors, StringList);
159
160 private:
161 struct Impl;
162 Impl *_d = nullptr;
163 SslContext _ctx;
164
165 enum SslState {
166 NotEncrypted,
167 Handshaking,
168 Encrypted,
169 Failed
170 };
171 SslState _state = NotEncrypted;
172
173 Error performHandshakeStep();
174};
175
176PROMEKI_NAMESPACE_END
177
178#endif // PROMEKI_ENABLE_TLS