Skip to content

Commit

Permalink
SSL_CTX_new can fail
Browse files Browse the repository at this point in the history
SSLv23_ methods deprecated
  • Loading branch information
scaprile committed Jul 9, 2024
1 parent a9902b5 commit 96c2955
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -12567,8 +12567,19 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
s_initialised++;
}
MG_DEBUG(("%lu Setting TLS", c->id));
tls->ctx = c->is_client ? SSL_CTX_new(SSLv23_client_method())
: SSL_CTX_new(SSLv23_server_method());
tls->ctx = c->is_client ? SSL_CTX_new(TLS_client_method())
: SSL_CTX_new(TLS_server_method());
if (tls->ctx == NULL) {
mg_error(c, "SSL_CTX_new");
goto fail;
}
#if MG_TLS == MG_TLS_WOLFSSL && !defined(OPENSSL_COMPATIBLE_DEFAULTS)
if (opts->ca.len == 0 || mg_strcmp(opts->ca, mg_str("*")) == 0) {
// Older versions require that either the CA is loaded or SSL_VERIFY_NONE
// explicitly set
SSL_CTX_set_verify(tls->ssl, SSL_VERIFY_NONE, NULL);
}
#endif
#ifdef MG_TLS_SSLKEYLOGFILE
SSL_CTX_set_keylog_callback(tls->ctx, ssl_keylog_cb);
#endif
Expand Down
15 changes: 13 additions & 2 deletions src/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,19 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
s_initialised++;
}
MG_DEBUG(("%lu Setting TLS", c->id));
tls->ctx = c->is_client ? SSL_CTX_new(SSLv23_client_method())
: SSL_CTX_new(SSLv23_server_method());
tls->ctx = c->is_client ? SSL_CTX_new(TLS_client_method())
: SSL_CTX_new(TLS_server_method());
if (tls->ctx == NULL) {
mg_error(c, "SSL_CTX_new");
goto fail;
}
#if MG_TLS == MG_TLS_WOLFSSL && !defined(OPENSSL_COMPATIBLE_DEFAULTS)
if (opts->ca.len == 0 || mg_strcmp(opts->ca, mg_str("*")) == 0) {
// Older versions require that either the CA is loaded or SSL_VERIFY_NONE
// explicitly set
SSL_CTX_set_verify(tls->ssl, SSL_VERIFY_NONE, NULL);
}
#endif
#ifdef MG_TLS_SSLKEYLOGFILE
SSL_CTX_set_keylog_callback(tls->ctx, ssl_keylog_cb);
#endif
Expand Down

0 comments on commit 96c2955

Please sign in to comment.