Commit 3eeca52
tls: fix bugs of double TLS
Fixs two issues in `TLSWrap`, one of them is reported in
#30896.
1. `TLSWrap` has exactly one `StreamListener`, however,
that `StreamListener` can be replaced. We have not been
rigorous enough here: if an active write has not been
finished before the transition, the finish callback of it
will be wrongly fired the successor `StreamListener`.
2. A `TLSWrap` does not allow more than one active write,
as checked in the assertion about current_write in
`TLSWrap::DoWrite()`.
However, when users make use of an existing `tls.TLSSocket`
to establish double TLS, by
either
tls.connect({socket: tlssock})
or
tlsServer.emit('connection', tlssock)
we have both of the user provided `tls.TLSSocket`, tlssock and
a brand new created `TLSWrap` writing to the `TLSWrap` bound to
tlssock, which easily violates the constranint because two writers
have no idea of each other.
The design of the fix is:
when a `TLSWrap` is created on top of a user provided socket,
do not send any data to the socket until all existing writes
of the socket are done and ensure registered callbacks of
those writes can be fired.
PR-URL: #48969
Backport-PR-URL: #49183
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>1 parent 6de7aa1 commit 3eeca52Copy full SHA for 3eeca52
File tree
Expand file treeCollapse file tree
7 files changed
+297
-24
lines changedOpen diff view settings
Filter options
- lib
- src/crypto
- test
- parallel
- sequential
Expand file treeCollapse file tree
7 files changed
+297
-24
lines changedOpen diff view settings
Collapse file
+50-18Lines changed: 50 additions & 18 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
502 | 502 | |
503 | 503 | |
504 | 504 | |
505 | | - |
506 | | - |
507 | | - |
508 | | - |
| 505 | + |
| 506 | + |
| 507 | + |
| 508 | + |
| 509 | + |
| 510 | + |
| 511 | + |
| 512 | + |
| 513 | + |
| 514 | + |
| 515 | + |
| 516 | + |
| 517 | + |
| 518 | + |
| 519 | + |
| 520 | + |
| 521 | + |
| 522 | + |
509 | 523 | |
510 | | - |
511 | | - |
512 | | - |
513 | | - |
514 | | - |
515 | | - |
| 524 | + |
| 525 | + |
| 526 | + |
516 | 527 | |
517 | 528 | |
518 | 529 | |
519 | 530 | |
520 | 531 | |
521 | 532 | |
522 | 533 | |
523 | | - |
| 534 | + |
524 | 535 | |
525 | 536 | |
526 | 537 | |
| ||
539 | 550 | |
540 | 551 | |
541 | 552 | |
| 553 | + |
| 554 | + |
| 555 | + |
| 556 | + |
| 557 | + |
| 558 | + |
| 559 | + |
| 560 | + |
| 561 | + |
| 562 | + |
| 563 | + |
| 564 | + |
| 565 | + |
| 566 | + |
| 567 | + |
542 | 568 | |
543 | 569 | |
544 | 570 | |
| ||
599 | 625 | |
600 | 626 | |
601 | 627 | |
602 | | - |
603 | | - |
604 | | - |
605 | | - |
606 | | - |
| 628 | + |
| 629 | + |
| 630 | + |
| 631 | + |
| 632 | + |
| 633 | + |
| 634 | + |
| 635 | + |
607 | 636 | |
608 | 637 | |
609 | 638 | |
| ||
620 | 649 | |
621 | 650 | |
622 | 651 | |
623 | | - |
| 652 | + |
| 653 | + |
| 654 | + |
| 655 | + |
624 | 656 | |
625 | 657 | |
626 | 658 | |
| ||
637 | 669 | |
638 | 670 | |
639 | 671 | |
640 | | - |
| 672 | + |
641 | 673 | |
642 | 674 | |
643 | 675 | |
|
Collapse file
+44-4Lines changed: 44 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
319 | 319 | |
320 | 320 | |
321 | 321 | |
322 | | - |
| 322 | + |
| 323 | + |
323 | 324 | |
324 | 325 | |
325 | 326 | |
326 | 327 | |
327 | | - |
| 328 | + |
| 329 | + |
| 330 | + |
328 | 331 | |
329 | 332 | |
330 | 333 | |
| ||
434 | 437 | |
435 | 438 | |
436 | 439 | |
437 | | - |
| 440 | + |
438 | 441 | |
439 | 442 | |
440 | 443 | |
| 444 | + |
441 | 445 | |
442 | 446 | |
443 | 447 | |
444 | 448 | |
| 449 | + |
| 450 | + |
| 451 | + |
| 452 | + |
445 | 453 | |
446 | 454 | |
447 | 455 | |
| ||
452 | 460 | |
453 | 461 | |
454 | 462 | |
455 | | - |
| 463 | + |
| 464 | + |
456 | 465 | |
457 | 466 | |
458 | 467 | |
| ||
558 | 567 | |
559 | 568 | |
560 | 569 | |
| 570 | + |
| 571 | + |
| 572 | + |
| 573 | + |
| 574 | + |
| 575 | + |
| 576 | + |
561 | 577 | |
562 | 578 | |
563 | 579 | |
| ||
628 | 644 | |
629 | 645 | |
630 | 646 | |
| 647 | + |
| 648 | + |
| 649 | + |
| 650 | + |
| 651 | + |
| 652 | + |
| 653 | + |
| 654 | + |
| 655 | + |
631 | 656 | |
632 | 657 | |
633 | 658 | |
| ||
1974 | 1999 | |
1975 | 2000 | |
1976 | 2001 | |
| 2002 | + |
| 2003 | + |
| 2004 | + |
| 2005 | + |
| 2006 | + |
| 2007 | + |
| 2008 | + |
| 2009 | + |
| 2010 | + |
| 2011 | + |
1977 | 2012 | |
1978 | 2013 | |
1979 | 2014 | |
| ||
2050 | 2085 | |
2051 | 2086 | |
2052 | 2087 | |
| 2088 | + |
| 2089 | + |
| 2090 | + |
| 2091 | + |
2053 | 2092 | |
2054 | 2093 | |
2055 | 2094 | |
| ||
2131 | 2170 | |
2132 | 2171 | |
2133 | 2172 | |
| 2173 | + |
2134 | 2174 | |
2135 | 2175 | |
2136 | 2176 | |
|
Collapse file
+8-1Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
48 | 48 | |
49 | 49 | |
50 | 50 | |
| 51 | + |
| 52 | + |
51 | 53 | |
52 | 54 | |
53 | 55 | |
| ||
136 | 138 | |
137 | 139 | |
138 | 140 | |
139 | | - |
| 141 | + |
| 142 | + |
140 | 143 | |
141 | 144 | |
142 | 145 | |
| ||
216 | 219 | |
217 | 220 | |
218 | 221 | |
| 222 | + |
| 223 | + |
219 | 224 | |
220 | 225 | |
221 | 226 | |
| ||
283 | 288 | |
284 | 289 | |
285 | 290 | |
| 291 | + |
| 292 | + |
286 | 293 | |
287 | 294 | |
288 | 295 | |
|
Collapse file
test/parallel/test-double-tls-client.js
Copy file name to clipboard+58Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
0 commit comments