Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 15530a7

Browse filesBrowse files
nodejs-github-botaduh95
authored andcommitted
deps: update ngtcp2 to 1.22.0
PR-URL: #62595 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 9b29be6 commit 15530a7
Copy full SHA for 15530a7

114 files changed

+5,216-4,339Lines changed: 5216 additions & 4339 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c
+27-3Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
402402
int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
403403
const ngtcp2_crypto_cipher_ctx *hp_ctx,
404404
const uint8_t *sample) {
405-
static const uint8_t PLAINTEXT[] = "\x00\x00\x00\x00\x00";
405+
static const uint8_t PLAINTEXT[16] = {0};
406406
ngtcp2_crypto_boringssl_cipher_ctx *ctx = hp_ctx->native_handle;
407407
uint32_t counter;
408408

@@ -420,7 +420,7 @@ int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
420420
#else /* !defined(WORDS_BIGENDIAN) */
421421
memcpy(&counter, sample, sizeof(counter));
422422
#endif /* !defined(WORDS_BIGENDIAN) */
423-
CRYPTO_chacha_20(dest, PLAINTEXT, ngtcp2_strlen_lit(PLAINTEXT), ctx->key,
423+
CRYPTO_chacha_20(dest, PLAINTEXT, sizeof(PLAINTEXT), ctx->key,
424424
sample + sizeof(counter), counter);
425425
return 0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
int rv;
437437
int err;
438438

439-
if (SSL_provide_quic_data(
439+
if (datalen &&
440+
SSL_provide_quic_data(
440441
ssl,
441442
ngtcp2_crypto_boringssl_from_ngtcp2_encryption_level(encryption_level),
442443
data, datalen) != 1) {
@@ -465,6 +466,16 @@ int ngtcp2_crypto_read_write_crypto_data(
465466
}
466467

467468
goto retry;
469+
case SSL_ERROR_WANT_X509_LOOKUP:
470+
case SSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
case SSL_ERROR_WANT_CERTIFICATE_VERIFY:
472+
/* It might be better to return this error, but ngtcp2 does
473+
not need to know whether handshake has been interrupted or
474+
not. We expect that necessary plumbing should be done by
475+
application when handshake is interrupted (e.g., via
476+
SSL_PRIVATE_KEY_METHOD). If it does not work, we will
477+
reconsider this. */
478+
return 0;
468479
default:
469480
return -1;
470481
}
@@ -568,6 +579,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
568579
return 0;
569580
}
570581

582+
int ngtcp2_crypto_get_path_challenge_data2_cb(ngtcp2_conn *conn,
583+
ngtcp2_path_challenge_data *data,
584+
void *user_data) {
585+
(void)conn;
586+
(void)user_data;
587+
588+
if (RAND_bytes(data->data, NGTCP2_PATH_CHALLENGE_DATALEN) != 1) {
589+
return NGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return 0;
593+
}
594+
571595
int ngtcp2_crypto_random(uint8_t *data, size_t datalen) {
572596
if (RAND_bytes(data, datalen) != 1) {
573597
return -1;
Collapse file

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

Copy file name to clipboardExpand all lines: deps/ngtcp2/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h
+39-7Lines 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
*
Collapse file

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

Copy file name to clipboardExpand all lines: deps/ngtcp2/ngtcp2/crypto/ossl/ossl.c
+48-21Lines 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;
Collapse file

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

Copy file name to clipboardExpand all lines: deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c
+30-8Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ngtcp2_crypto_md *ngtcp2_crypto_md_sha256(ngtcp2_crypto_md *md) {
5050
ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx) {
5151
ngtcp2_crypto_aead_init(&ctx->aead, (void *)&ptls_openssl_aes128gcm);
5252
ctx->md.native_handle = (void *)&ptls_openssl_sha256;
53-
ctx->hp.native_handle = (void *)&ptls_openssl_aes128ctr;
53+
ctx->hp.native_handle = (void *)&ptls_openssl_aes128ecb;
5454
ctx->max_encryption = 0;
5555
ctx->max_decryption_failure = 0;
5656
return ctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
static const ptls_cipher_algorithm_t *
105105
crypto_cipher_suite_get_hp(ptls_cipher_suite_t *cs) {
106106
if (cs->aead == &ptls_openssl_aes128gcm) {
107-
return &ptls_openssl_aes128ctr;
107+
return &ptls_openssl_aes128ecb;
108108
}
109109

110110
if (cs->aead == &ptls_openssl_aes256gcm) {
111-
return &ptls_openssl_aes256ctr;
111+
return &ptls_openssl_aes256ecb;
112112
}
113113

114114
#ifdef PTLS_OPENSSL_HAVE_CHACHA20_POLY1305
@@ -238,6 +238,11 @@ int ngtcp2_crypto_cipher_ctx_encrypt_init(ngtcp2_crypto_cipher_ctx *cipher_ctx,
238238
return -1;
239239
}
240240

241+
if (cipher->native_handle == &ptls_openssl_aes128ecb ||
242+
cipher->native_handle == &ptls_openssl_aes256ecb) {
243+
ptls_cipher_init(actx, NULL);
244+
}
245+
241246
cipher_ctx->native_handle = actx;
242247

243248
return 0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
353358
const ngtcp2_crypto_cipher_ctx *hp_ctx,
354359
const uint8_t *sample) {
360+
static const uint8_t PLAINTEXT[16] = {0};
355361
ptls_cipher_context_t *actx = hp_ctx->native_handle;
356-
static const uint8_t PLAINTEXT[] = "\x00\x00\x00\x00\x00";
357362

358363
(void)hp;
359364

365+
if (hp->native_handle == &ptls_openssl_aes128ecb ||
366+
hp->native_handle == &ptls_openssl_aes256ecb) {
367+
ptls_cipher_encrypt(actx, dest, sample, NGTCP2_HP_SAMPLELEN);
368+
369+
return 0;
370+
}
371+
360372
ptls_cipher_init(actx, sample);
361-
ptls_cipher_encrypt(actx, dest, PLAINTEXT, ngtcp2_strlen_lit(PLAINTEXT));
373+
ptls_cipher_encrypt(actx, dest, PLAINTEXT, sizeof(PLAINTEXT));
362374

363375
return 0;
364376
}
@@ -377,7 +389,7 @@ int ngtcp2_crypto_read_write_crypto_data(
377389

378390
ptls_buffer_init(&sendbuf, (void *)"", 0);
379391

380-
assert(epoch == ptls_get_read_epoch(cptls->ptls));
392+
assert(datalen == 0 || epoch == ptls_get_read_epoch(cptls->ptls));
381393

382394
rv = ptls_handle_message(cptls->ptls, &sendbuf, epoch_offsets, epoch, data,
383395
datalen, &cptls->handshake_properties);
@@ -493,15 +505,25 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
493505
return 0;
494506
}
495507

508+
int ngtcp2_crypto_get_path_challenge_data2_cb(ngtcp2_conn *conn,
509+
ngtcp2_path_challenge_data *data,
510+
void *user_data) {
511+
(void)conn;
512+
(void)user_data;
513+
514+
ptls_openssl_random_bytes(data->data, NGTCP2_PATH_CHALLENGE_DATALEN);
515+
516+
return 0;
517+
}
518+
496519
int ngtcp2_crypto_random(uint8_t *data, size_t datalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return 0;
500523
}
501524

502525
void ngtcp2_crypto_picotls_ctx_init(ngtcp2_crypto_picotls_ctx *cptls) {
503-
cptls->ptls = NULL;
504-
memset(&cptls->handshake_properties, 0, sizeof(cptls->handshake_properties));
526+
*cptls = (ngtcp2_crypto_picotls_ctx){0};
505527
}
506528

507529
static int set_additional_extensions(ptls_handshake_properties_t *hsprops,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.