Skip to content

Commit c423d37

Browse files
Roytakmichalvasko
authored andcommitted
session openssl BUGFIX enable auto chain building
1 parent bee19e2 commit c423d37

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed

src/session_client_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ nc_client_tls_session_new(int sock, const char *host, int timeout, struct nc_cli
304304
cli_cert = cli_pkey = cert_store = crl_store = NULL;
305305

306306
/* setup config from ctx */
307-
if (nc_tls_setup_config_from_ctx_wrap(tls_ctx, NC_CLIENT, tls_cfg)) {
307+
if (nc_tls_setup_config_from_ctx_wrap(tls_ctx, tls_cfg)) {
308308
goto fail;
309309
}
310310

src/session_mbedtls.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,29 @@ nc_tls_session_destroy_wrap(void *tls_session)
295295
}
296296

297297
void *
298-
nc_tls_config_new_wrap(int UNUSED(side))
298+
nc_tls_config_new_wrap(int side)
299299
{
300+
int r;
300301
mbedtls_ssl_config *tls_cfg;
301302

302303
tls_cfg = malloc(sizeof *tls_cfg);
303304
NC_CHECK_ERRMEM_RET(!tls_cfg, NULL);
304305

305306
mbedtls_ssl_config_init(tls_cfg);
307+
308+
/* set default config data */
309+
if (side == NC_SERVER) {
310+
r = mbedtls_ssl_config_defaults(tls_cfg, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
311+
} else {
312+
r = mbedtls_ssl_config_defaults(tls_cfg, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
313+
}
314+
if (r) {
315+
nc_mbedtls_strerr(NULL, r, "Setting default TLS config failed");
316+
mbedtls_ssl_config_free(tls_cfg);
317+
free(tls_cfg);
318+
return NULL;
319+
}
320+
306321
return tls_cfg;
307322
}
308323

@@ -1143,27 +1158,15 @@ nc_tls_init_ctx_wrap(void *cert, void *pkey, void *cert_store, void *crl_store,
11431158
}
11441159

11451160
int
1146-
nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, int side, void *tls_cfg)
1161+
nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, void *tls_cfg)
11471162
{
1148-
int rc;
1149-
1150-
/* set default config data */
1151-
if (side == NC_SERVER) {
1152-
rc = mbedtls_ssl_config_defaults(tls_cfg, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
1153-
} else {
1154-
rc = mbedtls_ssl_config_defaults(tls_cfg, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
1155-
}
1156-
if (rc) {
1157-
nc_mbedtls_strerr(NULL, rc, "Setting default TLS config failed");
1158-
return 1;
1159-
}
1160-
11611163
/* set config's rng */
11621164
mbedtls_ssl_conf_rng(tls_cfg, mbedtls_ctr_drbg_random, tls_ctx->ctr_drbg);
11631165
/* set config's cert and key */
11641166
mbedtls_ssl_conf_own_cert(tls_cfg, tls_ctx->cert, tls_ctx->pkey);
11651167
/* set config's CA and CRL cert store */
11661168
mbedtls_ssl_conf_ca_chain(tls_cfg, tls_ctx->cert_store, tls_ctx->crl_store);
1169+
11671170
return 0;
11681171
}
11691172

src/session_openssl.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ nc_tls_move_crls_to_store(const X509_STORE *src, X509_STORE *dst)
777777
}
778778

779779
int
780-
nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, int side, void *tls_cfg)
780+
nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, void *tls_cfg)
781781
{
782782
if (SSL_CTX_use_certificate(tls_cfg, tls_ctx->cert) != 1) {
783783
ERR(NULL, "Setting up TLS certificate failed (%s).", ERR_reason_error_string(ERR_get_error()));
@@ -789,11 +789,6 @@ nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, int side, void *tl
789789
return 1;
790790
}
791791

792-
/* disable server-side automatic chain building */
793-
if (side == NC_SERVER) {
794-
SSL_CTX_set_mode(tls_cfg, SSL_MODE_NO_AUTO_CHAIN);
795-
}
796-
797792
if (tls_ctx->crl_store) {
798793
/* move CRLs from crl_store to cert_store, because SSL_CTX can only have one store */
799794
if (nc_tls_move_crls_to_store(tls_ctx->crl_store, tls_ctx->cert_store)) {

src/session_server_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ nc_accept_tls_session(struct nc_session *session, struct nc_server_tls_opts *opt
885885
srv_cert = srv_pkey = cert_store = crl_store = NULL;
886886

887887
/* setup config from ctx */
888-
if (nc_tls_setup_config_from_ctx_wrap(&session->ti.tls.ctx, NC_SERVER, tls_cfg)) {
888+
if (nc_tls_setup_config_from_ctx_wrap(&session->ti.tls.ctx, tls_cfg)) {
889889
goto fail;
890890
}
891891
session->ti.tls.config = tls_cfg;

src/session_wrapper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,10 @@ int nc_tls_init_ctx_wrap(void *cert, void *pkey, void *cert_store, void *crl_sto
451451
* @brief Setup a TLS configuration from a TLS context.
452452
*
453453
* @param[in] tls_ctx TLS context.
454-
* @param[in] side Side of the TLS connection.
455454
* @param[in,out] tls_cfg TLS configuration.
456455
* @return 0 on success, non-zero on fail.
457456
*/
458-
int nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, int side, void *tls_cfg);
457+
int nc_tls_setup_config_from_ctx_wrap(struct nc_tls_ctx *tls_ctx, void *tls_cfg);
459458

460459
/**
461460
* @brief Get the error code from a TLS session's verification.

0 commit comments

Comments
 (0)