* @param role The role of the client.
* @param sslContext The SSL context for the client.
*/
-TlsStream::TlsStream(const Socket::Ptr& socket, ConnectionRole role, const boost::shared_ptr<SSL_CTX>& sslContext)
+TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const boost::shared_ptr<SSL_CTX>& sslContext)
: SocketEvents(socket, this), m_Eof(false), m_HandshakeOK(false), m_VerifyOK(true), m_ErrorCode(0),
m_ErrorOccurred(false), m_Socket(socket), m_Role(role), m_SendQ(new FIFO()), m_RecvQ(new FIFO()),
m_CurrentAction(TlsActionNone), m_Retry(false)
if (m_Role == RoleServer)
SSL_set_accept_state(m_SSL.get());
- else
+ else {
+#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
+ if (!hostname.IsEmpty())
+ SSL_set_tlsext_host_name(m_SSL.get(), hostname.CStr());
+#endif /* SSL_CTRL_SET_TLSEXT_HOSTNAME */
+
SSL_set_connect_state(m_SSL.get());
+ }
}
TlsStream::~TlsStream(void)
public:
DECLARE_PTR_TYPEDEFS(TlsStream);
- TlsStream(const Socket::Ptr& socket, ConnectionRole role, const boost::shared_ptr<SSL_CTX>& sslContext);
+ TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const boost::shared_ptr<SSL_CTX>& sslContext);
~TlsStream(void);
boost::shared_ptr<X509> GetClientCertificate(void) const;
return 1;
}
- TlsStream::Ptr stream = new TlsStream(client, RoleClient, sslContext);
+ TlsStream::Ptr stream = new TlsStream(client, String(), RoleClient, sslContext);
try {
stream->Handshake();
return 1;
}
- TlsStream::Ptr stream = new TlsStream(client, RoleClient, sslContext);
+ TlsStream::Ptr stream = new TlsStream(client, String(), RoleClient, sslContext);
try {
stream->Handshake();
for (;;) {
try {
Socket::Ptr client = server->Accept();
- Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleServer), LowLatencyScheduler);
+ Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, String(), RoleServer), LowLatencyScheduler);
} catch (const std::exception&) {
Log(LogCritical, "ApiListener", "Cannot accept new connection.");
}
try {
endpoint->SetConnecting(true);
client->Connect(host, port);
- NewClientHandler(client, RoleClient);
+ NewClientHandler(client, endpoint->GetName(), RoleClient);
endpoint->SetConnecting(false);
} catch (const std::exception& ex) {
endpoint->SetConnecting(false);
*
* @param client The new client.
*/
-void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole role)
+void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
{
CONTEXT("Handling new API client connection");
{
ObjectLock olock(this);
try {
- tlsStream = new TlsStream(client, role, m_SSLContext);
+ tlsStream = new TlsStream(client, hostname, role, m_SSLContext);
} catch (const std::exception&) {
Log(LogCritical, "ApiListener", "Cannot create TLS stream from client connection.");
return;
bool AddListener(const String& node, const String& service);
void AddConnection(const Endpoint::Ptr& endpoint);
- void NewClientHandler(const Socket::Ptr& client, ConnectionRole role);
+ void NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role);
void ListenerThreadProc(const Socket::Ptr& server);
WorkQueue m_RelayQueue;