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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
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
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
403403
constngtcp2_crypto_cipher_ctx*hp_ctx,
404404
constuint8_t*sample) {
405-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
405+
staticconstuint8_tPLAINTEXT[16] ={0};
406406
ngtcp2_crypto_boringssl_cipher_ctx*ctx=hp_ctx->native_handle;
407407
uint32_tcounter;
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
return0;
426426
default:
@@ -436,7 +436,8 @@ int ngtcp2_crypto_read_write_crypto_data(
436436
intrv;
437437
interr;
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+
caseSSL_ERROR_WANT_X509_LOOKUP:
470+
caseSSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
471+
caseSSL_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+
return0;
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
return0;
569580
}
570581

582+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
590+
}
591+
592+
return0;
593+
}
594+
571595
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
572596
if (RAND_bytes(data, datalen) !=1) {
573597
return-1;

β€Ž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_EXTERNint
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_EXTERNintngtcp2_crypto_recv_crypto_data_cb(
552566
ngtcp2_conn*conn, ngtcp2_encryption_levelencryption_level, uint64_toffset,
@@ -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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xb6
600+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY0xB6
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-
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xb7
608+
#defineNGTCP2_CRYPTO_TOKEN_MAGIC_RETRY20xB7
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_EXTERNintngtcp2_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_EXTERNintngtcp2_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
staticEVP_CIPHER*crypto_aes_128_gcm;
5050
staticEVP_CIPHER*crypto_aes_256_gcm;
5151
staticEVP_CIPHER*crypto_aes_128_ccm;
52-
staticEVP_CIPHER*crypto_aes_128_ctr;
53-
staticEVP_CIPHER*crypto_aes_256_ctr;
52+
staticEVP_CIPHER*crypto_aes_128_ecb;
53+
staticEVP_CIPHER*crypto_aes_256_ecb;
5454
#ifndefNGTCP2_NO_CHACHA_POLY1305
5555
staticEVP_CIPHER*crypto_chacha20_poly1305;
5656
staticEVP_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
#ifndefNGTCP2_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
returnEVP_aes_128_ccm();
114114
}
115115

116-
staticconstEVP_CIPHER*crypto_cipher_aes_128_ctr(void) {
117-
if (crypto_aes_128_ctr) {
118-
returncrypto_aes_128_ctr;
116+
staticconstEVP_CIPHER*crypto_cipher_aes_128_ecb(void) {
117+
if (crypto_aes_128_ecb) {
118+
returncrypto_aes_128_ecb;
119119
}
120120

121-
returnEVP_aes_128_ctr();
121+
returnEVP_aes_128_ecb();
122122
}
123123

124-
staticconstEVP_CIPHER*crypto_cipher_aes_256_ctr(void) {
125-
if (crypto_aes_256_ctr) {
126-
returncrypto_aes_256_ctr;
124+
staticconstEVP_CIPHER*crypto_cipher_aes_256_ecb(void) {
125+
if (crypto_aes_256_ecb) {
126+
returncrypto_aes_256_ecb;
127127
}
128128

129-
returnEVP_aes_256_ctr();
129+
returnEVP_aes_256_ecb();
130130
}
131131

132132
#ifndefNGTCP2_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
returnctx;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269
switch (cipher_id) {
270270
caseTLS1_3_CK_AES_128_GCM_SHA256:
271271
caseTLS1_3_CK_AES_128_CCM_SHA256:
272-
returncrypto_cipher_aes_128_ctr();
272+
returncrypto_cipher_aes_128_ecb();
273273
caseTLS1_3_CK_AES_256_GCM_SHA384:
274-
returncrypto_cipher_aes_256_ctr();
274+
returncrypto_cipher_aes_256_ecb();
275275
#ifndefNGTCP2_NO_CHACHA_POLY1305
276276
caseTLS1_3_CK_CHACHA20_POLY1305_SHA256:
277277
returncrypto_cipher_chacha20();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
839839
constngtcp2_crypto_cipher_ctx*hp_ctx,
840840
constuint8_t*sample) {
841-
staticconstuint8_tPLAINTEXT[] ="\x00\x00\x00\x00\x00";
841+
staticconstuint8_tPLAINTEXT[16] ={0};
842842
EVP_CIPHER_CTX*actx=hp_ctx->native_handle;
843843
intlen;
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+
caseNID_aes_128_ecb:
849+
caseNID_aes_256_ecb:
850+
if (!EVP_EncryptUpdate(actx, dest, &len, sample, NGTCP2_HP_SAMPLELEN)) {
851+
return-1;
852+
}
853+
854+
break;
855+
caseNID_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
return0;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997
return0;
984998
}
985999

1000+
intngtcp2_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+
returnNGTCP2_ERR_CALLBACK_FAILURE;
1008+
}
1009+
1010+
return0;
1011+
}
1012+
9861013
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
9871014
if (RAND_bytes(data, (int)datalen) !=1) {
9881015
return-1;

β€Ždeps/ngtcp2/ngtcp2/crypto/picotls/picotls.cβ€Ž

Lines 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
returnctx;
@@ -104,11 +104,11 @@ crypto_cipher_suite_get_aead_max_decryption_failure(ptls_cipher_suite_t *cs) {
104104
staticconstptls_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
#ifdefPTLS_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
return0;
@@ -352,13 +357,20 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
352357
intngtcp2_crypto_hp_mask(uint8_t*dest, constngtcp2_crypto_cipher*hp,
353358
constngtcp2_crypto_cipher_ctx*hp_ctx,
354359
constuint8_t*sample) {
360+
staticconstuint8_tPLAINTEXT[16] = {0};
355361
ptls_cipher_context_t*actx=hp_ctx->native_handle;
356-
staticconstuint8_tPLAINTEXT[] ="\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+
return0;
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
return0;
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
return0;
494506
}
495507

508+
intngtcp2_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+
return0;
517+
}
518+
496519
intngtcp2_crypto_random(uint8_t*data, size_tdatalen) {
497520
ptls_openssl_random_bytes(data, datalen);
498521

499522
return0;
500523
}
501524

502525
voidngtcp2_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
staticintset_additional_extensions(ptls_handshake_properties_t*hsprops,

0 commit comments

Comments
Β (0)