summaryrefslogtreecommitdiff
path: root/modules/mbedtls/ssl_context_mbedtls.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-08-22 20:44:20 +0200
committerGitHub <noreply@github.com>2019-08-22 20:44:20 +0200
commitccf294b92f02af6e60206e220dcf4a8474f73f0a (patch)
tree48d80553c00b7ce76333bb6bbf0e5b8b56b747a4 /modules/mbedtls/ssl_context_mbedtls.cpp
parent79a480a55e1ebada7f2987afeeb2039a39c8666b (diff)
parent17d5b471b9be55a60c366da82629099f6937ec88 (diff)
Merge pull request #31566 from Faless/ssl/fix_custom_cert
Fix StreamPeerSSL connect_to_stream w/ custom cert.
Diffstat (limited to 'modules/mbedtls/ssl_context_mbedtls.cpp')
-rw-r--r--modules/mbedtls/ssl_context_mbedtls.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp
index 014a201f9c..97b5e23f58 100644
--- a/modules/mbedtls/ssl_context_mbedtls.cpp
+++ b/modules/mbedtls/ssl_context_mbedtls.cpp
@@ -94,9 +94,12 @@ Error SSLContextMbedTLS::init_server(int p_transport, int p_authmode, Ref<Crypto
}
Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509CertificateMbedTLS> p_valid_cas) {
+ Error err = _setup(MBEDTLS_SSL_IS_CLIENT, p_transport, p_authmode);
+ ERR_FAIL_COND_V(err != OK, err);
+
X509CertificateMbedTLS *cas = NULL;
- if (certs.is_valid()) {
+ if (p_valid_cas.is_valid()) {
// Locking CA certificates
certs = p_valid_cas;
certs->lock();
@@ -104,12 +107,12 @@ Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509Ce
} else {
// Fall back to default certificates (no need to lock those).
cas = CryptoMbedTLS::get_default_certificates();
- ERR_FAIL_COND_V(cas == NULL, ERR_UNCONFIGURED);
+ if (cas == NULL) {
+ clear();
+ ERR_FAIL_V_MSG(ERR_UNCONFIGURED, "SSL module failed to initialize!");
+ }
}
- Error err = _setup(MBEDTLS_SSL_IS_CLIENT, p_transport, p_authmode);
- ERR_FAIL_COND_V(err != OK, err);
-
// Set valid CAs
mbedtls_ssl_conf_ca_chain(&conf, &(cas->cert), NULL);
mbedtls_ssl_setup(&ssl, &conf);