SNode.C
Loading...
Searching...
No Matches
TLSHandshake.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef CORE_SOCKET_STREAM_TLS_TLSHANDSHAKE_H
21#define CORE_SOCKET_STREAM_TLS_TLSHANDSHAKE_H
22
23#include "core/eventreceiver/ReadEventReceiver.h"
24#include "core/eventreceiver/WriteEventReceiver.h"
25
26#ifndef DOXYGEN_SHOULD_SKIP_THIS
27
28namespace utils {
29 class Timeval;
30}
31
32#include <functional>
33#include <openssl/opensslv.h>
34#include <string>
35
36#if OPENSSL_VERSION_NUMBER >= 0x30000000L
37#include <openssl/types.h>
38#elif OPENSSL_VERSION_NUMBER >= 0x10100000L
39#include <openssl/ossl_typ.h>
40#endif
41
42#endif /* DOXYGEN_SHOULD_SKIP_THIS */
43
44namespace core::socket::stream::tls {
45
47 : public core::eventreceiver::ReadEventReceiver
48 , public core::eventreceiver::WriteEventReceiver {
49 public:
50 static void doHandshake(const std::string& instanceName,
51 SSL* ssl,
52 const std::function<void(void)>& onSuccess,
53 const std::function<void(void)>& onTimeout,
54 const std::function<void(int)>& onStatus,
55 const utils::Timeval& timeout);
56
57 private:
58 TLSHandshake(const std::string& instanceName,
59 SSL* ssl,
60 const std::function<void(void)>& onSuccess,
61 const std::function<void(void)>& onTimeout,
62 const std::function<void(int)>& onStatus,
63 const utils::Timeval& timeout);
64
65 void readEvent() final;
66 void writeEvent() final;
67 void signalEvent(int signum) final;
68
69 void readTimeout() final;
70 void writeTimeout() final;
71
72 void unobservedEvent() final;
73
74 SSL* ssl = nullptr;
75 std::function<void(void)> onSuccess;
76 std::function<void(void)> onTimeout;
77 std::function<void(int)> onStatus;
78
80
81 int fd = -1;
82 };
83
84} // namespace core::socket::stream::tls
85
86#endif // CORE_SOCKET_STREAM_TLS_TLSHANDSHAKE_H
static void doHandshake(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)
TLSHandshake(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)
std::function< void(void)> onTimeout
std::function< void(int)> onStatus
std::function< void(void)> onSuccess