-
-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #1478 mbedTLS 3.0 is not API compatible with 2.x
- Loading branch information
Showing
6 changed files
with
121 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2020 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2021 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// Copyright 2019 Devolutions <[email protected]> | ||
// | ||
|
@@ -44,13 +44,13 @@ static nni_mtx rng_lock; | |
#endif | ||
|
||
struct nng_tls_engine_conn { | ||
void * tls; // parent conn | ||
void *tls; // parent conn | ||
mbedtls_ssl_context ctx; | ||
}; | ||
|
||
struct nng_tls_engine_config { | ||
mbedtls_ssl_config cfg_ctx; | ||
char * server_name; | ||
char *server_name; | ||
mbedtls_x509_crt ca_certs; | ||
mbedtls_x509_crl crl; | ||
int min_ver; | ||
|
@@ -104,14 +104,29 @@ static struct { | |
int tls; | ||
int nng; | ||
} tls_errs[] = { | ||
#ifdef MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE | ||
{ MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE, NNG_EPEERAUTH }, | ||
#endif | ||
#ifdef MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED | ||
{ MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED, NNG_EPEERAUTH }, | ||
#endif | ||
#ifdef MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED | ||
{ MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED, NNG_EPEERAUTH }, | ||
#endif | ||
#ifdef MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE | ||
{ MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE, NNG_EPEERAUTH }, | ||
#endif | ||
{ MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY, NNG_ECONNREFUSED }, | ||
{ MBEDTLS_ERR_SSL_ALLOC_FAILED, NNG_ENOMEM }, | ||
{ MBEDTLS_ERR_SSL_TIMEOUT, NNG_ETIMEDOUT }, | ||
{ MBEDTLS_ERR_SSL_CONN_EOF, NNG_ECLOSED }, | ||
// MbedTLS 3.0 error codes | ||
#ifdef MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE | ||
{ MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE, NNG_EPEERAUTH }, | ||
#endif | ||
#ifdef MBEDTLS_ERR_SSL_BAD_CERTIFICATE | ||
{ MBEDTLS_ERR_SSL_BAD_CERTIFICATE, NNG_EPEERAUTH }, | ||
#endif | ||
// terminator | ||
{ 0, 0 }, | ||
}; | ||
|
@@ -337,7 +352,7 @@ config_server_name(nng_tls_engine_config *cfg, const char *name) | |
if ((dup = nni_strdup(name)) == NULL) { | ||
return (NNG_ENOMEM); | ||
} | ||
if (cfg->server_name) { | ||
if (cfg->server_name != NULL) { | ||
nni_strfree(cfg->server_name); | ||
} | ||
cfg->server_name = dup; | ||
|
@@ -395,7 +410,7 @@ config_own_cert(nng_tls_engine_config *cfg, const char *cert, const char *key, | |
{ | ||
size_t len; | ||
const uint8_t *pem; | ||
pair * p; | ||
pair *p; | ||
int rv; | ||
|
||
if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { | ||
|
@@ -413,8 +428,13 @@ config_own_cert(nng_tls_engine_config *cfg, const char *cert, const char *key, | |
|
||
pem = (const uint8_t *) key; | ||
len = strlen(key) + 1; | ||
rv = mbedtls_pk_parse_key(&p->key, pem, len, (const uint8_t *) pass, | ||
pass != NULL ? strlen(pass) : 0); | ||
#if MBEDTLS_VERSION_MAJOR < 3 | ||
rv = mbedtls_pk_parse_key(&p->key, pem, len, (const uint8_t *) pass, | ||
pass != NULL ? strlen(pass) : 0); | ||
#else | ||
rv = mbedtls_pk_parse_key(&p->key, pem, len, (const uint8_t *) pass, | ||
pass != NULL ? strlen(pass) : 0, tls_random, NULL); | ||
#endif | ||
if (rv != 0) { | ||
rv = tls_mk_err(rv); | ||
goto err; | ||
|
@@ -448,12 +468,16 @@ config_version(nng_tls_engine_config *cfg, nng_tls_version min_ver, | |
return (NNG_ENOTSUP); | ||
} | ||
switch (min_ver) { | ||
#ifdef MBEDTLS_SSL_MINOR_VERSION_1 | ||
case NNG_TLS_1_0: | ||
v1 = MBEDTLS_SSL_MINOR_VERSION_1; | ||
break; | ||
#endif | ||
#ifdef MBEDTLS_SSL_MINOR_VERSION_2 | ||
case NNG_TLS_1_1: | ||
v1 = MBEDTLS_SSL_MINOR_VERSION_2; | ||
break; | ||
#endif | ||
case NNG_TLS_1_2: | ||
v1 = MBEDTLS_SSL_MINOR_VERSION_3; | ||
break; | ||
|
@@ -462,12 +486,16 @@ config_version(nng_tls_engine_config *cfg, nng_tls_version min_ver, | |
} | ||
|
||
switch (max_ver) { | ||
#ifdef MBEDTLS_SSL_MINOR_VERSION_1 | ||
case NNG_TLS_1_0: | ||
v2 = MBEDTLS_SSL_MINOR_VERSION_1; | ||
break; | ||
#endif | ||
#ifdef MBEDTLS_SSL_MINOR_VERSION_2 | ||
case NNG_TLS_1_1: | ||
v2 = MBEDTLS_SSL_MINOR_VERSION_2; | ||
break; | ||
#endif | ||
case NNG_TLS_1_2: | ||
case NNG_TLS_1_3: // We lack support for 1.3, so treat as 1.2. | ||
v2 = MBEDTLS_SSL_MINOR_VERSION_3; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters