@@ -92,8 +92,8 @@ ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) {
9292 return ngtcp2_crypto_aead_init (aead , (void * )EVP_aead_aes_128_gcm ());
9393}
9494
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 ) {
9797 case TLS1_CK_AES_128_GCM_SHA256 :
9898 return EVP_aead_aes_128_gcm ();
9999 case TLS1_CK_AES_256_GCM_SHA384 :
@@ -105,8 +105,8 @@ static const EVP_AEAD *crypto_ssl_get_aead(SSL *ssl) {
105105 }
106106}
107107
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 ) {
110110 case TLS1_CK_AES_128_GCM_SHA256 :
111111 case TLS1_CK_AES_256_GCM_SHA384 :
112112 return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM ;
@@ -117,8 +117,9 @@ static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) {
117117 }
118118}
119119
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 ) {
122123 case TLS1_CK_AES_128_GCM_SHA256 :
123124 case TLS1_CK_AES_256_GCM_SHA384 :
124125 return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM ;
@@ -129,8 +130,9 @@ static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) {
129130 }
130131}
131132
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 ) {
134136 case TLS1_CK_AES_128_GCM_SHA256 :
135137 return & crypto_cipher_aes_128 ;
136138 case TLS1_CK_AES_256_GCM_SHA384 :
@@ -142,8 +144,8 @@ static const ngtcp2_crypto_boringssl_cipher *crypto_ssl_get_hp(SSL *ssl) {
142144 }
143145}
144146
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 ) {
147149 case TLS1_CK_AES_128_GCM_SHA256 :
148150 case TLS1_CK_CHACHA20_POLY1305_SHA256 :
149151 return EVP_sha256 ();
@@ -154,15 +156,47 @@ static const EVP_MD *crypto_ssl_get_md(SSL *ssl) {
154156 }
155157}
156158
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+
157183ngtcp2_crypto_ctx * ngtcp2_crypto_ctx_tls (ngtcp2_crypto_ctx * ctx ,
158184 void * tls_native_handle ) {
159185 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 );
166200}
167201
168202ngtcp2_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,
394428 }
395429}
396430
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 ) {
400434 SSL * ssl = ngtcp2_conn_get_tls_native_handle (conn );
401435 int rv ;
402436 int err ;
403437
404438 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 ),
406442 data , datalen ) != 1 ) {
407443 return -1 ;
408444 }
@@ -423,7 +459,10 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
423459
424460 SSL_reset_early_data_reject (ssl );
425461
426- ngtcp2_conn_early_data_rejected (conn );
462+ rv = ngtcp2_conn_tls_early_data_rejected (conn );
463+ if (rv != 0 ) {
464+ return -1 ;
465+ }
427466
428467 goto retry ;
429468 default :
@@ -435,7 +474,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
435474 return 0 ;
436475 }
437476
438- ngtcp2_conn_handshake_completed (conn );
477+ ngtcp2_conn_tls_handshake_completed (conn );
439478 }
440479
441480 rv = SSL_process_quic_post_handshake (ssl );
@@ -464,7 +503,7 @@ int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) {
464503
465504 SSL_get_peer_quic_transport_params (ssl , & tp , & tplen );
466505
467- rv = ngtcp2_conn_decode_remote_transport_params (conn , tp , tplen );
506+ rv = ngtcp2_conn_decode_and_set_remote_transport_params (conn , tp , tplen );
468507 if (rv != 0 ) {
469508 ngtcp2_conn_set_tls_error (conn , rv );
470509 return -1 ;
@@ -482,33 +521,34 @@ int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf,
482521 return 0 ;
483522}
484523
485- ngtcp2_crypto_level ngtcp2_crypto_boringssl_from_ssl_encryption_level (
524+ ngtcp2_encryption_level ngtcp2_crypto_boringssl_from_ssl_encryption_level (
486525 enum ssl_encryption_level_t ssl_level ) {
487526 switch (ssl_level ) {
488527 case ssl_encryption_initial :
489- return NGTCP2_CRYPTO_LEVEL_INITIAL ;
528+ return NGTCP2_ENCRYPTION_LEVEL_INITIAL ;
490529 case ssl_encryption_early_data :
491- return NGTCP2_CRYPTO_LEVEL_EARLY ;
530+ return NGTCP2_ENCRYPTION_LEVEL_0RTT ;
492531 case ssl_encryption_handshake :
493- return NGTCP2_CRYPTO_LEVEL_HANDSHAKE ;
532+ return NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE ;
494533 case ssl_encryption_application :
495- return NGTCP2_CRYPTO_LEVEL_APPLICATION ;
534+ return NGTCP2_ENCRYPTION_LEVEL_1RTT ;
496535 default :
497536 assert (0 );
498537 abort ();
499538 }
500539}
501540
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 :
506546 return ssl_encryption_initial ;
507- case NGTCP2_CRYPTO_LEVEL_HANDSHAKE :
547+ case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE :
508548 return ssl_encryption_handshake ;
509- case NGTCP2_CRYPTO_LEVEL_APPLICATION :
549+ case NGTCP2_ENCRYPTION_LEVEL_1RTT :
510550 return ssl_encryption_application ;
511- case NGTCP2_CRYPTO_LEVEL_EARLY :
551+ case NGTCP2_ENCRYPTION_LEVEL_0RTT :
512552 return ssl_encryption_early_data ;
513553 default :
514554 assert (0 );
@@ -541,7 +581,7 @@ static int set_read_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
541581 size_t secretlen ) {
542582 ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
543583 ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
544- ngtcp2_crypto_level level =
584+ ngtcp2_encryption_level level =
545585 ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
546586 (void )cipher ;
547587
@@ -558,7 +598,7 @@ static int set_write_secret(SSL *ssl, enum ssl_encryption_level_t bssl_level,
558598 size_t secretlen ) {
559599 ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
560600 ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
561- ngtcp2_crypto_level level =
601+ ngtcp2_encryption_level level =
562602 ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
563603 (void )cipher ;
564604
@@ -574,7 +614,7 @@ static int add_handshake_data(SSL *ssl, enum ssl_encryption_level_t bssl_level,
574614 const uint8_t * data , size_t datalen ) {
575615 ngtcp2_crypto_conn_ref * conn_ref = SSL_get_app_data (ssl );
576616 ngtcp2_conn * conn = conn_ref -> get_conn (conn_ref );
577- ngtcp2_crypto_level level =
617+ ngtcp2_encryption_level level =
578618 ngtcp2_crypto_boringssl_from_ssl_encryption_level (bssl_level );
579619 int rv ;
580620
0 commit comments