Commit 3bb3e3e7 authored by Ian Craggs's avatar Ian Craggs

Add SNI support, issue 171

parent c2b12985
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
* Ian Craggs - automatic reconnect and offline buffering (send while disconnected) * Ian Craggs - automatic reconnect and offline buffering (send while disconnected)
* Ian Craggs - fix for bug 472250 * Ian Craggs - fix for bug 472250
* Ian Craggs - fix for bug 486548 * Ian Craggs - fix for bug 486548
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -2708,7 +2709,16 @@ int MQTTAsync_connecting(MQTTAsyncs* m) ...@@ -2708,7 +2709,16 @@ int MQTTAsync_connecting(MQTTAsyncs* m)
#if defined(OPENSSL) #if defined(OPENSSL)
if (m->ssl) if (m->ssl)
{ {
if (SSLSocket_setSocketForSSL(&m->c->net, m->c->sslopts) != MQTTASYNC_SUCCESS) int port;
char* hostname;
int setSocketForSSLrc = 0;
hostname = MQTTProtocol_addressPort(m->serverURI, &port);
setSocketForSSLrc = SSLSocket_setSocketForSSL(&m->c->net, m->c->sslopts, hostname);
if (hostname != m->serverURI)
free(hostname);
if (setSocketForSSLrc != MQTTASYNC_SUCCESS)
{ {
if (m->c->session != NULL) if (m->c->session != NULL)
if ((rc = SSL_set_session(m->c->net.ssl, m->c->session)) != 1) if ((rc = SSL_set_session(m->c->net.ssl, m->c->session)) != 1)
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2015 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
* Ian Craggs - fix for bug 459791 - deadlock in WaitForCompletion for bad client * Ian Craggs - fix for bug 459791 - deadlock in WaitForCompletion for bad client
* Ian Craggs - fix for bug 474905 - insufficient synchronization for subscribe, unsubscribe, connect * Ian Craggs - fix for bug 474905 - insufficient synchronization for subscribe, unsubscribe, connect
* Ian Craggs - make it clear that yield and receive are not intended for multi-threaded mode (bug 474748) * Ian Craggs - make it clear that yield and receive are not intended for multi-threaded mode (bug 474748)
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -834,7 +835,16 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o ...@@ -834,7 +835,16 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
#if defined(OPENSSL) #if defined(OPENSSL)
if (m->ssl) if (m->ssl)
{ {
if (SSLSocket_setSocketForSSL(&m->c->net, m->c->sslopts) != MQTTCLIENT_SUCCESS) int port;
char* hostname;
int setSocketForSSLrc = 0;
hostname = MQTTProtocol_addressPort(m->serverURI, &port);
setSocketForSSLrc = SSLSocket_setSocketForSSL(&m->c->net, m->c->sslopts, hostname);
if (hostname != m->serverURI)
free(hostname);
if (setSocketForSSLrc != MQTTCLIENT_SUCCESS)
{ {
if (m->c->session != NULL) if (m->c->session != NULL)
if ((rc = SSL_set_session(m->c->net.ssl, m->c->session)) != 1) if ((rc = SSL_set_session(m->c->net.ssl, m->c->session)) != 1)
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* Ian Craggs - MQTT 3.1.1 support * Ian Craggs - MQTT 3.1.1 support
* Rong Xiang, Ian Craggs - C++ compatibility * Rong Xiang, Ian Craggs - C++ compatibility
* Ian Craggs - fix for bug 479376 * Ian Craggs - fix for bug 479376
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -103,7 +104,7 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int MQTTVersi ...@@ -103,7 +104,7 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int MQTTVersi
#if defined(OPENSSL) #if defined(OPENSSL)
if (ssl) if (ssl)
{ {
if (SSLSocket_setSocketForSSL(&aClient->net, aClient->sslopts) == 1) if (SSLSocket_setSocketForSSL(&aClient->net, aClient->sslopts, addr) == 1)
{ {
rc = SSLSocket_connect(aClient->net.ssl, aClient->net.socket); rc = SSLSocket_connect(aClient->net.ssl, aClient->net.socket);
if (rc == -1) if (rc == -1)
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2014 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Ian Craggs - initial API and implementation and/or initial documentation * Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs, Allan Stockdill-Mander - SSL updates * Ian Craggs, Allan Stockdill-Mander - SSL updates
* Ian Craggs - MQTT 3.1.1 support * Ian Craggs - MQTT 3.1.1 support
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
#if !defined(MQTTPROTOCOLOUT_H) #if !defined(MQTTPROTOCOLOUT_H)
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#define DEFAULT_PORT 1883 #define DEFAULT_PORT 1883
char* MQTTProtocol_addressPort(const char* uri, int* port);
void MQTTProtocol_reconnect(const char* ip_address, Clients* client); void MQTTProtocol_reconnect(const char* ip_address, Clients* client);
#if defined(OPENSSL) #if defined(OPENSSL)
int MQTTProtocol_connect(const char* ip_address, Clients* acClients, int ssl, int MQTTVersion); int MQTTProtocol_connect(const char* ip_address, Clients* acClients, int ssl, int MQTTVersion);
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Ian Craggs - allow compilation for OpenSSL < 1.0 * Ian Craggs - allow compilation for OpenSSL < 1.0
* Ian Craggs - fix for bug #453883 * Ian Craggs - fix for bug #453883
* Ian Craggs - fix for bug #480363, issue 13 * Ian Craggs - fix for bug #480363, issue 13
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -543,7 +544,7 @@ exit: ...@@ -543,7 +544,7 @@ exit:
} }
int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts) int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts, char* hostname)
{ {
int rc = 1; int rc = 1;
...@@ -569,6 +570,9 @@ int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts) ...@@ -569,6 +570,9 @@ int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts)
} }
if ((rc = SSL_set_fd(net->ssl, net->socket)) != 1) if ((rc = SSL_set_fd(net->ssl, net->socket)) != 1)
SSLSocket_error("SSL_set_fd", net->ssl, net->socket, rc); SSLSocket_error("SSL_set_fd", net->ssl, net->socket, rc);
if ((rc = SSL_set_tlsext_host_name(net->ssl, hostname)) != 1)
SSLSocket_error("SSL_set_tlsext_host_name", NULL, net->socket, rc);
} }
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2014 IBM Corp. * Copyright (c) 2009, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* *
* Contributors: * Contributors:
* Ian Craggs, Allan Stockdill-Mander - initial implementation * Ian Craggs, Allan Stockdill-Mander - initial implementation
* Ian Craggs - SNI support
*******************************************************************************/ *******************************************************************************/
#if !defined(SSLSOCKET_H) #if !defined(SSLSOCKET_H)
#define SSLSOCKET_H #define SSLSOCKET_H
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
int SSLSocket_initialize(); int SSLSocket_initialize();
void SSLSocket_terminate(); void SSLSocket_terminate();
int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts); int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts, char* hostname);
int SSLSocket_getch(SSL* ssl, int socket, char* c); int SSLSocket_getch(SSL* ssl, int socket, char* c);
char *SSLSocket_getdata(SSL* ssl, int socket, size_t bytes, size_t* actual_len); char *SSLSocket_getdata(SSL* ssl, int socket, size_t bytes, size_t* actual_len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment