Skip to content

Commit

Permalink
Fix use of MOSQ_OPT_TLS_ENGINE being unable to be used.
Browse files Browse the repository at this point in the history
This was due to the openssl ctx not being initialised until starting to connect.

Closes #2537. Thanks to chessing-c4.
  • Loading branch information
ralight committed May 17, 2022
1 parent 127c5e7 commit b6b8039
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -11,6 +11,8 @@ Broker:
Client library:
- Fix threads library detection on Windows under cmake. Bumps the minimum
cmake version to 3.1, which is still ancient.
- Fix use of `MOSQ_OPT_TLS_ENGINE` being unable to be used due to the openssl
ctx not being initialised until starting to connect. Closes #2537.

Clients:
- Fix mosquitto_pub incorrectly reusing topic aliases when reconnecting.
Expand Down
3 changes: 3 additions & 0 deletions include/mosquitto.h
Expand Up @@ -1565,6 +1565,9 @@ libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t
* MOSQ_OPT_TLS_ENGINE - Configure the client for TLS Engine support.
* Pass a TLS Engine ID to be used when creating TLS
* connections. Must be set before <mosquitto_connect>.
* Must be a valid engine, and note that the string will not be used
* until a connection attempt is made so this function will return
* success even if an invalid engine string is passed.
*
* MOSQ_OPT_TLS_KEYFORM - Configure the client to treat the keyfile
* differently depending on its type. Must be set
Expand Down
19 changes: 11 additions & 8 deletions lib/options.c
Expand Up @@ -284,14 +284,17 @@ int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, cons
switch(option){
case MOSQ_OPT_TLS_ENGINE:
#if defined(WITH_TLS) && !defined(OPENSSL_NO_ENGINE)
eng = ENGINE_by_id(value);
if(!eng){
return MOSQ_ERR_INVAL;
}
ENGINE_free(eng); /* release the structural reference from ENGINE_by_id() */
mosq->tls_engine = mosquitto__strdup(value);
if(!mosq->tls_engine){
return MOSQ_ERR_NOMEM;
mosquitto__free(mosq->tls_engine);
if(value){
eng = ENGINE_by_id(value);
if(!eng){
return MOSQ_ERR_INVAL;
}
ENGINE_free(eng); /* release the structural reference from ENGINE_by_id() */
mosq->tls_engine = mosquitto__strdup(value);
if(!mosq->tls_engine){
return MOSQ_ERR_NOMEM;
}
}
return MOSQ_ERR_SUCCESS;
#else
Expand Down

0 comments on commit b6b8039

Please sign in to comment.