Skip to content

Commit 63c72d3

Browse files
committed
crypto/openssl-wrapper: fix SSL error code mapping
Map mbedtls error codes to OpenSSL standard return codes in SSL_connect/SSL_do_handshake: - Return 1 on success - Return 0 on controlled shutdown - Return -1 on fatal error (was returning mbedtls error codes) This aligns the return values with OpenSSL specification where SSL_get_error() should be called to get the actual error reason. Signed-off-by: makejian <makejian@xiaomi.com>
1 parent 9c43ced commit 63c72d3

File tree

1 file changed

+9
-5
lines changed
  • crypto/openssl_mbedtls_wrapper/mbedtls

1 file changed

+9
-5
lines changed

crypto/openssl_mbedtls_wrapper/mbedtls/ssl_pm.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,21 @@ int ssl_pm_handshake(SSL *ssl)
368368
}
369369

370370
/* OpenSSL return codes:
371-
* 0 = did not complete, but may be retried
371+
* 0 = The TLS/SSL handshake was not successful but was shut down
372+
* controlled and by the specifications of the TLS/SSL protocol.
372373
* 1 = successfully completed
373-
* <0 = death
374+
* <0 = The TLS/SSL handshake was not successful because a fatal error
375+
* occurred either at the protocol level or a connection failure
376+
* occurred.
374377
*/
375378

376379
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)
377380
{
378-
ssl->err = ret;
381+
ssl->err = (ret == MBEDTLS_ERR_SSL_WANT_READ) ? SSL_ERROR_WANT_READ :
382+
SSL_ERROR_WANT_WRITE;
379383
SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL,
380384
"mbedtls_ssl_handshake() return -0x%x", -ret);
381-
return 0; /* OpenSSL: did not complete but may be retried */
385+
return -1;
382386
}
383387

384388
if (ret == 0)
@@ -397,7 +401,7 @@ int ssl_pm_handshake(SSL *ssl)
397401
{
398402
ssl->err = ret == MBEDTLS_ERR_SSL_WANT_READ;
399403

400-
return 0;
404+
return -1;
401405
}
402406

403407
SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL,

0 commit comments

Comments
 (0)