Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add *_SSLOptions #1463

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IF (NOT PAHO_HIGH_PERFORMANCE)
ENDIF()

IF (WIN32)
SET(LIBS_SYSTEM ws2_32 crypt32 RpcRT4)
SET(LIBS_SYSTEM ws2_32 crypt32 rpcrt4)
ELSEIF (UNIX)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(LIBS_SYSTEM c dl pthread rt)
Expand Down
5 changes: 5 additions & 0 deletions src/MQTTAsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
m->c->sslopts->protos = (const unsigned char*)MQTTStrdup((const char*)options->ssl->protos);
m->c->sslopts->protos_len = options->ssl->protos_len;
}
if (m->c->sslopts->struct_version >= 6)
{
m->c->sslopts->ssl_ctx_cb = options->ssl->ssl_ctx_cb;
m->c->sslopts->ssl_ctx_context = options->ssl->ssl_ctx_context;
}
}
#else
if (options->struct_version != 0 && options->ssl)
Expand Down
17 changes: 16 additions & 1 deletion src/MQTTAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ typedef struct
* 2 means no ssl_error_context, ssl_error_cb
* 3 means no ssl_psk_cb, ssl_psk_context, disableDefaultTrustStore
* 4 means no protos, protos_len
* 5 means no ssl_ctx_cb, ssl_ctx_context
*/
int struct_version;

Expand Down Expand Up @@ -1174,9 +1175,23 @@ typedef struct
* Exists only if struct_version >= 5
*/
unsigned int protos_len;

/**
* Callback function for setting options on SSL context after creation.
* This callback will be called late in context creation, after other parameters have been set
* ssl_ctx will receive the SSL_CTX* of the context just created and setup
* Exists only if struct_version >= 6
*/
void (*ssl_ctx_cb) (void* ssl_ctx, void* ssl_ctx_context);

/**
* Application-specific context for ssl_ctx_cb
* Exists only if struct_version >= 6
*/
void* ssl_ctx_context;
} MQTTAsync_SSLOptions;

#define MQTTAsync_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 5, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0 }
#define MQTTAsync_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 6, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL }

/** Utility structure where name/value pairs are needed */
typedef struct
Expand Down
5 changes: 5 additions & 0 deletions src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,11 @@ static MQTTResponse MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectO
m->c->sslopts->protos = options->ssl->protos;
m->c->sslopts->protos_len = options->ssl->protos_len;
}
if (m->c->sslopts->struct_version >= 6)
{
m->c->sslopts->ssl_ctx_cb = options->ssl->ssl_ctx_cb;
m->c->sslopts->ssl_ctx_context = options->ssl->ssl_ctx_context;
}
}
#endif

Expand Down
17 changes: 16 additions & 1 deletion src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ typedef struct
* 2 means no ssl_error_context, ssl_error_cb
* 3 means no ssl_psk_cb, ssl_psk_context, disableDefaultTrustStore
* 4 means no protos, protos_len
* 5 means no ssl_ctx_cb, ssl_ctx_context
*/
int struct_version;

Expand Down Expand Up @@ -777,9 +778,23 @@ typedef struct
* Exists only if struct_version >= 5
*/
unsigned int protos_len;

/**
* Callback function for setting options on SSL context after creation.
* This callback will be called late in context creation, after other parameters have been set
* ssl_ctx will receive the SSL_CTX* of the context just created and setup
* Exists only if struct_version >= 6
*/
void (*ssl_ctx_cb) (void* ssl_ctx, void* ssl_ctx_context);

/**
* Application-specific context for ssl_ctx_cb
* Exists only if struct_version >= 6
*/
void* ssl_ctx_context;
} MQTTClient_SSLOptions;

#define MQTTClient_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 5, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0 }
#define MQTTClient_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 6, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL}

/**
* MQTTClient_libraryInfo is used to store details relating to the currently used
Expand Down
5 changes: 5 additions & 0 deletions src/SSLSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ int SSLSocket_createContext(networkHandles* net, MQTTClient_SSLOptions* opts)

SSL_CTX_set_mode(net->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);

/* Finally, allow the client to have the last say in context setup */
if (opts->ssl_ctx_cb != NULL)
{
opts->ssl_ctx_cb(net->ctx, opts->ssl_ctx_context);
}
goto exit;
free_ctx:
SSL_CTX_free(net->ctx);
Expand Down