Skip to content

Commit c3e37d1

Browse files
committed
extmod/modtls_axtls: Add verify_mode and CERT_NONE constant.
Supporting `verify_mode` and `CERT_NONE` is required for the new `ssl.py` code, as well as `requests` to work. Signed-off-by: Damien George <[email protected]>
1 parent 628a37e commit c3e37d1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

extmod/modtls_axtls.c

+23
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#define PROTOCOL_TLS_CLIENT (0)
4040
#define PROTOCOL_TLS_SERVER (1)
4141

42+
#define CERT_NONE (0)
43+
4244
// This corresponds to an SSLContext object.
4345
typedef struct _mp_obj_ssl_context_t {
4446
mp_obj_base_t base;
@@ -155,6 +157,25 @@ static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
155157
return MP_OBJ_FROM_PTR(self);
156158
}
157159

160+
static void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
161+
if (dest[0] == MP_OBJ_NULL) {
162+
// Load attribute.
163+
if (attr == MP_QSTR_verify_mode) {
164+
// CERT_NONE is the only supported verify_mode value.
165+
dest[0] = MP_OBJ_NEW_SMALL_INT(CERT_NONE);
166+
} else {
167+
// Continue lookup in locals_dict.
168+
dest[1] = MP_OBJ_SENTINEL;
169+
}
170+
} else if (dest[1] != MP_OBJ_NULL) {
171+
// Store attribute.
172+
if (attr == MP_QSTR_verify_mode) {
173+
// CERT_NONE is the only supported verify_mode value, so no need to store anything.
174+
dest[0] = MP_OBJ_NULL;
175+
}
176+
}
177+
}
178+
158179
static void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) {
159180
self->key = key_obj;
160181
self->cert = cert_obj;
@@ -199,6 +220,7 @@ static MP_DEFINE_CONST_OBJ_TYPE(
199220
MP_QSTR_SSLContext,
200221
MP_TYPE_FLAG_NONE,
201222
make_new, ssl_context_make_new,
223+
attr, ssl_context_attr,
202224
locals_dict, &ssl_context_locals_dict
203225
);
204226

@@ -429,6 +451,7 @@ static const mp_rom_map_elem_t mp_module_tls_globals_table[] = {
429451
// Constants.
430452
{ MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_CLIENT), MP_ROM_INT(PROTOCOL_TLS_CLIENT) },
431453
{ MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_SERVER), MP_ROM_INT(PROTOCOL_TLS_SERVER) },
454+
{ MP_ROM_QSTR(MP_QSTR_CERT_NONE), MP_ROM_INT(CERT_NONE) },
432455
};
433456
static MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table);
434457

0 commit comments

Comments
 (0)