Skip to content

Commit d5b9681

Browse files
committed
extmod/modssl_mbedtls: Fix cipher iteration in SSLContext.get_ciphers.
Prior to this commit it would skip every second cipher returned from mbedtls. The corresponding test is also updated and now passes on esp32, rp2, stm32 and unix. Signed-off-by: Damien George <[email protected]>
1 parent 46e833b commit d5b9681

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

extmod/modssl_mbedtls.c

-4
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,6 @@ STATIC mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) {
311311
for (const int *cipher_list = mbedtls_ssl_list_ciphersuites(); *cipher_list; ++cipher_list) {
312312
const char *cipher_name = mbedtls_ssl_get_ciphersuite_name(*cipher_list);
313313
mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str(cipher_name, strlen(cipher_name))));
314-
cipher_list++;
315-
if (!*cipher_list) {
316-
break;
317-
}
318314
}
319315
return list;
320316
}

tests/extmod/ssl_sslcontext_ciphers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
ciphers = ctx.get_ciphers()
1313

1414
for ci in ciphers:
15-
print(ci)
15+
# Only print those ciphers know to exist on all ports.
16+
if ("TLS-ECDHE-ECDSA-WITH-AES" in ci or "TLS-RSA-WITH-AES" in ci) and "CBC" in ci:
17+
print(ci)
1618

1719
ctx.set_ciphers(ciphers[:1])
1820

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384
2+
TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA
23
TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256
4+
TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA
35
TLS-RSA-WITH-AES-256-CBC-SHA256
6+
TLS-RSA-WITH-AES-256-CBC-SHA
47
TLS-RSA-WITH-AES-128-CBC-SHA256
8+
TLS-RSA-WITH-AES-128-CBC-SHA
59
object 'str' isn't a tuple or list
610
(-24192, 'MBEDTLS_ERR_SSL_BAD_CONFIG')

0 commit comments

Comments
 (0)