reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
AsyncTlsSocketBase.hxx
Go to the documentation of this file.
1
2#if defined(HAVE_CONFIG_H)
3 #include "config.h"
4#endif
5
6#ifdef USE_SSL
7#ifndef ASYNC_TLS_SOCKET_BASE_HXX
8#define ASYNC_TLS_SOCKET_BASE_HXX
9
10#include <asio.hpp>
11#include <asio/ssl.hpp>
12
13#include "AsyncSocketBase.hxx"
14
15namespace reTurn {
16
18{
19public:
20 AsyncTlsSocketBase(asio::io_context& ioService, asio::ssl::context& context, bool validateServerCertificateHostname);
21
27 static bool setupClientSsl(SSL* ssl, const std::string& hostname, bool validateHostname);
28
31 static void logClientHandshakeResult(SSL* ssl, const std::string& hostname, const asio::error_code& ec);
32
33 unsigned int getSocketDescriptor() override;
34
35 asio::error_code bind(const asio::ip::address& address, unsigned short port) override;
36 void connect(const std::string& address, unsigned short port) override;
37
40 void doHandshake(unsigned int timeoutSeconds = 0);
41
42 void transportReceive() override;
43 void transportFramedReceive() override;
44 void transportSend(const StunTuple& destination, std::vector<asio::const_buffer>& buffers) override;
45 void transportClose() override;
46
47 asio::ip::address getSenderEndpointAddress() override;
48 unsigned short getSenderEndpointPort() override;
49
50protected:
51 void handleReadHeader(const asio::error_code& e) override;
52 void handleServerHandshake(const asio::error_code& e) override;
53 void handleTcpResolve(const asio::error_code& ec, const asio::ip::tcp::resolver::results_type& endpoints) override;
54 void handleConnect(const asio::error_code& ec, const asio::ip::tcp::endpoint& endpoint) override;
55 void handleClientHandshake(const asio::error_code& ec, const asio::ip::tcp::endpoint& endpoint) override;
56
57 virtual void onServerHandshakeSuccess() { resip_assert(false); }
58 virtual void onServerHandshakeFailure(const asio::error_code& e) { resip_assert(false); }
59
60 asio::ssl::stream<asio::ip::tcp::socket> mSocket;
61 asio::ip::tcp::resolver mResolver;
62
63private:
64 asio::steady_timer mHandshakeTimer;
65 bool mServerHandshakeDone;
66 std::string mHostname;
67 bool mValidateServerCertificateHostname;
68};
69
70}
71
72#endif
73#endif
74
75/* ====================================================================
76
77 Copyright (c) 2008-2026 SIP Spectrum, Inc. https://www.sipspectrum.com
78 Copyright (c) 2007-2008, Plantronics, Inc.
79 All rights reserved.
80
81 Redistribution and use in source and binary forms, with or without
82 modification, are permitted provided that the following conditions are
83 met:
84
85 1. Redistributions of source code must retain the above copyright
86 notice, this list of conditions and the following disclaimer.
87
88 2. Redistributions in binary form must reproduce the above copyright
89 notice, this list of conditions and the following disclaimer in the
90 documentation and/or other materials provided with the distribution.
91
92 3. Neither the name of Plantronics nor the names of its contributors
93 may be used to endorse or promote products derived from this
94 software without specific prior written permission.
95
96 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
97 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
98 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
99 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
100 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
101 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
102 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
103 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
106 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
107
108 ==================================================================== */
struct ssl_st SSL
#define resip_assert(x)
This file needs to work for both C and C++ code.
asio::ip::address getSenderEndpointAddress() override
asio::ip::tcp::resolver mResolver
asio::ssl::stream< asio::ip::tcp::socket > mSocket
void transportSend(const StunTuple &destination, std::vector< asio::const_buffer > &buffers) override
void handleServerHandshake(const asio::error_code &e) override
void handleReadHeader(const asio::error_code &e) override
virtual void onServerHandshakeFailure(const asio::error_code &e)
static bool setupClientSsl(SSL *ssl, const std::string &hostname, bool validateHostname)
Sets up a client SSL to connect to hostname (a host name or IP address): SNI for a host name,...
unsigned int getSocketDescriptor() override
void handleConnect(const asio::error_code &ec, const asio::ip::tcp::endpoint &endpoint) override
unsigned short getSenderEndpointPort() override
void handleTcpResolve(const asio::error_code &ec, const asio::ip::tcp::resolver::results_type &endpoints) override
static void logClientHandshakeResult(SSL *ssl, const std::string &hostname, const asio::error_code &ec)
Logs a client handshake's outcome: the TLS version and cipher, or why the server certificate was reje...
void doHandshake(unsigned int timeoutSeconds=0)
Starts the server side handshake.
void connect(const std::string &address, unsigned short port) override
asio::error_code bind(const asio::ip::address &address, unsigned short port) override
Note: The following API's are thread safe and queue the request to be handled by the ioService thread...
void handleClientHandshake(const asio::error_code &ec, const asio::ip::tcp::endpoint &endpoint) override
void list()
Definition userAdmin.cxx:66