@@ -70,12 +70,6 @@ struct tls_security_s {
70
70
mbedtls_x509_crl * crl ; /**< Certificate Revocation List */
71
71
mbedtls_x509_crt owncert ; /**< Own certificate(s) */
72
72
mbedtls_pk_context pkey ; /**< Private key for own certificate */
73
-
74
- uint8_t client_random [32 ]; /**< Client random (from Client Hello) */
75
- uint8_t server_random [32 ]; /**< Server random (from Server Hello) */
76
-
77
- uint8_t step ; /**< Random extract step */
78
-
79
73
void * handle ; /**< Handle provided in callbacks (defined by library user) */
80
74
tls_sec_prot_lib_send * send ; /**< Send callback */
81
75
tls_sec_prot_lib_receive * receive ; /**< Receive callback */
@@ -89,9 +83,11 @@ static int tls_sec_prot_lib_ssl_get_timer(void *ctx);
89
83
static int tls_sec_lib_entropy_poll (void * data , unsigned char * output , size_t len , size_t * olen );
90
84
static int tls_sec_prot_lib_ssl_send (void * ctx , const unsigned char * buf , size_t len );
91
85
static int tls_sec_prot_lib_ssl_recv (void * ctx , unsigned char * buf , size_t len );
92
- static int tls_sec_prot_lib_ssl_export_keys (void * ctx , const unsigned char * ms ,
93
- const unsigned char * kb , size_t maclen , size_t keylen , size_t ivlen );
94
- static void tls_sec_prot_lib_random_extract (tls_security_t * sec , const uint8_t * buf , uint16_t len );
86
+ static int tls_sec_prot_lib_ssl_export_keys (void * p_expkey , const unsigned char * ms ,
87
+ const unsigned char * kb , size_t maclen , size_t keylen ,
88
+ size_t ivlen , unsigned char client_random [32 ],
89
+ unsigned char server_random [32 ],
90
+ mbedtls_tls_prf_types tls_prf_type );
95
91
#ifdef TLS_SEC_PROT_LIB_TLS_DEBUG
96
92
static void tls_sec_prot_lib_debug (void * ctx , int level , const char * file , int line , const char * string );
97
93
#endif
@@ -126,7 +122,6 @@ int8_t tls_sec_prot_lib_init(tls_security_t *sec)
126
122
mbedtls_pk_init (& sec -> pkey );
127
123
128
124
sec -> crl = NULL ;
129
- sec -> step = 0 ;
130
125
131
126
if (mbedtls_entropy_add_source (& sec -> entropy , tls_sec_lib_entropy_poll , NULL ,
132
127
128 , MBEDTLS_ENTROPY_SOURCE_WEAK ) < 0 ) {
@@ -331,7 +326,7 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
331
326
#endif
332
327
333
328
// Export keys callback
334
- mbedtls_ssl_conf_export_keys_cb (& sec -> conf , tls_sec_prot_lib_ssl_export_keys , sec );
329
+ mbedtls_ssl_conf_export_keys_ext_cb (& sec -> conf , tls_sec_prot_lib_ssl_export_keys , sec );
335
330
336
331
mbedtls_ssl_conf_min_version (& sec -> conf , MBEDTLS_SSL_MAJOR_VERSION_3 , MBEDTLS_SSL_MAJOR_VERSION_3 );
337
332
mbedtls_ssl_conf_max_version (& sec -> conf , MBEDTLS_SSL_MAJOR_VERSION_3 , MBEDTLS_SSL_MAJOR_VERSION_3 );
@@ -394,9 +389,6 @@ static int tls_sec_prot_lib_ssl_get_timer(void *ctx)
394
389
static int tls_sec_prot_lib_ssl_send (void * ctx , const unsigned char * buf , size_t len )
395
390
{
396
391
tls_security_t * sec = (tls_security_t * )ctx ;
397
-
398
- tls_sec_prot_lib_random_extract (sec , buf , len );
399
-
400
392
return sec -> send (sec -> handle , buf , len );
401
393
}
402
394
@@ -408,74 +400,34 @@ static int tls_sec_prot_lib_ssl_recv(void *ctx, unsigned char *buf, size_t len)
408
400
if (ret == TLS_SEC_PROT_LIB_NO_DATA ) {
409
401
return MBEDTLS_ERR_SSL_WANT_READ ;
410
402
}
411
-
412
- tls_sec_prot_lib_random_extract (sec , buf , len );
413
-
414
403
return ret ;
415
404
}
416
405
417
- static void tls_sec_prot_lib_random_extract (tls_security_t * sec , const uint8_t * buf , uint16_t len )
418
- {
419
- if (sec -> step == 0 ) {
420
- if (* buf ++ != 22 && len < 5 ) {
421
- return ;
422
- }
423
-
424
- buf ++ ; // version
425
- buf ++ ;
426
-
427
- buf ++ ; // length
428
- buf ++ ;
429
-
430
- sec -> step ++ ;
431
-
432
- if (len < 6 ) {
433
- return ;
434
- }
435
- }
436
-
437
- if (sec -> step == 1 ) {
438
- uint8_t * random_ptr ;
439
- if (* buf == 0x01 ) { // Client hello
440
- random_ptr = sec -> client_random ;
441
- } else if (* buf == 0x02 ) { // Server hello
442
- random_ptr = sec -> server_random ;
443
- } else {
444
- return ;
445
- }
446
- buf ++ ;
447
-
448
- buf ++ ; // length
449
- buf ++ ;
450
- buf ++ ;
451
-
452
- buf ++ ; // version
453
- buf ++ ;
454
-
455
- memcpy (random_ptr , buf , 32 );
456
-
457
- sec -> step = 0 ;
458
- }
459
- }
460
-
461
- static int tls_sec_prot_lib_ssl_export_keys (void * ctx , const unsigned char * ms ,
462
- const unsigned char * kb , size_t maclen ,
463
- size_t keylen , size_t ivlen )
406
+ static int tls_sec_prot_lib_ssl_export_keys (void * p_expkey , const unsigned char * ms ,
407
+ const unsigned char * kb , size_t maclen , size_t keylen ,
408
+ size_t ivlen , unsigned char client_random [32 ],
409
+ unsigned char server_random [32 ],
410
+ mbedtls_tls_prf_types tls_prf_type )
464
411
{
465
412
(void ) kb ;
466
413
(void ) maclen ;
467
414
(void ) keylen ;
468
415
(void ) ivlen ;
469
416
470
- tls_security_t * sec = (tls_security_t * )ctx ;
417
+ tls_security_t * sec = (tls_security_t * )p_expkey ;
471
418
472
419
uint8_t eap_tls_key_material [128 ];
473
420
uint8_t random [64 ];
474
- memcpy (random , sec -> client_random , 32 );
475
- memcpy (& random [32 ], sec -> server_random , 32 );
421
+ memcpy (random , client_random , 32 );
422
+ memcpy (& random [32 ], server_random , 32 );
423
+
424
+ int ret = mbedtls_ssl_tls_prf (tls_prf_type , ms , 48 , "client EAP encryption" ,
425
+ random , 64 , eap_tls_key_material , 128 );
476
426
477
- sec -> ssl .handshake -> tls_prf (ms , 48 , "client EAP encryption" ,
478
- random , 64 , eap_tls_key_material , 128 );
427
+ if (ret != 0 ) {
428
+ tr_error ("key material PRF error" );
429
+ return 0 ;
430
+ }
479
431
480
432
sec -> export_keys (sec -> handle , ms , eap_tls_key_material );
481
433
return 0 ;
0 commit comments