summaryrefslogtreecommitdiff
path: root/extmod/modssl_mbedtls.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-12-12 17:15:24 +1100
committerDamien George <damien@micropython.org>2023-12-12 21:21:54 +1100
commitef996d15b9cbadee591a185f27fb16e90a5d4f5d (patch)
tree595af344ea1e59e1c0813897df3152680acc662b /extmod/modssl_mbedtls.c
parentc9eb6bc6016a7f13cc624b6a4160599ab6b166ff (diff)
extmod/modssl_mbedtls: Make SSLSocket.getpeercert() optional.
And only enable this method when the relevant feature is available in mbedtls. Otherwise, if mbedtls doesn't support getting the peer certificate, this method always returns None and it's confusing why it does that. It's better to remove the method altogether, so the error trying to use it is more obvious. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/modssl_mbedtls.c')
-rw-r--r--extmod/modssl_mbedtls.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/extmod/modssl_mbedtls.c b/extmod/modssl_mbedtls.c
index 3d420759d..cdb4f2b08 100644
--- a/extmod/modssl_mbedtls.c
+++ b/extmod/modssl_mbedtls.c
@@ -554,6 +554,7 @@ cleanup:
mbedtls_raise_error(ret);
}
+#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) {
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
if (!mp_obj_is_true(binary_form)) {
@@ -566,6 +567,7 @@ STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) {
return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert);
+#endif
STATIC mp_obj_t mod_ssl_cipher(mp_obj_t o_in) {
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
@@ -726,7 +728,9 @@ STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = {
#if MICROPY_UNIX_COVERAGE
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&mp_stream_ioctl_obj) },
#endif
+ #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
+ #endif
{ MP_ROM_QSTR(MP_QSTR_cipher), MP_ROM_PTR(&mod_ssl_cipher_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table);