Skip to content

Commit 3f1bdf7

Browse files
committed
session tls BUGFIX init mbedtls lib
Fixes #530
1 parent 0561951 commit 3f1bdf7

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

src/session_client.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,10 @@ nc_client_init(void)
20062006
}
20072007

20082008
#ifdef NC_ENABLED_SSH_TLS
2009+
if (nc_tls_backend_init_wrap()) {
2010+
ERR(NULL, "%s: failed to init the SSL library backend.", __func__);
2011+
return -1;
2012+
}
20092013
if (ssh_init()) {
20102014
ERR(NULL, "%s: failed to init libssh.", __func__);
20112015
return -1;
@@ -2024,6 +2028,7 @@ nc_client_destroy(void)
20242028
nc_client_ch_del_bind(NULL, 0, 0);
20252029
nc_client_ssh_destroy_opts();
20262030
nc_client_tls_destroy_opts();
2031+
nc_tls_backend_destroy_wrap();
20272032
ssh_finalize();
20282033
#endif /* NC_ENABLED_SSH_TLS */
20292034
}

src/session_mbedtls.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@ nc_tls_get_verify_err_str(int err)
194194
return err_buf;
195195
}
196196

197+
int
198+
nc_tls_backend_init_wrap(void)
199+
{
200+
int r;
201+
202+
r = psa_crypto_init();
203+
204+
if (r) {
205+
ERR(NULL, "Failed to initialize PSA crypto (%s).", nc_get_mbedtls_str_err(r));
206+
return -1;
207+
}
208+
209+
return 0;
210+
}
211+
212+
void
213+
nc_tls_backend_destroy_wrap(void)
214+
{
215+
mbedtls_psa_crypto_free();
216+
}
217+
197218
void *
198219
nc_tls_session_new_wrap(void *tls_cfg)
199220
{

src/session_openssl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@
4444
#include <openssl/x509.h>
4545
#include <openssl/x509v3.h>
4646

47+
int
48+
nc_tls_backend_init_wrap(void)
49+
{
50+
/* nothing to do */
51+
return 0;
52+
}
53+
54+
void
55+
nc_tls_backend_destroy_wrap(void)
56+
{
57+
/* nothing to do */
58+
return;
59+
}
60+
4761
void *
4862
nc_tls_session_new_wrap(void *tls_cfg)
4963
{

src/session_server.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,11 @@ nc_server_init(void)
864864
goto error;
865865
}
866866

867+
if (nc_tls_backend_init_wrap()) {
868+
ERR(NULL, "%s: failed to init the SSL library backend.", __func__);
869+
return -1;
870+
}
871+
867872
/* optional for dynamic library, mandatory for static */
868873
if (ssh_init()) {
869874
ERR(NULL, "%s: failed to init libssh.", __func__);
@@ -946,6 +951,7 @@ nc_server_destroy(void)
946951
nc_server_config_ks_keystore(NULL, NC_OP_DELETE);
947952
nc_server_config_ts_truststore(NULL, NC_OP_DELETE);
948953
curl_global_cleanup();
954+
nc_tls_backend_destroy_wrap();
949955
ssh_finalize();
950956

951957
/* close the TLS keylog file */

src/session_wrapper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ struct nc_tls_verify_cb_data {
6969
void *chain; /**< Certificate chain used to verify the client cert. */
7070
};
7171

72+
/**
73+
* @brief Initializes the TLS backend.
74+
*
75+
* Does nothing for OpenSSL, required for MbedTLS version 3.6.0 and later.
76+
*/
77+
int nc_tls_backend_init_wrap(void);
78+
79+
/**
80+
* @brief Destroys the TLS backend.
81+
*
82+
* Does nothing for OpenSSL, required for MbedTLS version 3.6.0 and later.
83+
*/
84+
void nc_tls_backend_destroy_wrap(void);
85+
7286
/**
7387
* @brief Creates a new TLS session from the given configuration.
7488
*

0 commit comments

Comments
 (0)