63
63
#include "mbedtls/asn1.h"
64
64
#endif
65
65
66
+ #if defined(MBEDTLS_CONFIG_FILE )
67
+ #include MBEDTLS_CONFIG_FILE
68
+ #endif
69
+
70
+ #if defined(MBEDTLS_SSL_SESSION_TICKETS ) && defined(MBEDTLS_SSL_TICKET_C )
71
+ #include "mbedtls/ssl_ticket.h"
72
+ #endif
73
+
66
74
#ifndef MICROPY_MBEDTLS_CONFIG_BARE_METAL
67
75
#define MICROPY_MBEDTLS_CONFIG_BARE_METAL (0)
68
76
#endif
@@ -86,6 +94,9 @@ typedef struct _mp_obj_ssl_context_t {
86
94
mbedtls_x509_crt cacert ;
87
95
mbedtls_x509_crt cert ;
88
96
mbedtls_pk_context pkey ;
97
+ #if defined(MBEDTLS_SSL_SESSION_TICKETS ) && defined(MBEDTLS_SSL_TICKET_C )
98
+ mbedtls_ssl_ticket_context ticket ;
99
+ #endif
89
100
int authmode ;
90
101
int * ciphersuites ;
91
102
mp_obj_t handler ;
@@ -340,6 +351,9 @@ static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
340
351
mbedtls_x509_crt_init (& self -> cacert );
341
352
mbedtls_x509_crt_init (& self -> cert );
342
353
mbedtls_pk_init (& self -> pkey );
354
+ #if defined(MBEDTLS_SSL_SESSION_TICKETS ) && defined(MBEDTLS_SSL_TICKET_C )
355
+ mbedtls_ssl_ticket_init (& self -> ticket );
356
+ #endif
343
357
self -> ciphersuites = NULL ;
344
358
self -> handler = mp_const_none ;
345
359
#if MICROPY_PY_SSL_ECDSA_SIGN_ALT
@@ -381,6 +395,14 @@ static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
381
395
mbedtls_ssl_conf_dbg (& self -> conf , mbedtls_debug , NULL );
382
396
#endif
383
397
398
+ #if defined(MBEDTLS_SSL_SESSION_TICKETS ) && defined(MBEDTLS_SSL_TICKET_C )
399
+ ret = mbedtls_ssl_ticket_setup (& self -> ticket , mbedtls_ctr_drbg_random , & self -> ctr_drbg , MBEDTLS_CIPHER_AES_256_GCM , 86400 );
400
+ if (ret != 0 ) {
401
+ mbedtls_raise_error (ret );
402
+ }
403
+ mbedtls_ssl_conf_session_tickets_cb (& self -> conf , mbedtls_ssl_ticket_write , mbedtls_ssl_ticket_parse , & self -> ticket );
404
+ #endif
405
+
384
406
return MP_OBJ_FROM_PTR (self );
385
407
}
386
408
@@ -421,6 +443,9 @@ static void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
421
443
#if MICROPY_PY_SSL_FINALISER
422
444
static mp_obj_t ssl_context___del__ (mp_obj_t self_in ) {
423
445
mp_obj_ssl_context_t * self = MP_OBJ_TO_PTR (self_in );
446
+ #if defined(MBEDTLS_SSL_SESSION_TICKETS ) && defined(MBEDTLS_SSL_TICKET_C )
447
+ mbedtls_ssl_ticket_free (& self -> ticket );
448
+ #endif
424
449
mbedtls_pk_free (& self -> pkey );
425
450
mbedtls_x509_crt_free (& self -> cert );
426
451
mbedtls_x509_crt_free (& self -> cacert );
0 commit comments