deps: update ngtcp2 to 1.22.0 · nodejs/node@080c4d7 · GitHub
Skip to content

Commit 080c4d7

Browse files
nodejs-github-botaduh95
authored andcommitted
deps: update ngtcp2 to 1.22.0
PR-URL: #62595 Backport-PR-URL: #64675 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 4309e7c commit 080c4d7

114 files changed

Lines changed: 5216 additions & 4339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c

Lines changed: 27 additions & 3 deletions

deps/ngtcp2/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,14 @@ NGTCP2_EXTERN int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn,
524524
* completes. It is allowed to call this function with |datalen| ==
525525
* 0. In this case, no additional read operation is done.
526526
*
527+
* This function is implemented per TLS backend. See
528+
* :ref:`tls-integration` for more details.
529+
*
527530
* This function returns 0 if it succeeds, or a negative error code.
528531
* The generic error code is -1 if a specific error code is not
529532
* suitable. The error codes less than -10000 are specific to
530-
* underlying TLS implementation. For quictls, the error codes are
531-
* defined in *ngtcp2_crypto_quictls.h*.
533+
* underlying TLS implementation. Refer to the implementation
534+
* specific header files for error codes.
532535
*/
533536
NGTCP2_EXTERN int
534537
ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
@@ -542,11 +545,22 @@ ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
542545
* `ngtcp2_crypto_read_write_crypto_data`. It can be directly passed
543546
* to :member:`ngtcp2_callbacks.recv_crypto_data` field.
544547
*
548+
* For quictls and OpenSSL, the following error codes are treated as
549+
* success:
550+
*
551+
* - -10001 (e.g., :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP`)
552+
* - -10002 (e.g., :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB`)
553+
*
554+
* To continue the interrupted handshake, call
555+
* `ngtcp2_conn_continue_handshake`.
556+
*
557+
* See :ref:`tls-integration` for more details.
558+
*
545559
* If this function is used, the TLS implementation specific error
546560
* codes described in `ngtcp2_crypto_read_write_crypto_data` are
547-
* treated as if it returns -1. Do not use this function if an
548-
* application wishes to use the TLS implementation specific error
549-
* codes.
561+
* treated as if it returns -1 except for those that are listed above.
562+
* Do not use this function if an application wishes to use the TLS
563+
* implementation specific error codes.
550564
*/
551565
NGTCP2_EXTERN int ngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level, uint64_t offset,
@@ -583,15 +597,15 @@ NGTCP2_EXTERN int ngtcp2_crypto_generate_stateless_reset_token(
583597
* :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY` is the magic byte for
584598
* Retry token generated by `ngtcp2_crypto_generate_retry_token`.
585599
*/
586-
#define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY 0xb6
600+
#define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY 0xB6
587601

588602
/**
589603
* @macro
590604
*
591605
* :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2` is the magic byte for
592606
* Retry token generated by `ngtcp2_crypto_generate_retry_token2`.
593607
*/
594-
#define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2 0xb7
608+
#define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2 0xB7
595609

596610
/**
597611
* @macro
@@ -978,11 +992,29 @@ NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_cipher_ctx_cb(
978992
*
979993
* This function can be directly passed to
980994
* :member:`ngtcp2_callbacks.get_path_challenge_data` field.
995+
*
996+
* Deprecated since v1.22.0. Use
997+
* `ngtcp2_crypto_get_path_challenge_data2_cb` instead.
981998
*/
982999
NGTCP2_EXTERN int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn,
9831000
uint8_t *data,
9841001
void *user_data);
9851002

1003+
/**
1004+
* @function
1005+
*
1006+
* `ngtcp2_crypto_get_path_challenge_data2_cb` writes unpredictable
1007+
* sequence of :macro:`NGTCP2_PATH_CHALLENGE_DATALEN` bytes to |data|
1008+
* which is sent with PATH_CHALLENGE frame.
1009+
*
1010+
* This function can be directly passed to
1011+
* :member:`ngtcp2_callbacks.get_path_challenge_data2` field.
1012+
*
1013+
* This function has been available since v1.22.0.
1014+
*/
1015+
NGTCP2_EXTERN int ngtcp2_crypto_get_path_challenge_data2_cb(
1016+
ngtcp2_conn *conn, ngtcp2_path_challenge_data *data, void *user_data);
1017+
9861018
/**
9871019
* @function
9881020
*

deps/ngtcp2/ngtcp2/crypto/ossl/ossl.c

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
static EVP_CIPHER *crypto_aes_128_gcm;
5050
static EVP_CIPHER *crypto_aes_256_gcm;
5151
static EVP_CIPHER *crypto_aes_128_ccm;
52-
static EVP_CIPHER *crypto_aes_128_ctr;
53-
static EVP_CIPHER *crypto_aes_256_ctr;
52+
static EVP_CIPHER *crypto_aes_128_ecb;
53+
static EVP_CIPHER *crypto_aes_256_ecb;
5454
#ifndef NGTCP2_NO_CHACHA_POLY1305
5555
static EVP_CIPHER *crypto_chacha20_poly1305;
5656
static EVP_CIPHER *crypto_chacha20;
@@ -66,8 +66,8 @@ int ngtcp2_crypto_ossl_init(void) {
6666
crypto_aes_128_gcm = EVP_CIPHER_fetch(NULL, "AES-128-GCM", NULL);
6767
crypto_aes_256_gcm = EVP_CIPHER_fetch(NULL, "AES-256-GCM", NULL);
6868
crypto_aes_128_ccm = EVP_CIPHER_fetch(NULL, "AES-128-CCM", NULL);
69-
crypto_aes_128_ctr = EVP_CIPHER_fetch(NULL, "AES-128-CTR", NULL);
70-
crypto_aes_256_ctr = EVP_CIPHER_fetch(NULL, "AES-256-CTR", NULL);
69+
crypto_aes_128_ecb = EVP_CIPHER_fetch(NULL, "AES-128-ECB", NULL);
70+
crypto_aes_256_ecb = EVP_CIPHER_fetch(NULL, "AES-256-ECB", NULL);
7171
#ifndef NGTCP2_NO_CHACHA_POLY1305
7272
crypto_chacha20_poly1305 = EVP_CIPHER_fetch(NULL, "ChaCha20-Poly1305", NULL);
7373
crypto_chacha20 = EVP_CIPHER_fetch(NULL, "ChaCha20", NULL);
@@ -113,20 +113,20 @@ static const EVP_CIPHER *crypto_aead_aes_128_ccm(void) {
113113
return EVP_aes_128_ccm();
114114
}
115115

116-
static const EVP_CIPHER *crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
return crypto_aes_128_ctr;
116+
static const EVP_CIPHER *crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
return crypto_aes_128_ecb;
119119
}
120120

121-
return EVP_aes_128_ctr();
121+
return EVP_aes_128_ecb();
122122
}
123123

124-
static const EVP_CIPHER *crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
return crypto_aes_256_ctr;
124+
static const EVP_CIPHER *crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
return crypto_aes_256_ecb;
127127
}
128128

129-
return EVP_aes_256_ctr();
129+
return EVP_aes_256_ecb();
130130
}
131131

132132
#ifndef NGTCP2_NO_CHACHA_POLY1305
@@ -198,7 +198,7 @@ ngtcp2_crypto_md *ngtcp2_crypto_md_sha256(ngtcp2_crypto_md *md) {
198198
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx) {
199199
ngtcp2_crypto_aead_init(&ctx->aead, (void *)crypto_aead_aes_128_gcm());
200200
ctx->md.native_handle = (void *)crypto_md_sha256();
201-
ctx->hp.native_handle = (void *)crypto_cipher_aes_128_ctr();
201+
ctx->hp.native_handle = (void *)crypto_cipher_aes_128_ecb();
202202
ctx->max_encryption = 0;
203203
ctx->max_decryption_failure = 0;
204204
return ctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
case TLS1_3_CK_AES_128_GCM_SHA256:
271271
case TLS1_3_CK_AES_128_CCM_SHA256:
272-
return crypto_cipher_aes_128_ctr();
272+
return crypto_cipher_aes_128_ecb();
273273
case TLS1_3_CK_AES_256_GCM_SHA384:
274-
return crypto_cipher_aes_256_ctr();
274+
return crypto_cipher_aes_256_ecb();
275275
#ifndef NGTCP2_NO_CHACHA_POLY1305
276276
case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
return crypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
839839
const ngtcp2_crypto_cipher_ctx *hp_ctx,
840840
const uint8_t *sample) {
841-
static const uint8_t PLAINTEXT[] = "\x00\x00\x00\x00\x00";
841+
static const uint8_t PLAINTEXT[16] = {0};
842842
EVP_CIPHER_CTX *actx = hp_ctx->native_handle;
843843
int len;
844844

845845
(void)hp;
846846

847-
if (!EVP_EncryptInit_ex(actx, NULL, NULL, NULL, sample) ||
848-
!EVP_EncryptUpdate(actx, dest, &len, PLAINTEXT,
849-
ngtcp2_strlen_lit(PLAINTEXT)) ||
850-
!EVP_EncryptFinal_ex(actx, dest + ngtcp2_strlen_lit(PLAINTEXT), &len)) {
851-
return -1;
847+
switch (EVP_CIPHER_CTX_nid(actx)) {
848+
case NID_aes_128_ecb:
849+
case NID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return -1;
852+
}
853+
854+
break;
855+
case NID_chacha20:
856+
if (!EVP_EncryptInit_ex(actx, NULL, NULL, NULL, sample) ||
857+
!EVP_EncryptUpdate(actx, dest, &len, PLAINTEXT, sizeof(PLAINTEXT)) ||
858+
!EVP_EncryptFinal_ex(actx, dest + sizeof(PLAINTEXT), &len)) {
859+
return -1;
860+
}
861+
862+
break;
863+
default:
864+
assert(0);
865+
abort();
852866
}
853867

854868
return 0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return 0;
984998
}
985999

1000+
int ngtcp2_crypto_get_path_challenge_data2_cb(ngtcp2_conn *conn,
1001+
ngtcp2_path_challenge_data *data,
1002+
void *user_data) {
1003+
(void)conn;
1004+
(void)user_data;
1005+
1006+
if (RAND_bytes(data->data, NGTCP2_PATH_CHALLENGE_DATALEN) != 1) {
1007+
return NGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return 0;
1011+
}
1012+
9861013
int ngtcp2_crypto_random(uint8_t *data, size_t datalen) {
9871014
if (RAND_bytes(data, (int)datalen) != 1) {
9881015
return -1;

deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c

Lines changed: 30 additions & 8 deletions

0 commit comments

Comments
 (0)