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

MOSQ_OPT_SSL_CTX using SSL_CTX defaults is broken #2463

Closed
tim-nordell-nimbelink opened this issue Feb 18, 2022 · 3 comments
Closed

MOSQ_OPT_SSL_CTX using SSL_CTX defaults is broken #2463

tim-nordell-nimbelink opened this issue Feb 18, 2022 · 3 comments
Labels
Component: libmosquitto Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Milestone

Comments

@tim-nordell-nimbelink
Copy link

tim-nordell-nimbelink commented Feb 18, 2022

I'm pretty sure this is a regression (I haven't tested on older versions of libmosquitto but debugged for my use case) caused by d5aae3e. Basically in the baseline example for this functionality should be:

SSL_CTX *ssl_ctx = SSL_CTX_new(TLS_client_method());
mosquitto_void_option(ctx, MOSQ_OPT_SSL_CTX, ssl_ctx);

and libmosquitto should essentially still work for connecting to TLS. However, it errors out with an error message:

OpenSSL Error[0]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

In net_mosq.c, from commit d5aae3e, the net__init_tls() call is only invoked if mosq->ssl_ctx hasn't been created yet. This is always hit in the case of MOSQ_OPT_SSL_CTX being specified. I think it should always be invoked (e.g. move up the invocation of net__init_tls() one line to just outside of the check for mosq->ssl_ctx already being instantiated) since net__init_tls() has an internal check if it's been already run already. This appears to fix the case of the example above where you instantiate the TLS instance outside of libmosquitto and otherwise leave it to defaults.

(It might need to be always invoked from net__init_ssl_ctx(...) to maintain prior behavior when MOSQ_OPT_SSL_CTX was created; I'm not sure of the interactions with users that aren't using MOSQ_OPT_SSL_CTX_WITH_DEFAULTS.)

Thanks,
Tim

@ralight
Copy link
Contributor

ralight commented Aug 10, 2022

Thanks Tim, that's a good spot. It's now fixed and will be in 2.0.15 shortly.

@ralight ralight added Type: Bug Component: libmosquitto Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. labels Aug 10, 2022
@ralight ralight added this to the 2.0.15 milestone Aug 10, 2022
@tim-nordell-nimbelink
Copy link
Author

tim-nordell-nimbelink commented Aug 10, 2022

Hi @ralight -

The fix looks good. I'd note that the new test cases look like they cleanup the dynamic initialization of the mosquitto library, but not the dynamic initialization of SSL. It could potentially catch a double free (if supported in the allocation library used) in the test cases if libmosquitto accidentally free'd the SSL context created externally if the cleanup of the SSL contexts were added.

-- Tim

@ralight
Copy link
Contributor

ralight commented Aug 12, 2022

Nice idea, I've added that in to the tests.

ralight added a commit that referenced this issue Aug 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: libmosquitto Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants