Commit 46ab0422 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

extmod/modussl_mbedtls: Add server_hostname param for wrap_socket().

In CPython, module-level .wrap_socket() function actually doesn't accept
(or document) this param, only SSLContext.wrap_socket() has.
parent ec078af9
...@@ -61,6 +61,7 @@ struct ssl_args { ...@@ -61,6 +61,7 @@ struct ssl_args {
mp_arg_val_t key; mp_arg_val_t key;
mp_arg_val_t cert; mp_arg_val_t cert;
mp_arg_val_t server_side; mp_arg_val_t server_side;
mp_arg_val_t server_hostname;
}; };
STATIC const mp_obj_type_t ussl_socket_type; STATIC const mp_obj_type_t ussl_socket_type;
...@@ -143,10 +144,12 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { ...@@ -143,10 +144,12 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
assert(0); assert(0);
} }
// delme if (args->server_hostname.u_obj != mp_const_none) {
ret = mbedtls_ssl_set_hostname(&o->ssl, "mbed TLS Server 1"); const char *sni = mp_obj_str_get_str(args->server_hostname.u_obj);
if (ret != 0) { ret = mbedtls_ssl_set_hostname(&o->ssl, sni);
assert(0); if (ret != 0) {
assert(0);
}
} }
o->sock = sock; o->sock = sock;
...@@ -260,6 +263,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_ ...@@ -260,6 +263,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
{ MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, { MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
}; };
// TODO: Check that sock implements stream protocol // TODO: Check that sock implements stream protocol
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment