Skip to content

Commit 980121b

Browse files
committed
Lift TLS 1.2 limit for verify_none, newer MbedTLS.
Fixed in MbedTLS 3.6.1, only limit affected versions to TLS 1.2. Signed-off-by: Peter M <petermm@gmail.com>
1 parent f660ded commit 980121b

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646
- Added `init:get_argument/1`, `init:get_plain_arguments/0` and `init:notify_when_started/1`
4747
- Added `application:get_env/2`
4848
- Added CodeQL analysis to esp32, stm32, pico, and wasm workflows
49+
- Lift TLS 1.2 limit for requests with verify_none, for newer MbedTLS versions.
4950

5051
### Changed
5152

src/libAtomVM/otp_ssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ static term nif_ssl_conf_authmode(Context *ctx, int argc, term argv[])
457457

458458
// MBEDTLS_SSL_VERIFY_NONE and MBEDTLS_SSL_VERIFY_OPTIONAL do not work with TLS 1.3
459459
// https://github.com/Mbed-TLS/mbedtls/issues/7075
460+
// Fixed in 3.6.1 https://github.com/Mbed-TLS/mbedtls/releases/tag/mbedtls-3.6.1
461+
// "Fixed by adding support for optional/none with TLS 1.3 as well."
460462
if (authmode != MBEDTLS_SSL_VERIFY_REQUIRED) {
461-
#if MBEDTLS_VERSION_NUMBER >= 0x03020000
463+
#if MBEDTLS_VERSION_NUMBER >= 0x03020000 && MBEDTLS_VERSION_NUMBER < 0x03060100
462464
mbedtls_ssl_conf_max_tls_version(&rsrc_obj->config, MBEDTLS_SSL_VERSION_TLS1_2);
463-
#else
464-
mbedtls_ssl_conf_max_version(&rsrc_obj->config, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3);
465465
#endif
466466
}
467467

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
CONFIG_PARTITION_TABLE_CUSTOM=y
22
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
33
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
4+
CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y
5+
CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y

src/platforms/esp32/test/main/test_erl_sources/test_ssl.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
start() ->
2525
% start SSL
26+
ok = ssl:start(),
27+
ok = test_print_client_capabilities(),
28+
ok = ssl:stop(),
2629
Entropy = ssl:nif_entropy_init(),
2730
CtrDrbg = ssl:nif_ctr_drbg_init(),
2831
ok = ssl:nif_ctr_drbg_seed(CtrDrbg, Entropy, <<"AtomVM">>),
@@ -59,6 +62,29 @@ start() ->
5962
ok = socket:close(Socket),
6063
ok.
6164

65+
test_print_client_capabilities() ->
66+
{ok, SSLSocket} = ssl:connect("check-tls.akamai.io", 443, [
67+
{verify, verify_none}, {active, false}, {binary, true}
68+
]),
69+
UserAgent = erlang:system_info(machine),
70+
ok = ssl:send(SSLSocket, [
71+
<<"GET /v1/tlsinfo.json HTTP/1.1\r\nHost: check-tls.akamai.io\r\nUser-Agent: ">>,
72+
UserAgent,
73+
<<"\r\n\r\n">>
74+
]),
75+
ok = recv_helper(SSLSocket, 0),
76+
ok = ssl:close(SSLSocket),
77+
ok.
78+
79+
recv_helper(SSLSocket, Bytes) ->
80+
case ssl:recv(SSLSocket, Bytes) of
81+
{ok, Data} ->
82+
io:format("~s~n", [Data]),
83+
recv_helper(SSLSocket, 0);
84+
{error, _Reason} ->
85+
ok
86+
end.
87+
6288
handshake_loop(SSLContext, Socket) ->
6389
case ssl:nif_handshake_step(SSLContext) of
6490
ok ->

src/platforms/esp32/test/sdkconfig.defaults

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ CONFIG_ESP_INT_WDT_TIMEOUT_MS=10000
55
CONFIG_ETH_USE_OPENETH=y
66
CONFIG_AVM_RTC_SLOW_MAX_SIZE=1024
77
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
8+
CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y
9+
CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y

tests/libs/estdlib/test_ssl.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ is_ssl_available() ->
4848
end.
4949

5050
test_ssl() ->
51+
ok = ssl:start(),
52+
ok = test_print_client_capabilities(),
53+
ok = ssl:stop(),
5154
ok = ssl:start(),
5255
ok = test_start_twice(),
5356
ok = test_connect_close(),
@@ -57,6 +60,29 @@ test_ssl() ->
5760
ok = ssl:stop(),
5861
ok.
5962

63+
test_print_client_capabilities() ->
64+
{ok, SSLSocket} = ssl:connect("check-tls.akamai.io", 443, [
65+
{verify, verify_none}, {active, false}, {binary, true}
66+
]),
67+
UserAgent = erlang:system_info(machine),
68+
ok = ssl:send(SSLSocket, [
69+
<<"GET /v1/tlsinfo.json HTTP/1.1\r\nHost: check-tls.akamai.io\r\nUser-Agent: ">>,
70+
UserAgent,
71+
<<"\r\n\r\n">>
72+
]),
73+
ok = recv_helper(SSLSocket, 0),
74+
ok = ssl:close(SSLSocket),
75+
ok.
76+
77+
recv_helper(SSLSocket, Bytes) ->
78+
case ssl:recv(SSLSocket, Bytes) of
79+
{ok, Data} ->
80+
io:format("~s~n", [Data]),
81+
recv_helper(SSLSocket, 0);
82+
{error, _Reason} ->
83+
ok
84+
end.
85+
6086
test_start_twice() ->
6187
ok = ssl:start().
6288

0 commit comments

Comments
 (0)