Skip to content

Commit 0f72c05

Browse files
david-cermakespressif-bot
authored andcommitted
openssl: made verification mode conversion to mbetls modes more strict
1 parent 1c8171c commit 0f72c05

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

components/openssl/platform/ssl_pm.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,36 @@ void ssl_pm_free(SSL *ssl)
249249
static int ssl_pm_reload_crt(SSL *ssl)
250250
{
251251
int ret;
252-
int mode;
252+
int mode = MBEDTLS_SSL_VERIFY_UNSET;
253253
struct ssl_pm *ssl_pm = ssl->ssl_pm;
254254
struct x509_pm *ca_pm = (struct x509_pm *)ssl->client_CA->x509_pm;
255255

256256
struct pkey_pm *pkey_pm = (struct pkey_pm *)ssl->cert->pkey->pkey_pm;
257257
struct x509_pm *crt_pm = (struct x509_pm *)ssl->cert->x509->x509_pm;
258258

259-
if (ssl->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
260-
mode = MBEDTLS_SSL_VERIFY_REQUIRED;
261-
else if (ssl->verify_mode & SSL_VERIFY_PEER)
262-
mode = MBEDTLS_SSL_VERIFY_OPTIONAL;
263-
else if (ssl->verify_mode & SSL_VERIFY_CLIENT_ONCE)
264-
mode = MBEDTLS_SSL_VERIFY_UNSET;
265-
else
266-
mode = MBEDTLS_SSL_VERIFY_NONE;
259+
/* OpenSSL verification modes outline (see `man SSL_set_verify` for more details)
260+
*
261+
* | openssl mode | Server | Client |
262+
* | SSL_VERIFY_NONE | will not send a client certificate request | server certificate which will be checked |
263+
* handshake will be continued regardless |
264+
* | SSL_VERIFY_PEER | depends on SSL_VERIFY_FAIL_IF_NO_PEER_CERT | handshake is terminated if verify fails |
265+
* (unless anonymous ciphers--not supported |
266+
* | SSL_VERIFY_FAIL_IF_NO_PEER_CERT | handshake is terminated if | ignored |
267+
* client cert verify fails | |
268+
*/
269+
if (ssl->method->endpoint == MBEDTLS_SSL_IS_SERVER) {
270+
if (ssl->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
271+
mode = MBEDTLS_SSL_VERIFY_REQUIRED;
272+
else if (ssl->verify_mode & SSL_VERIFY_PEER)
273+
mode = MBEDTLS_SSL_VERIFY_OPTIONAL;
274+
else if (ssl->verify_mode == SSL_VERIFY_NONE)
275+
mode = MBEDTLS_SSL_VERIFY_NONE;
276+
} else if (ssl->method->endpoint == MBEDTLS_SSL_IS_CLIENT) {
277+
if (ssl->verify_mode & SSL_VERIFY_PEER)
278+
mode = MBEDTLS_SSL_VERIFY_REQUIRED;
279+
else if (ssl->verify_mode == SSL_VERIFY_NONE)
280+
mode = MBEDTLS_SSL_VERIFY_NONE;
281+
}
267282

268283
mbedtls_ssl_conf_authmode(&ssl_pm->conf, mode);
269284

0 commit comments

Comments
 (0)