@@ -92,8 +92,8 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
92
92
return ngtcp2_crypto_aead_init (aead , (void * )EVP_aead_aes_128_gcm ());
93
93
}
94
94
95
- static const EVP_AEAD * crypto_ssl_get_aead ( SSL * ssl ) {
96
- switch (SSL_CIPHER_get_id ( SSL_get_current_cipher ( ssl )) ) {
95
+ static const EVP_AEAD * crypto_cipher_id_get_aead ( uint32_t cipher_id ) {
96
+ switch (cipher_id ) {
97
97
case TLS1_CK_AES_128_GCM_SHA256 :
98
98
return EVP_aead_aes_128_gcm ();
99
99
case TLS1_CK_AES_256_GCM_SHA384 :
@@ -105,8 +105,8 @@ static const EVP_AEAD *crypto_ssl_get_aead(SSL *ssl) {
105
105
}
106
106
}
107
107
108
- static uint64_t crypto_ssl_get_aead_max_encryption ( SSL * ssl ) {
109
- switch (SSL_CIPHER_get_id ( SSL_get_current_cipher ( ssl )) ) {
108
+ static uint64_t crypto_cipher_id_get_aead_max_encryption ( uint32_t cipher_id ) {
109
+ switch (cipher_id ) {
110
110
case TLS1_CK_AES_128_GCM_SHA256 :
111
111
case TLS1_CK_AES_256_GCM_SHA384 :
112
112
return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM ;
@@ -117,8 +117,9 @@ static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
117
117
}
118
118
}
119
119
120
- static uint64_t crypto_ssl_get_aead_max_decryption_failure (SSL * ssl ) {
121
- switch (SSL_CIPHER_get_id (SSL_get_current_cipher (ssl ))) {
120
+ static uint64_t
121
+ crypto_cipher_id_get_aead_max_decryption_failure (uint32_t cipher_id ) {
122
+ switch (cipher_id ) {
122
123
case TLS1_CK_AES_128_GCM_SHA256 :
123
124
case TLS1_CK_AES_256_GCM_SHA384 :
124
125
return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM ;
@@ -129,8 +130,9 @@ static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
129
130
}
130
131
}
131
132
132
- static const ngtcp2_crypto_boringssl_cipher * crypto_ssl_get_hp (SSL * ssl ) {
133
- switch (SSL_CIPHER_get_id (SSL_get_current_cipher (ssl ))) {
133
+ static const ngtcp2_crypto_boringssl_cipher *
134
+ crypto_cipher_id_get_hp (uint32_t cipher_id ) {
135
+ switch (cipher_id ) {
134
136
case TLS1_CK_AES_128_GCM_SHA256 :
135
137
return & crypto_cipher_aes_128 ;
136
138
case TLS1_CK_AES_256_GCM_SHA384 :
@@ -142,8 +144,8 @@ static const ngtcp2_crypto_boringssl_cipher *crypto_ssl_get_hp(SSL *ssl) {
142
144
}
143
145
}
144
146
145
- static const EVP_MD * crypto_ssl_get_md ( SSL * ssl ) {
146
- switch (SSL_CIPHER_get_id ( SSL_get_current_cipher ( ssl )) ) {
147
+ static const EVP_MD * crypto_cipher_id_get_md ( uint32_t cipher_id ) {
148
+ switch (cipher_id ) {
147
149
case TLS1_CK_AES_128_GCM_SHA256 :
148
150
case TLS1_CK_CHACHA20_POLY1305_SHA256 :
149
151
return EVP_sha256 ();
@@ -154,15 +156,47 @@ static const EVP_MD *crypto_ssl_get_md(SSL *ssl) {
154
156
}
155
157
}
156
158
159
+ static int supported_cipher_id (uint32_t cipher_id ) {
160
+ switch (cipher_id ) {
161
+ case TLS1_CK_AES_128_GCM_SHA256 :
162
+ case TLS1_CK_AES_256_GCM_SHA384 :
163
+ case TLS1_CK_CHACHA20_POLY1305_SHA256 :
164
+ return 1 ;
165
+ default :
166
+ return 0 ;
167
+ }
168
+ }
169
+
170
+ static ngtcp2_crypto_ctx * crypto_ctx_cipher_id (ngtcp2_crypto_ctx * ctx ,
171
+ uint32_t cipher_id ) {
172
+ ngtcp2_crypto_aead_init (& ctx -> aead ,
173
+ (void * )crypto_cipher_id_get_aead (cipher_id ));
174
+ ctx -> md .native_handle = (void * )crypto_cipher_id_get_md (cipher_id );
175
+ ctx -> hp .native_handle = (void * )crypto_cipher_id_get_hp (cipher_id );
176
+ ctx -> max_encryption = crypto_cipher_id_get_aead_max_encryption (cipher_id );
177
+ ctx -> max_decryption_failure =
178
+ crypto_cipher_id_get_aead_max_decryption_failure (cipher_id );
179
+
180
+ return ctx ;
181
+ }
182
+
157
183
ngtcp2_crypto_ctx * ngtcp2_crypto_ctx_tls (ngtcp2_crypto_ctx * ctx ,
158
184
void * tls_native_handle ) {
159
185
SSL * ssl = tls_native_handle ;
160
- ngtcp2_crypto_aead_init (& ctx -> aead , (void * )crypto_ssl_get_aead (ssl ));
161
- ctx -> md .native_handle = (void * )crypto_ssl_get_md (ssl );
162
- ctx -> hp .native_handle = (void * )crypto_ssl_get_hp (ssl );
163
- ctx -> max_encryption = crypto_ssl_get_aead_max_encryption (ssl );
164
- ctx -> max_decryption_failure = crypto_ssl_get_aead_max_decryption_failure (ssl );
165
- return ctx ;
186
+ const SSL_CIPHER * cipher = SSL_get_current_cipher (ssl );
187
+ uint32_t cipher_id ;
188
+
189
+ if (cipher == NULL ) {
190
+ return NULL ;
191
+ }
192
+
193
+ cipher_id = SSL_CIPHER_get_id (cipher );
194
+
195
+ if (!supported_cipher_id (cipher_id )) {
196
+ return NULL ;
197
+ }
198
+
199
+ return crypto_ctx_cipher_id (ctx , cipher_id );
166
200
}
167
201
168
202
ngtcp2_crypto_ctx * ngtcp2_crypto_ctx_tls_early (ngtcp2_crypto_ctx * ctx ,
@@ -394,15 +428,17 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
394
428
}
395
429
}
396
430
397
- int ngtcp2_crypto_read_write_crypto_data (ngtcp2_conn * conn ,
398
- ngtcp2_crypto_level crypto_level ,
399
- const uint8_t * data , size_t datalen ) {
431
+ int ngtcp2_crypto_read_write_crypto_data (
432
+ ngtcp2_conn * conn , ngtcp2_encryption_level encryption_level ,
433
+ const uint8_t * data , size_t datalen ) {
400
434
SSL * ssl = ngtcp2_conn_get_tls_native_handle (conn );
401
435
int rv ;
402
436
int err ;
403
437
404
438
if (SSL_provide_quic_data (
405
- ssl , ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level (crypto_level ),
439
+ ssl ,
440
+ ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level (
441
+ encryption_level ),
406
442
data , datalen ) != 1 ) {
407
443
return -1 ;
408
444
}
@@ -423,7 +459,10 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
423
459
424
460
SSL_reset_early_data_reject (ssl );
425
461
426
- ngtcp2_conn_early_data_rejected (conn );
462
+ rv = ngtcp2_conn_tls_early_data_rejected (conn );
463
+ if (rv != 0 ) {
464
+ return -1 ;
465
+ }
427
466
428
467
goto retry ;
429
468
default :
@@ -435,7 +474,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
435
474
return 0 ;
436
475
}
437
476
438
- ngtcp2_conn_handshake_completed (conn );
477
+ ngtcp2_conn_tls_handshake_completed (conn );
439
478
}
440
479
441
480
rv = SSL_process_quic_post_handshake (ssl );
@@ -464,7 +503,7 @@ int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
464
503
465
504
SSL_get_peer_quic_transport_params (ssl , & tp , & tplen );
466
505
467
- rv = ngtcp2_conn_decode_remote_transport_params (conn , tp , tplen );
506
+ rv = ngtcp2_conn_decode_and_set_remote_transport_params (conn , tp , tplen );
468
507
if (rv != 0 ) {
469
508
ngtcp2_conn_set_tls_error (conn , rv );
470
509
return -1 ;
@@ -482,33 +521,34 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
482
521
return 0 ;
483
522
}
484
523
485
- ngtcp2_crypto_level ngtcp2_crypto_boringssl_from_ssl_encryption_level (
524
+ ngtcp2_encryption_level ngtcp2_crypto_boringssl_from_ssl_encryption_level (
486
525
enum ssl_encryption_level_t ssl_level ) {
487
526
switch (ssl_level ) {
488
527
case ssl_encryption_initial :
489
- return NGTCP2_CRYPTO_LEVEL_INITIAL ;
528
+ return NGTCP2_ENCRYPTION_LEVEL_INITIAL ;
490
529
case ssl_encryption_early_data :
491
- return NGTCP2_CRYPTO_LEVEL_EARLY ;
530
+ return NGTCP2_ENCRYPTION_LEVEL_0RTT ;
492
531
case ssl_encryption_handshake :
493
- return NGTCP2_CRYPTO_LEVEL_HANDSHAKE ;
532
+ return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE ;
494
533
case ssl_encryption_application :
495
- return NGTCP2_CRYPTO_LEVEL_APPLICATION ;
534
+ return NGTCP2_ENCRYPTION_LEVEL_1RTT ;
496
535
default :
497
536
assert (0 );
498
537
abort ();
499
538
}
500
539
}
501
540
502
- enum ssl_encryption_level_t ngtcp2_crypto_boringssl_from_ngtcp2_crypto_level (
503
- ngtcp2_crypto_level crypto_level ) {
504
- switch (crypto_level ) {
505
- case NGTCP2_CRYPTO_LEVEL_INITIAL :
541
+ enum ssl_encryption_level_t
542
+ ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level (
543
+ ngtcp2_encryption_level encryption_level ) {
544
+ switch (encryption_level ) {
545
+ case NGTCP2_ENCRYPTION_LEVEL_INITIAL :
506
546
return ssl_encryption_initial ;
507
- case NGTCP2_CRYPTO_LEVEL_HANDSHAKE :
547
+ case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE :
508
548
return ssl_encryption_handshake ;
509
- case NGTCP2_CRYPTO_LEVEL_APPLICATION :
549
+ case NGTCP2_ENCRYPTION_LEVEL_1RTT :
510
550
return ssl_encryption_application ;
511
- case NGTCP2_CRYPTO_LEVEL_EARLY :
551
+ case NGTCP2_ENCRYPTION_LEVEL_0RTT :
512
552
return ssl_encryption_early_data ;
513
553
default :
514
554
assert (0 );
@@ -541,7 +581,7 @@ static int set_read_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
541
581
size_t secretlen ) {
542
582
ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
543
583
ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
544
- ngtcp2_crypto_level level =
584
+ ngtcp2_encryption_level level =
545
585
ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
546
586
(void )cipher ;
547
587
@@ -558,7 +598,7 @@ static int set_write_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
558
598
size_t secretlen ) {
559
599
ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
560
600
ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
561
- ngtcp2_crypto_level level =
601
+ ngtcp2_encryption_level level =
562
602
ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
563
603
(void )cipher ;
564
604
@@ -574,7 +614,7 @@ static int add_handshake_data(SSL *ssl, enum ssl_encryption_level_t bssl_level,
574
614
const uint8_t * data , size_t datalen ) {
575
615
ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
576
616
ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
577
- ngtcp2_crypto_level level =
617
+ ngtcp2_encryption_level level =
578
618
ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
579
619
int rv ;
580
620
0 commit comments