8000 extmod/modussl_mbedtls: Add server_hostname param for wrap_socket(). · sparkfun/circuitpython@46ab042 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46ab042

Browse files
committed
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.
1 parent ec078af commit 46ab042

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

extmod/modussl_mbedtls.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct ssl_args {
6161
mp_arg_val_t key;
6262
mp_arg_val_t cert;
6363
mp_arg_val_t server_side;
64+
mp_arg_val_t server_hostname;
6465
};
6566

6667
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) {
143144
assert(0);
144145
}
145146

146-
// delme
147-
ret = mbedtls_ssl_set_hostname(&o->ssl, "mbed TLS Server 1");
148-
if (ret != 0) {
149-
assert(0);
147+
if (args->server_hostname.u_obj != mp_const_none) {
148+
const char *sni = mp_obj_str_get_str(args->server_hostname.u_obj);
149+
ret = mbedtls_ssl_set_hostname(&o->ssl, sni);
150+
if (ret != 0) {
151+
assert(0);
152+
}
150153
}
151154

152155
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_
260263
{ MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
261264
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
262265
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
266+
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
263267
};
264268

265269
// TODO: Check that sock implements stream protocol

0 commit comments

Comments
 (0)
0