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.
This commit is contained in:
Paul Sokolovsky 2016-09-23 01:44:23 +03:00
parent ec078af985
commit 46ab042230
1 changed files with 8 additions and 4 deletions

View File

@ -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,11 +144,13 @@ 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);
ret = mbedtls_ssl_set_hostname(&o->ssl, sni);
if (ret != 0) { if (ret != 0) {
assert(0); assert(0);
} }
}
o->sock = sock; o->sock = sock;
mbedtls_ssl_set_bio(&o->ssl, &o->sock, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL); mbedtls_ssl_set_bio(&o->ssl, &o->sock, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL);
@ -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