werift 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +299 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +51 -10
- package/lib/common/src/transport.js +35 -9
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/carrier/direct.d.ts +67 -0
- package/lib/dtls/src/carrier/direct.js +226 -0
- package/lib/dtls/src/carrier/direct.js.map +1 -0
- package/lib/dtls/src/carrier/types.d.ts +81 -0
- package/lib/dtls/src/carrier/types.js +7 -0
- package/lib/dtls/src/carrier/types.js.map +1 -0
- package/lib/dtls/src/cipher/const.d.ts +6 -0
- package/lib/dtls/src/cipher/const.js +13 -2
- package/lib/dtls/src/cipher/const.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +11 -2
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
- package/lib/dtls/src/cipher/tls13/aead.js +128 -0
- package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/signature.js +149 -0
- package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
- package/lib/dtls/src/client.d.ts +253 -0
- package/lib/dtls/src/client.js +1269 -14
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +47 -0
- package/lib/dtls/src/context/dtls.js +121 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +30 -1
- package/lib/dtls/src/context/transport.js +67 -3
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
- package/lib/dtls/src/engine/v1_3/connection.js +680 -0
- package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
- package/lib/dtls/src/engine/v1_3/host.js +11 -0
- package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
- package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
- package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
- package/lib/dtls/src/engine/v1_3/types.js +113 -0
- package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
- package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
- package/lib/dtls/src/flight/client/flight1.js +9 -3
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
- package/lib/dtls/src/flight/client/flight3.js +24 -4
- package/lib/dtls/src/flight/client/flight3.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +17 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +21 -0
- package/lib/dtls/src/flight/flight.js +119 -9
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
- package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
- package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
- package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
- package/lib/dtls/src/flight/server/flight2.js +29 -105
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +14 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +12 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +10 -0
- package/lib/dtls/src/handshake/const.js +10 -0
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
- package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
- package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/ids.js +11 -0
- package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/unique.js +19 -0
- package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
- package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
- package/lib/dtls/src/handshake/random.d.ts +14 -0
- package/lib/dtls/src/handshake/random.js +24 -0
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/handshake/validation.d.ts +26 -0
- package/lib/dtls/src/handshake/validation.js +32 -0
- package/lib/dtls/src/handshake/validation.js.map +1 -0
- package/lib/dtls/src/index.d.ts +8 -1
- package/lib/dtls/src/index.js +125 -44
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/internal.d.ts +7 -0
- package/lib/dtls/src/internal.js +57 -0
- package/lib/dtls/src/internal.js.map +1 -0
- package/lib/dtls/src/peer.d.ts +49 -0
- package/lib/dtls/src/peer.js +54 -0
- package/lib/dtls/src/peer.js.map +1 -0
- package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
- package/lib/dtls/src/record/antiReplayWindow.js +119 -0
- package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
- package/lib/dtls/src/record/const.d.ts +15 -0
- package/lib/dtls/src/record/const.js +15 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +0 -2
- package/lib/dtls/src/record/message/fragment.js +36 -17
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
- package/lib/dtls/src/record/message/reassembler.js +249 -0
- package/lib/dtls/src/record/message/reassembler.js.map +1 -0
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +58 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
- package/lib/dtls/src/record/v1_3/header.js +95 -0
- package/lib/dtls/src/record/v1_3/header.js.map +1 -0
- package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
- package/lib/dtls/src/record/v1_3/record.js +370 -0
- package/lib/dtls/src/record/v1_3/record.js.map +1 -0
- package/lib/dtls/src/retransmission.d.ts +26 -0
- package/lib/dtls/src/retransmission.js +39 -0
- package/lib/dtls/src/retransmission.js.map +1 -0
- package/lib/dtls/src/server.d.ts +38 -0
- package/lib/dtls/src/server.js +382 -17
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +487 -11
- package/lib/dtls/src/socket.js +1359 -70
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/version.d.ts +89 -0
- package/lib/dtls/src/version.js +204 -0
- package/lib/dtls/src/version.js.map +1 -0
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +126 -0
- package/lib/ice/src/consent.js +470 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -0
- package/lib/ice/src/dns/lookup.js +130 -3
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +9 -0
- package/lib/ice/src/exceptions.js +14 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/failover.d.ts +270 -0
- package/lib/ice/src/failover.js +674 -0
- package/lib/ice/src/failover.js.map +1 -0
- package/lib/ice/src/gatheringError.d.ts +28 -0
- package/lib/ice/src/gatheringError.js +17 -0
- package/lib/ice/src/gatheringError.js.map +1 -0
- package/lib/ice/src/ice.d.ts +486 -78
- package/lib/ice/src/ice.js +2415 -1129
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +404 -14
- package/lib/ice/src/iceBase.js +251 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +3 -0
- package/lib/ice/src/index.js +5 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/datagram.d.ts +37 -0
- package/lib/ice/src/internal/datagram.js +45 -0
- package/lib/ice/src/internal/datagram.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +28 -0
- package/lib/ice/src/internal/hostInterfaces.js +89 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/internal/sped-bind.d.ts +44 -0
- package/lib/ice/src/internal/sped-bind.js +53 -0
- package/lib/ice/src/internal/sped-bind.js.map +1 -0
- package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
- package/lib/ice/src/internal/sped-binding-cache.js +102 -0
- package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
- package/lib/ice/src/internal/sped.d.ts +15 -0
- package/lib/ice/src/internal/sped.js +62 -0
- package/lib/ice/src/internal/sped.js.map +1 -0
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionController.d.ts +111 -0
- package/lib/ice/src/nomination/selectionController.js +172 -0
- package/lib/ice/src/nomination/selectionController.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +178 -0
- package/lib/ice/src/nomination/selectionReplacement.js +429 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
- package/lib/ice/src/sped/draft00/codec.js +59 -0
- package/lib/ice/src/sped/draft00/codec.js.map +1 -0
- package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
- package/lib/ice/src/sped/draft00/constants.js +18 -0
- package/lib/ice/src/sped/draft00/constants.js.map +1 -0
- package/lib/ice/src/sped/draft00/index.d.ts +6 -0
- package/lib/ice/src/sped/draft00/index.js +26 -0
- package/lib/ice/src/sped/draft00/index.js.map +1 -0
- package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
- package/lib/ice/src/sped/draft00/mtu.js +96 -0
- package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
- package/lib/ice/src/sped/draft00/session.d.ts +86 -0
- package/lib/ice/src/sped/draft00/session.js +353 -0
- package/lib/ice/src/sped/draft00/session.js.map +1 -0
- package/lib/ice/src/sped/draft00/types.d.ts +16 -0
- package/lib/ice/src/sped/draft00/types.js +3 -0
- package/lib/ice/src/sped/draft00/types.js.map +1 -0
- package/lib/ice/src/sped/runtime.d.ts +188 -0
- package/lib/ice/src/sped/runtime.js +643 -0
- package/lib/ice/src/sped/runtime.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +38 -2
- package/lib/ice/src/stun/protocol.js +107 -21
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
- package/lib/ice/src/stun/rawAttributeValue.js +6 -0
- package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -1
- package/lib/ice/src/stun/tcpProtocol.js +21 -9
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +4 -0
- package/lib/ice/src/stun/transaction.js +27 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +23 -4
- package/lib/ice/src/turn/protocol.js +99 -11
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +25 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +13 -0
- package/lib/ice/src/utils.js +13 -0
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +43 -3
- package/lib/ice-server/src/stun/message.js +258 -40
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/index.mjs +47427 -25303
- package/lib/nonstandard/index.mjs +3076 -1318
- package/lib/polyfill/dom.mjs +40430 -18730
- package/lib/polyfill/index.mjs +40333 -18639
- package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
- package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
- package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
- package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
- package/lib/rtp/src/extra/processor/webm.js +6 -2
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
- package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +10 -0
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js +4 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +86 -5
- package/lib/sctp/src/sctp.js +354 -75
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +547 -36
- package/lib/webrtc/src/api/peerConfig.js +187 -26
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +87 -2
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +122 -10
- package/lib/webrtc/src/dataChannel.js +214 -20
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
- package/lib/webrtc/src/media/domEventTarget.js +216 -0
- package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
- package/lib/webrtc/src/media/index.d.ts +2 -0
- package/lib/webrtc/src/media/index.js +1 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +5 -0
- package/lib/webrtc/src/media/parameters.js +10 -0
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +245 -51
- package/lib/webrtc/src/media/router.js +702 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +277 -5
- package/lib/webrtc/src/media/rtpReceiver.js +826 -36
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +8 -1
- package/lib/webrtc/src/media/rtpSender.js +13 -6
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +47 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +95 -11
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +13 -0
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +112 -11
- package/lib/webrtc/src/media/track.js +250 -19
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
- package/lib/webrtc/src/media/trackConstraints.js +141 -0
- package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
- package/lib/webrtc/src/negotiation/internalState.js +0 -11
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +12 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +133 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +57 -5
- package/lib/webrtc/src/negotiationTransaction.js +134 -10
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +106 -11
- package/lib/webrtc/src/peerConnection.js +370 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +2 -1
- package/lib/webrtc/src/polyfill/api.js +3 -3
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
- package/lib/webrtc/src/polyfill/dom.js +15 -0
- package/lib/webrtc/src/polyfill/dom.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +8 -3
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.d.ts +1 -1
- package/lib/webrtc/src/polyfill/index.js +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.d.ts +5 -1
- package/lib/webrtc/src/polyfill/install.js +4 -2
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
- package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
- package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +31 -18
- package/lib/webrtc/src/sctpManager.js +162 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +107 -2
- package/lib/webrtc/src/sdp.js +223 -17
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +101 -10
- package/lib/webrtc/src/sdpManager.js +236 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +49 -3
- package/lib/webrtc/src/secureTransportManager.js +166 -12
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +87 -6
- package/lib/webrtc/src/transceiverManager.js +272 -51
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
- package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
- package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
- package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
- package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
- package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-stats.js +134 -0
- package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
- package/lib/webrtc/src/transport/dtls-types.js +11 -0
- package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
- package/lib/webrtc/src/transport/dtls.d.ts +236 -47
- package/lib/webrtc/src/transport/dtls.js +1198 -441
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +95 -5
- package/lib/webrtc/src/transport/ice.js +323 -21
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +149 -2
- package/lib/webrtc/src/transport/sctp.js +826 -128
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/transport/sped.d.ts +139 -0
- package/lib/webrtc/src/transport/sped.js +757 -0
- package/lib/webrtc/src/transport/sped.js.map +1 -0
- package/lib/webrtc/src/types/util.d.ts +6 -0
- package/lib/webrtc/src/types/util.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +34 -1
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/lib/webrtc/src/webidl.d.ts +15 -0
- package/lib/webrtc/src/webidl.js +34 -0
- package/lib/webrtc/src/webidl.js.map +1 -0
- package/package.json +8 -3
- package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
package/lib/dtls/src/client.js
CHANGED
|
@@ -1,18 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DtlsClient = void 0;
|
|
4
|
+
const const_1 = require("./cipher/const");
|
|
5
|
+
const namedCurve_1 = require("./cipher/namedCurve");
|
|
4
6
|
const abstract_1 = require("./cipher/suites/abstract");
|
|
7
|
+
const connection_1 = require("./engine/v1_3/connection");
|
|
5
8
|
const flight1_1 = require("./flight/client/flight1");
|
|
6
9
|
const flight3_1 = require("./flight/client/flight3");
|
|
7
10
|
const flight5_1 = require("./flight/client/flight5");
|
|
8
|
-
const
|
|
11
|
+
const const_2 = require("./handshake/const");
|
|
12
|
+
const cookie_1 = require("./handshake/extensions/cookie");
|
|
13
|
+
const ellipticCurves_1 = require("./handshake/extensions/ellipticCurves");
|
|
14
|
+
const keyShare_1 = require("./handshake/extensions/keyShare");
|
|
15
|
+
const signatureAlgorithms_1 = require("./handshake/extensions/signatureAlgorithms");
|
|
16
|
+
const supportedVersions_1 = require("./handshake/extensions/supportedVersions");
|
|
17
|
+
const hello_1 = require("./handshake/message/client/hello");
|
|
18
|
+
const hello_2 = require("./handshake/message/server/hello");
|
|
9
19
|
const helloVerifyRequest_1 = require("./handshake/message/server/helloVerifyRequest");
|
|
20
|
+
const random_1 = require("./handshake/random");
|
|
10
21
|
const common_1 = require("./imports/common");
|
|
22
|
+
const const_3 = require("./record/const");
|
|
23
|
+
const record_1 = require("./record/v1_3/record");
|
|
11
24
|
const socket_1 = require("./socket");
|
|
25
|
+
const version_1 = require("./version");
|
|
12
26
|
const log = (0, common_1.debug)("werift-dtls : packages/dtls/src/client.ts : log");
|
|
13
27
|
class DtlsClient extends socket_1.DtlsSocket {
|
|
28
|
+
/**
|
|
29
|
+
* @internal Dual association phase for tests and diagnostics.
|
|
30
|
+
* Not part of the stable Public API (typedoc `--excludeInternal`).
|
|
31
|
+
*/
|
|
32
|
+
get dualAssociationPhase() {
|
|
33
|
+
return this.dualPhase;
|
|
34
|
+
}
|
|
35
|
+
/** @internal Include a parked 1.3 candidate while dual version probing. */
|
|
36
|
+
get earlyDataStats() {
|
|
37
|
+
return (this.engine13?.earlyDataStats ??
|
|
38
|
+
this.parkedEngine13?.earlyDataStats ?? {
|
|
39
|
+
bufferedPackets: 0,
|
|
40
|
+
bufferedBytes: 0,
|
|
41
|
+
droppedPackets: 0,
|
|
42
|
+
droppedBytes: 0,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use dualAssociationPhase === "probing". Kept for internal/tests
|
|
47
|
+
* that still read dualCookiePath via casting.
|
|
48
|
+
*/
|
|
49
|
+
get dualCookiePath() {
|
|
50
|
+
return this.dualPhase === "probing";
|
|
51
|
+
}
|
|
52
|
+
/** Public constructor — accepts stable {@link Options} only. */
|
|
14
53
|
constructor(options) {
|
|
15
54
|
super(options, abstract_1.SessionType.CLIENT);
|
|
55
|
+
/**
|
|
56
|
+
* Dual association phase. Final version is confirmed by ServerHello
|
|
57
|
+
* (1.3 commit or 1.2 + DOWNGRD check), never by unauthenticated HVR alone.
|
|
58
|
+
*/
|
|
59
|
+
Object.defineProperty(this, "dualPhase", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: "none"
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Original dual ClientHello + ECDHE material for 1.3 resume / retransmit.
|
|
67
|
+
* Cleared when committed to 1.2 or 1.3.
|
|
68
|
+
*/
|
|
69
|
+
Object.defineProperty(this, "dualResume", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Parked 1.3 engine after HVR: keeps CH-A retransmit (RFC 9147) while the
|
|
77
|
+
* association probes the 1.2 cookie path.
|
|
78
|
+
*/
|
|
79
|
+
Object.defineProperty(this, "parkedEngine13", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Handshake carrier used by the dual association (default engine carrier or
|
|
87
|
+
* injected). Kept after soft 1.3 dispose so commit12 can rebind inject to
|
|
88
|
+
* the association 1.2 path without holding a dead engine reference.
|
|
89
|
+
*/
|
|
90
|
+
Object.defineProperty(this, "associationCarrier", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Peer pin snapshot for dual probing (from parked 1.3 engine at HVR).
|
|
98
|
+
* datagram-address: version commit / RX require matching 5-tuple.
|
|
99
|
+
* authenticated-single-peer: transport identity is the peer — 5-tuple is
|
|
100
|
+
* TX convenience only (ICE may omit or change rinfo).
|
|
101
|
+
*/
|
|
102
|
+
Object.defineProperty(this, "dualAssociationPeerKey", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(this, "dualAssociationPeerAddr", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* Association generation token. Bumped on hard-close and on commit to 1.3
|
|
116
|
+
* so in-flight async 1.2 handshake work (waitForReady / Flight5) cannot
|
|
117
|
+
* resume after the association or version decision has moved on.
|
|
118
|
+
*/
|
|
119
|
+
Object.defineProperty(this, "associationGen", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: 0
|
|
124
|
+
});
|
|
16
125
|
Object.defineProperty(this, "flight5", {
|
|
17
126
|
enumerable: true,
|
|
18
127
|
configurable: true,
|
|
@@ -23,37 +132,141 @@ class DtlsClient extends socket_1.DtlsSocket {
|
|
|
23
132
|
enumerable: true,
|
|
24
133
|
configurable: true,
|
|
25
134
|
writable: true,
|
|
26
|
-
value: async (assembled) => {
|
|
135
|
+
value: async (assembled, _peer, meta) => {
|
|
136
|
+
if (this.engine13)
|
|
137
|
+
return;
|
|
138
|
+
if (this.dualPhase === "closed")
|
|
139
|
+
return;
|
|
140
|
+
// Capture generation so awaits cannot resume after close / commit13.
|
|
141
|
+
const gen = this.associationGen;
|
|
142
|
+
const rxGeneration = meta?.rxGeneration;
|
|
143
|
+
const isActive = () => this.isLegacy12PathActive(gen, rxGeneration);
|
|
27
144
|
log(this.dtls.sessionId, "handleHandshakes", assembled.map((a) => a.msg_type));
|
|
28
145
|
for (const handshake of assembled) {
|
|
146
|
+
if (!isActive() || this.handshakeStopped)
|
|
147
|
+
return;
|
|
29
148
|
switch (handshake.msg_type) {
|
|
30
|
-
|
|
31
|
-
case const_1.HandshakeType.hello_verify_request_3:
|
|
149
|
+
case const_2.HandshakeType.hello_verify_request_3:
|
|
32
150
|
{
|
|
33
151
|
const verifyReq = helloVerifyRequest_1.ServerHelloVerifyRequest.deSerialize(handshake.fragment);
|
|
34
152
|
await new flight3_1.Flight3(this.transport, this.dtls).exec(verifyReq);
|
|
153
|
+
if (!isActive())
|
|
154
|
+
return;
|
|
155
|
+
// Do not overwrite dualResume with the cookie-bearing CH2 body.
|
|
156
|
+
// dualResume is the original dual CH-A used if a 1.3 SH/HRR for
|
|
157
|
+
// that first CH still arrives (spoofed HVR race). Pure 1.2 peers
|
|
158
|
+
// never select 1.3, so cookie CH is only needed on the 1.2 flights.
|
|
35
159
|
}
|
|
36
160
|
break;
|
|
37
|
-
|
|
38
|
-
case const_1.HandshakeType.server_hello_2:
|
|
161
|
+
case const_2.HandshakeType.server_hello_2:
|
|
39
162
|
{
|
|
40
163
|
if (this.connected)
|
|
41
164
|
return;
|
|
165
|
+
if (!isActive())
|
|
166
|
+
return;
|
|
167
|
+
const only13 = this.protocolVersions.length === 1 &&
|
|
168
|
+
this.protocolVersions[0] === version_1.DtlsVersion.V1_3;
|
|
169
|
+
if (only13) {
|
|
170
|
+
// Hard version mismatch: tear down association (no parked RTO left).
|
|
171
|
+
this.reportLegacy12Fatal(new version_1.ProtocolVersionError("DTLS 1.3-only client received non-1.3 ServerHello"));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Dual probing: strict SH validation before version commit.
|
|
175
|
+
// Malformed / unknown version must NOT commit12 (keeps 1.3 candidate).
|
|
176
|
+
if (this.dualPhase === "probing") {
|
|
177
|
+
const verdict = this.classifyProbingServerHello(handshake.fragment);
|
|
178
|
+
if (verdict.kind === "drop") {
|
|
179
|
+
log("dual probing: discard invalid ServerHello (no version commit)", verdict.reason);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (verdict.kind === "error") {
|
|
183
|
+
// Actionable protocol failure (e.g. unknown selected version):
|
|
184
|
+
// same association teardown as fatal alert / DOWNGRD.
|
|
185
|
+
this.reportLegacy12Fatal(verdict.error);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (verdict.kind === "dtls13") {
|
|
189
|
+
const fragBytes = handshake.serialize();
|
|
190
|
+
const pkt = (0, record_1.serializePlaintextRecord)(const_3.ContentType.handshake, 0, 0, fragBytes);
|
|
191
|
+
this.resumeDtls13FromDualPath(pkt, meta?.rxGeneration);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// kind === "dtls12": DOWNGRD check then commit
|
|
195
|
+
if (verdict.hasDowngradeSentinel) {
|
|
196
|
+
// Client still offered 1.3 — illegal downgrade. Close association
|
|
197
|
+
// so parked 1.3 RTO / carrier cannot outlive onError.
|
|
198
|
+
this.reportLegacy12Fatal(new version_1.ProtocolVersionError("illegal_parameter: ServerHello Random contains TLS downgrade sentinel while client offered DTLS 1.3"));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!isActive())
|
|
202
|
+
return;
|
|
203
|
+
this.commitDualTo12();
|
|
204
|
+
if (!isActive())
|
|
205
|
+
return;
|
|
206
|
+
// Same as pure 1.2: do not replace Flight5 on duplicate SH.
|
|
207
|
+
if (this.flight5 || this.dtls.flight >= 5 || this.connected) {
|
|
208
|
+
this.flight5?.handleHandshake(handshake);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
this.flight5 = new flight5_1.Flight5(this.transport, this.dtls, this.cipher, this.srtp);
|
|
212
|
+
this.flight5.handleHandshake(handshake);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
// Non-probing (pure 1.2 or already committed12): legacy path with
|
|
216
|
+
// DOWNGRD when client still offered 1.3.
|
|
217
|
+
if ((0, version_1.supportsVersion)(this.protocolVersions, version_1.DtlsVersion.V1_3)) {
|
|
218
|
+
try {
|
|
219
|
+
const sh = hello_2.ServerHello.deSerialize(handshake.fragment);
|
|
220
|
+
const random32 = this.serverHelloRandom32(sh);
|
|
221
|
+
if ((0, version_1.hasTlsDowngradeSentinel)(random32)) {
|
|
222
|
+
this.reportLegacy12Fatal(new version_1.ProtocolVersionError("illegal_parameter: ServerHello Random contains TLS downgrade sentinel while client offered DTLS 1.3"));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
if (e instanceof version_1.ProtocolVersionError ||
|
|
228
|
+
(e instanceof Error && e.name === "ProtocolVersionError")) {
|
|
229
|
+
this.reportLegacy12Fatal(e);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!isActive())
|
|
235
|
+
return;
|
|
236
|
+
// Duplicate ServerHello (Flight4 retransmit) must not replace an
|
|
237
|
+
// existing Flight5 mid-handshake or re-apply crypto (ECDHE).
|
|
238
|
+
if (this.flight5 || this.dtls.flight >= 5 || this.connected) {
|
|
239
|
+
this.flight5?.handleHandshake(handshake);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
42
242
|
this.flight5 = new flight5_1.Flight5(this.transport, this.dtls, this.cipher, this.srtp);
|
|
43
243
|
this.flight5.handleHandshake(handshake);
|
|
44
244
|
}
|
|
45
245
|
break;
|
|
46
|
-
case
|
|
47
|
-
case const_1.HandshakeType.server_key_exchange_12:
|
|
48
|
-
case const_1.HandshakeType.certificate_request_13:
|
|
246
|
+
case const_2.HandshakeType.certificate_11:
|
|
49
247
|
{
|
|
50
248
|
await this.waitForReady(() => !!this.flight5);
|
|
51
249
|
this.flight5?.handleHandshake(handshake);
|
|
250
|
+
// Reject the server certificate before flight 5 (Finished) is sent.
|
|
251
|
+
if (!this.verifyRemoteCertificate())
|
|
252
|
+
return;
|
|
52
253
|
}
|
|
53
254
|
break;
|
|
54
|
-
case
|
|
255
|
+
case const_2.HandshakeType.server_key_exchange_12:
|
|
256
|
+
case const_2.HandshakeType.certificate_request_13:
|
|
55
257
|
{
|
|
56
258
|
await this.waitForReady(() => !!this.flight5);
|
|
259
|
+
// 解放済み candidate に触れないよう await 後に再検証
|
|
260
|
+
if (!isActive())
|
|
261
|
+
return;
|
|
262
|
+
this.flight5?.handleHandshake(handshake);
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
case const_2.HandshakeType.server_hello_done_14:
|
|
266
|
+
{
|
|
267
|
+
await this.waitForReady(() => !!this.flight5);
|
|
268
|
+
if (!isActive())
|
|
269
|
+
return;
|
|
57
270
|
this.flight5?.handleHandshake(handshake);
|
|
58
271
|
const targets = [
|
|
59
272
|
11,
|
|
@@ -61,15 +274,29 @@ class DtlsClient extends socket_1.DtlsSocket {
|
|
|
61
274
|
this.options.certificateRequest && 13,
|
|
62
275
|
].filter((n) => typeof n === "number");
|
|
63
276
|
await this.waitForReady(() => this.dtls.checkHandshakesExist(targets));
|
|
277
|
+
// close / commit13 後は Flight5.exec も onConnect も行わない
|
|
278
|
+
if (!isActive() || this.handshakeStopped)
|
|
279
|
+
return;
|
|
64
280
|
await this.flight5?.exec();
|
|
281
|
+
if (!isActive())
|
|
282
|
+
return;
|
|
65
283
|
}
|
|
66
284
|
break;
|
|
67
|
-
|
|
68
|
-
case const_1.HandshakeType.finished_20:
|
|
285
|
+
case const_2.HandshakeType.finished_20:
|
|
69
286
|
{
|
|
287
|
+
if (!isActive())
|
|
288
|
+
return;
|
|
289
|
+
if (this.connected)
|
|
290
|
+
return;
|
|
70
291
|
this.dtls.flight = 7;
|
|
71
292
|
this.connected = true;
|
|
72
|
-
|
|
293
|
+
// Keep existing connect()-time pin; never replace from last rinfo
|
|
294
|
+
// (spoof before Finished must not hijack app TX).
|
|
295
|
+
this.pinSendPeerFromTransportRinfo("set-if-empty");
|
|
296
|
+
// Flight5 was sleeping until nextFlight=7; cancel RTO sleep before
|
|
297
|
+
// onConnect so pending timers/tasks are gone on handshake complete.
|
|
298
|
+
this.cancelLegacy12FlightTimers();
|
|
299
|
+
this.notify(this.onConnect);
|
|
73
300
|
log(this.dtls.sessionId, "dtls connected");
|
|
74
301
|
}
|
|
75
302
|
break;
|
|
@@ -77,12 +304,1040 @@ class DtlsClient extends socket_1.DtlsSocket {
|
|
|
77
304
|
}
|
|
78
305
|
}
|
|
79
306
|
});
|
|
307
|
+
/**
|
|
308
|
+
* Association inbound dispatcher (UDP onData and carrier.inject).
|
|
309
|
+
*
|
|
310
|
+
* - closed: drop everything (no reconnect, no timer restart)
|
|
311
|
+
* - non-association peer: drop before version commit (anti-spoof)
|
|
312
|
+
* - active engine13 (committed13 / pure 1.3 after dual resume): forward to 1.3
|
|
313
|
+
* - probing + 1.3 SH/HRR from association peer: version commit to 1.3
|
|
314
|
+
* - probing + epoch-0 illegal_parameter only: suppress (legacy_cookie vs 1.3)
|
|
315
|
+
* - else: DTLS 1.2 record path (committed12 / dual cookie / pure 1.2)
|
|
316
|
+
*/
|
|
317
|
+
Object.defineProperty(this, "udpOnMessage", {
|
|
318
|
+
enumerable: true,
|
|
319
|
+
configurable: true,
|
|
320
|
+
writable: true,
|
|
321
|
+
value: (data, addr, meta) => {
|
|
322
|
+
// Terminal: dualPhase closed *or* associationTornDown mid peer-close reply.
|
|
323
|
+
if (this.dualPhase === "closed" || this.associationTornDown) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// Version selection below is synchronous and bypasses the legacy
|
|
327
|
+
// handleDatagram generation checks. Reject stale ICE datagrams before a
|
|
328
|
+
// probing ServerHello can commit the association to DTLS 1.3.
|
|
329
|
+
if (!this.isCurrentRxGeneration(meta?.rxGeneration)) {
|
|
330
|
+
log("dual association: drop stale RX generation before version select");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// Prefer explicit addr (UDP / inject); fall back to last rinfo.
|
|
334
|
+
const peerAddr = addr ??
|
|
335
|
+
(() => {
|
|
336
|
+
const r = this.options.transport.rinfo;
|
|
337
|
+
if (r?.address != null && r?.port != null) {
|
|
338
|
+
return [r.address, r.port];
|
|
339
|
+
}
|
|
340
|
+
return undefined;
|
|
341
|
+
})();
|
|
342
|
+
// Committed (or pure) 1.3: association still owns demux so late 1.2 / post-
|
|
343
|
+
// close races cannot bypass closed/committed12 guards via engine-only RX.
|
|
344
|
+
const peerTuple = peerAddr
|
|
345
|
+
? [peerAddr[0], peerAddr[1]]
|
|
346
|
+
: undefined;
|
|
347
|
+
// Peer gate for every phase that has a pin (pure 1.3 after connect, dual
|
|
348
|
+
// probing/committed). Unpinned pure/initial still accepts (engine/pre-HS).
|
|
349
|
+
if (!this.isAssociationPeer(peerAddr)) {
|
|
350
|
+
log("dual association: drop datagram from non-association peer", (0, cookie_1.peerKeyFromAddr)(peerTuple), this.dualAssociationPeerKey);
|
|
351
|
+
this.restorePinnedRinfo();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (this.engine13 && !this.engine13.isClosed()) {
|
|
355
|
+
return this.engine13.injectDatagram(data, peerTuple, meta?.rxGeneration);
|
|
356
|
+
}
|
|
357
|
+
if (this.dualPhase === "probing" &&
|
|
358
|
+
!this.engine13 &&
|
|
359
|
+
this.datagramSelectsDtls13(data)) {
|
|
360
|
+
this.resumeDtls13FromDualPath(data, meta?.rxGeneration);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (this.dualPhase === "probing" &&
|
|
364
|
+
!this.engine13 &&
|
|
365
|
+
this.datagramIsEpoch0IllegalParameterAlert(data)) {
|
|
366
|
+
log("dual probing: ignore epoch-0 illegal_parameter alert (likely legacy_cookie vs DTLS 1.3)");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
// After commit12, late 1.3 SH must not reverse version (resume guards too).
|
|
370
|
+
// Pass peer so base 1.2 RX pin gate applies (UDP + carrier.inject parity).
|
|
371
|
+
this.handleUdpDatagram(data, peerAddr, meta);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
80
374
|
this.onHandleHandshakes = this.handleHandshakes;
|
|
81
|
-
|
|
375
|
+
const versions = this.protocolVersions;
|
|
376
|
+
const only13 = versions.length === 1 && versions[0] === version_1.DtlsVersion.V1_3;
|
|
377
|
+
const dual = (0, version_1.supportsVersion)(versions, version_1.DtlsVersion.V1_3) &&
|
|
378
|
+
(0, version_1.supportsVersion)(versions, version_1.DtlsVersion.V1_2);
|
|
379
|
+
// normalizeProtocolVersions maps [1.2,1.3] → [1.3,1.2]; dual always 1.3-first.
|
|
380
|
+
const prefer13 = versions[0] === version_1.DtlsVersion.V1_3;
|
|
381
|
+
// Pure 1.3 or dual [1.3,1.2]: start 1.3 engine; CH advertises full list.
|
|
382
|
+
if (only13 || (dual && prefer13)) {
|
|
383
|
+
this.startEngine13(only13, versions);
|
|
384
|
+
}
|
|
385
|
+
log(this.dtls.sessionId, "start client", {
|
|
386
|
+
versions,
|
|
387
|
+
only13,
|
|
388
|
+
dual,
|
|
389
|
+
prefer13,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
startEngine13(strict13, offered) {
|
|
393
|
+
const engine = new connection_1.Dtls13Connection({
|
|
394
|
+
transport: this.options.transport,
|
|
395
|
+
cert: this.options.cert,
|
|
396
|
+
key: this.options.key,
|
|
397
|
+
srtpProfiles: this.options.srtpProfiles,
|
|
398
|
+
extendedMasterSecret: this.options.extendedMasterSecret,
|
|
399
|
+
certificateRequest: this.options.certificateRequest,
|
|
400
|
+
addressValidation: this.options.addressValidation,
|
|
401
|
+
peerIdentityMode: this.peerIdentityMode,
|
|
402
|
+
groups: this.options.namedGroups
|
|
403
|
+
? [...this.options.namedGroups]
|
|
404
|
+
: undefined,
|
|
405
|
+
mtu: this.options.mtu,
|
|
406
|
+
maxEarlyAppDataRecords: this.options.maxEarlyAppDataRecords,
|
|
407
|
+
maxEarlyAppDataBytes: this.options.maxEarlyAppDataBytes,
|
|
408
|
+
// handshakeCarrier is DtlsInternalOptions only (not stable Public API)
|
|
409
|
+
carrier: this.options.handshakeCarrier,
|
|
410
|
+
offeredProtocolVersions: offered,
|
|
411
|
+
}, abstract_1.SessionType.CLIENT);
|
|
412
|
+
const dualCanContinue12 = !strict13 && (0, version_1.supportsVersion)(this.protocolVersions, version_1.DtlsVersion.V1_2);
|
|
413
|
+
this.bridgeEngine13(engine, {
|
|
414
|
+
filterError: (e) => dualCanContinue12 &&
|
|
415
|
+
this.dualPhase === "none" &&
|
|
416
|
+
e instanceof version_1.DtlsVersionSelected &&
|
|
417
|
+
e.version === version_1.DtlsVersion.V1_2,
|
|
418
|
+
});
|
|
419
|
+
if (dualCanContinue12) {
|
|
420
|
+
engine.onError.subscribe((e) => {
|
|
421
|
+
if (this.dualPhase !== "none")
|
|
422
|
+
return;
|
|
423
|
+
if (!(e instanceof version_1.DtlsVersionSelected) ||
|
|
424
|
+
e.version !== version_1.DtlsVersion.V1_2) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
log("dual association: HVR → probing (1.3 CH-A park + 1.2 cookie path)", e.message);
|
|
428
|
+
// Engine already parked via tryParkDualProbe (CH-A retransmit kept).
|
|
429
|
+
this.dualResume = engine.exportDualResumeClientHello();
|
|
430
|
+
this.parkedEngine13 = engine;
|
|
431
|
+
this.engine13 = undefined;
|
|
432
|
+
this.dualPhase = "probing";
|
|
433
|
+
this.connected = false;
|
|
434
|
+
// Snapshot peer pin for association demux + 1.2 TX destination.
|
|
435
|
+
this.pinAssociationPeer(engine.getPeerAddr(), engine.getExpectedPeerKey());
|
|
436
|
+
// Association owns RX demux: both UDP onData and carrier.inject.
|
|
437
|
+
// Leaving inject bound to the parked engine would let Epic 2 SPED
|
|
438
|
+
// complete 1.3 while public engine13 stays undefined.
|
|
439
|
+
this.bindAssociationInbound(engine);
|
|
440
|
+
this.dtls = new this.dtls.constructor(this.options, this.sessionType);
|
|
441
|
+
this.cipher = new this.cipher.constructor(this.sessionType, this.options.cert, this.options.key, this.options.signatureHash);
|
|
442
|
+
this.srtp = new this.srtp.constructor();
|
|
443
|
+
// Dual extensions: keep advertising full supported_versions preference order
|
|
444
|
+
this.setupExtensionsForDualCookiePath();
|
|
445
|
+
void this.continueDualAfterHvr(e.helloVerifyCookie).catch((err) => {
|
|
446
|
+
// Cookie-path failure while still probing with a live parked 1.3:
|
|
447
|
+
// stop 1.2 retransmit only — do not public-fail the association
|
|
448
|
+
// (CH-A RTO may still complete 1.3). If no 1.3 candidate remains,
|
|
449
|
+
// fail the whole association (no onError-only zombie state).
|
|
450
|
+
if (this.dualPhase === "closed" || this.associationTornDown)
|
|
451
|
+
return;
|
|
452
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
453
|
+
if (this.dualPhase === "probing" &&
|
|
454
|
+
this.parkedEngine13 &&
|
|
455
|
+
!this.parkedEngine13.isClosed()) {
|
|
456
|
+
log("dual cookie path failed while parked 1.3 live — abort 1.2 flight only", e.message);
|
|
457
|
+
this.abortLegacy12Flight(e);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
this.reportLegacy12Fatal(e);
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
// Engine constructor binds transport.onData / carrier.inject to itself.
|
|
465
|
+
// Association must own both immediately (pure 1.3 and dual initial) so
|
|
466
|
+
// terminal/peer gates and carrier.inject never bypass udpOnMessage.
|
|
467
|
+
this.bindAssociationInbound(engine);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Hard-close every DTLS 1.3 candidate owned by this association (active
|
|
471
|
+
* engine13 and/or parked dual probe). Cancels RTO timers and pending flights.
|
|
472
|
+
* Bridge subscriptions are cut first so teardown onClose/onError cannot
|
|
473
|
+
* leak to the public socket after association close.
|
|
474
|
+
*
|
|
475
|
+
* Does **not** clear or close {@link associationCarrier} — callers that hard-
|
|
476
|
+
* close the association must call {@link closeAssociationCarrier} so that
|
|
477
|
+
* commit12 soft-dispose (engine gone, carrier still open) cannot leak.
|
|
478
|
+
*
|
|
479
|
+
* @returns true when at least one engine was asked to graceful-close (may
|
|
480
|
+
* still be sending close_notify asynchronously — do not close transport yet).
|
|
481
|
+
*/
|
|
482
|
+
closeAllDtls13Candidates(opts) {
|
|
483
|
+
this.unbridgeEngine13();
|
|
484
|
+
const candidates = new Set();
|
|
485
|
+
if (this.engine13)
|
|
486
|
+
candidates.add(this.engine13);
|
|
487
|
+
if (this.parkedEngine13)
|
|
488
|
+
candidates.add(this.parkedEngine13);
|
|
489
|
+
this.retireSelectedEngine13();
|
|
490
|
+
this.parkedEngine13 = undefined;
|
|
491
|
+
this.dualResume = undefined;
|
|
492
|
+
this.dualAssociationPeerKey = undefined;
|
|
493
|
+
this.dualAssociationPeerAddr = undefined;
|
|
494
|
+
this.transport.pinnedPeer = undefined;
|
|
495
|
+
let deferredTransportClose = false;
|
|
496
|
+
for (const eng of candidates) {
|
|
497
|
+
if (opts?.hardDispose) {
|
|
498
|
+
// Fatal path: force carrier/timer stop even after soft ProtocolVersionError
|
|
499
|
+
// (isClosed already true but carrier may still be open).
|
|
500
|
+
eng.hardDisposeResources();
|
|
501
|
+
}
|
|
502
|
+
else if (!eng.isClosed()) {
|
|
503
|
+
// Graceful: may async-send close_notify then teardownAssociation
|
|
504
|
+
// (closes transport). Caller must not close transport synchronously.
|
|
505
|
+
eng.close();
|
|
506
|
+
deferredTransportClose = true;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return deferredTransportClose;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Hard-close the association-owned handshake carrier if still open.
|
|
513
|
+
* Required after commit12: soft 1.3 dispose deliberately leaves the carrier
|
|
514
|
+
* reusable until association hard-close.
|
|
515
|
+
*/
|
|
516
|
+
closeAssociationCarrier() {
|
|
517
|
+
const carrier = this.associationCarrier;
|
|
518
|
+
this.associationCarrier = undefined;
|
|
519
|
+
if (carrier && !carrier.isClosed()) {
|
|
520
|
+
carrier.close();
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Full association hard-close: 1.2 flight stop, all 1.3 candidates, carrier,
|
|
525
|
+
* timers, phase → closed, RX drop.
|
|
526
|
+
*
|
|
527
|
+
* Transport close policy:
|
|
528
|
+
* - **Fatal** (`hardDisposeCandidates`): always close transport immediately
|
|
529
|
+
* (hardDispose does not close the UDP socket).
|
|
530
|
+
* - **Graceful** local close: if an engine is still sending close_notify,
|
|
531
|
+
* defer transport close to engine `teardownAssociation` so notify is not
|
|
532
|
+
* dropped. When no live 1.3 candidate remains, close transport here.
|
|
533
|
+
*
|
|
534
|
+
* Public onClose ownership:
|
|
535
|
+
* - **Local close** (`firePublicOnClose`): association fires onClose once
|
|
536
|
+
* (bridge is unsubscribed before eng.close, so engine teardown cannot).
|
|
537
|
+
* - **Fatal**: caller (`bridgeEngine13` onError) fires onClose after this.
|
|
538
|
+
* - **Peer close**: caller already fired onClose before this hook.
|
|
539
|
+
*/
|
|
540
|
+
closeAssociationHard(opts) {
|
|
541
|
+
// dualPhase already closed: never re-fire onClose.
|
|
542
|
+
// - Peer/fatal finish path: hardDisposeCandidates + candidates still present
|
|
543
|
+
// - Re-entrant local close() from onClose handlers: pure no-op (outer continues)
|
|
544
|
+
if (this.dualPhase === "closed") {
|
|
545
|
+
if (opts?.hardDisposeCandidates &&
|
|
546
|
+
(this.engine13 || this.parkedEngine13)) {
|
|
547
|
+
this.closeAllDtls13Candidates({ hardDispose: true });
|
|
548
|
+
this.closeAssociationCarrier();
|
|
549
|
+
this.transport.socket.onData = this.udpOnMessage;
|
|
550
|
+
if (!opts?.keepTransportOpen) {
|
|
551
|
+
void this.transport.close().catch(() => { });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
else if (!this.engine13 && !this.parkedEngine13) {
|
|
555
|
+
this.closeAssociationCarrier();
|
|
556
|
+
if (!opts?.keepTransportOpen) {
|
|
557
|
+
void this.transport.close().catch(() => { });
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
// A live candidate still finishes its close and the transport.
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
// Cancel cancelable 1.2 retransmit sleeps (not just flight=99 sentinel).
|
|
567
|
+
this.abortLegacy12Flight();
|
|
568
|
+
this.connected = false;
|
|
569
|
+
this.associationTornDown = true;
|
|
570
|
+
// Cancel waitForReady association sleeps immediately.
|
|
571
|
+
this.abortAssociationWaits();
|
|
572
|
+
// Mark closed before onClose so re-entrant client.close() is a no-op
|
|
573
|
+
// (handlers that call close() inside onClose must not recurse).
|
|
574
|
+
this.dualPhase = "closed";
|
|
575
|
+
// Invalidate any in-flight 1.2 handshake / dual cookie async work.
|
|
576
|
+
this.associationGen++;
|
|
577
|
+
this.flight5 = undefined;
|
|
578
|
+
// Local close: fire onClose while engine13 still visible (peer path parity).
|
|
579
|
+
// Fatal/peer paths omit this flag — they already fire or will fire elsewhere.
|
|
580
|
+
if (opts?.firePublicOnClose) {
|
|
581
|
+
this.notify(this.onClose);
|
|
582
|
+
}
|
|
583
|
+
const deferredTransport = this.closeAllDtls13Candidates({
|
|
584
|
+
hardDispose: opts?.hardDisposeCandidates,
|
|
585
|
+
});
|
|
586
|
+
// Always close association carrier (survives soft commit12 release).
|
|
587
|
+
// close_notify uses transport.send, not the handshake carrier.
|
|
588
|
+
this.closeAssociationCarrier();
|
|
589
|
+
// Association demux stays closed-gated so late inject is a no-op.
|
|
590
|
+
this.transport.socket.onData = this.udpOnMessage;
|
|
591
|
+
if (opts?.hardDisposeCandidates || !deferredTransport) {
|
|
592
|
+
// Fatal path, or no engine left to finish close_notify + teardown.
|
|
593
|
+
if (!opts?.keepTransportOpen || opts?.hardDisposeCandidates) {
|
|
594
|
+
void this.transport.close().catch(() => { });
|
|
595
|
+
}
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
// Graceful with live engine: teardownAssociation closes transport after notify.
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Dual association fatal teardown: phase → closed, all candidates + 1.2 flight
|
|
603
|
+
* stopped, RX drops further inject. Invoked from bridge on non-soft 1.3 errors
|
|
604
|
+
* (committed13 fatal alert, 1.3-only version mismatch, RTO exhaust, …).
|
|
605
|
+
* HVR soft (DtlsVersionSelected) never reaches here (filterError).
|
|
606
|
+
* The bridge fires public onError after this returns (a fatal error fires
|
|
607
|
+
* no onClose).
|
|
608
|
+
*/
|
|
609
|
+
failAssociationFromEngine13(err) {
|
|
610
|
+
log("dual association: fatal teardown", err.message);
|
|
611
|
+
this.closeAssociationHard({ hardDisposeCandidates: true });
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* DTLS 1.2 fatal alert / protocol_version on dual association (incl. committed12).
|
|
616
|
+
* Same ownership as 1.3 fatal: phase closed, carrier/transport down, Public API off.
|
|
617
|
+
* Caller fires onError (no onClose) when this returns true.
|
|
618
|
+
*/
|
|
619
|
+
failLegacy12Association(error) {
|
|
620
|
+
if (this.dualPhase === "closed" || this.associationTornDown)
|
|
621
|
+
return false;
|
|
622
|
+
log("dual association: 1.2 fatal teardown", error.message);
|
|
623
|
+
// Preserve fatalError for Flight loops; hard-close owns phase/carrier/transport.
|
|
624
|
+
this.abortLegacy12Flight(error);
|
|
625
|
+
this.closeAssociationHard({ hardDisposeCandidates: true });
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Peer close_notify on the DTLS 1.2 path (committed12 / pure dual 1.2),
|
|
630
|
+
* after the reply was sent or timed out: hard-close the association
|
|
631
|
+
* (dualPhase closed before onClose, so a close() from an onClose listener
|
|
632
|
+
* is a no-op), fire onClose once, then close the transport.
|
|
633
|
+
*/
|
|
634
|
+
finishPeerCloseNotify() {
|
|
635
|
+
log("dual association: 1.2 peer close_notify");
|
|
636
|
+
this.closeAssociationHard({
|
|
637
|
+
hardDisposeCandidates: true,
|
|
638
|
+
keepTransportOpen: true,
|
|
639
|
+
});
|
|
640
|
+
this.notify(this.onClose);
|
|
641
|
+
return this.transport.close().catch(() => { });
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Peer/engine onClose: mark dualPhase closed before public onClose so
|
|
645
|
+
* re-entrant local close() inside handlers is idempotent (no second onClose).
|
|
646
|
+
*/
|
|
647
|
+
prepareAssociationClosedFromEngine() {
|
|
648
|
+
this.connected = false;
|
|
649
|
+
this.associationTornDown = true;
|
|
650
|
+
this.abortLegacy12Flight();
|
|
651
|
+
this.abortAssociationWaits();
|
|
652
|
+
// Base parity: drop TX pin on terminal (hard-close also clears).
|
|
653
|
+
this.clearSendPeerPin();
|
|
654
|
+
this.dualPhase = "closed";
|
|
655
|
+
this.associationGen++;
|
|
656
|
+
this.flight5 = undefined;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Own association peer key + address for demux and 1.2 TX pin.
|
|
660
|
+
* Sets TransportContext.pinnedPeer so Flight/app send ignore hijacked rinfo.
|
|
661
|
+
*/
|
|
662
|
+
pinAssociationPeer(addr, key) {
|
|
663
|
+
if (addr) {
|
|
664
|
+
// replace: dual association / client connect must own TX destination
|
|
665
|
+
// even if a stale pin existed from a prior incomplete probe.
|
|
666
|
+
this.pinSendPeer(addr, "replace");
|
|
667
|
+
this.dualAssociationPeerAddr = this.transport.pinnedPeer
|
|
668
|
+
? [this.transport.pinnedPeer[0], this.transport.pinnedPeer[1]]
|
|
669
|
+
: undefined;
|
|
670
|
+
this.dualAssociationPeerKey =
|
|
671
|
+
key ??
|
|
672
|
+
(0, cookie_1.peerKeyFromAddr)(this.dualAssociationPeerAddr
|
|
673
|
+
? [
|
|
674
|
+
this.dualAssociationPeerAddr[0],
|
|
675
|
+
this.dualAssociationPeerAddr[1],
|
|
676
|
+
]
|
|
677
|
+
: undefined);
|
|
678
|
+
}
|
|
679
|
+
else if (key) {
|
|
680
|
+
this.dualAssociationPeerKey = key;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* True when a captured associationGen still owns the DTLS 1.2 handshake path.
|
|
685
|
+
* False after hard-close or commit to 1.3 (1.2 Flight5 must not resume).
|
|
686
|
+
*/
|
|
687
|
+
isLegacy12PathActive(gen, rxGeneration) {
|
|
688
|
+
if (gen !== this.associationGen)
|
|
689
|
+
return false;
|
|
690
|
+
if (this.dualPhase === "closed")
|
|
691
|
+
return false;
|
|
692
|
+
if (this.dualPhase === "committed13")
|
|
693
|
+
return false;
|
|
694
|
+
if (this.engine13)
|
|
695
|
+
return false;
|
|
696
|
+
return this.isCurrentRxGeneration(rxGeneration);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* True when dual cookie-path work after HVR may still send / throw publicly.
|
|
700
|
+
*/
|
|
701
|
+
isDualCookiePathActive(gen) {
|
|
702
|
+
return (gen === this.associationGen &&
|
|
703
|
+
this.dualPhase === "probing" &&
|
|
704
|
+
!this.engine13);
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Peer close_notify / engine onClose: full association closed (phase, carrier,
|
|
708
|
+
* transport, public API guards). Called after public onClose so handlers can
|
|
709
|
+
* still inspect engine13, then hard-closes association ownership.
|
|
710
|
+
* Does not re-fire onClose (already delivered by bridge; dualPhase already closed).
|
|
711
|
+
*/
|
|
712
|
+
onEngine13PeerOrLocalClose() {
|
|
713
|
+
log("dual association: engine closed → association hard-close");
|
|
714
|
+
// dualPhase already "closed" via prepareAssociationClosedFromEngine.
|
|
715
|
+
this.closeAssociationHard({ hardDisposeCandidates: true });
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Public close: tear down all dual candidates, association carrier, and
|
|
719
|
+
* 1.2 flight timers. Phase becomes permanently `closed`.
|
|
720
|
+
* Fires public onClose once (bridge is disposed before eng.close).
|
|
721
|
+
*/
|
|
722
|
+
async close(options = {}) {
|
|
723
|
+
const sending = options.notify && !this.engine13
|
|
724
|
+
? this.sendAlert(const_3.AlertLevel.warning, const_3.AlertDesc.CloseNotify, {
|
|
725
|
+
...(options.timeoutMs !== undefined && {
|
|
726
|
+
timeoutMs: options.timeoutMs,
|
|
727
|
+
}),
|
|
728
|
+
})
|
|
729
|
+
: undefined;
|
|
730
|
+
// Sync Public-API terminal before any await: send() after close() drops.
|
|
731
|
+
this.markEndedByLocalClose();
|
|
732
|
+
const engineClosesTransport = this.closeAssociationHard({
|
|
733
|
+
firePublicOnClose: true,
|
|
734
|
+
keepTransportOpen: true,
|
|
735
|
+
});
|
|
736
|
+
await sending;
|
|
737
|
+
// A concurrent fatal alert may already be in flight; do not close its
|
|
738
|
+
// transport before the alert has been handed to the peer.
|
|
739
|
+
await this.alertFlushed();
|
|
740
|
+
if (!engineClosesTransport) {
|
|
741
|
+
await this.transport.close().catch(() => { });
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Reject Public data / re-connect APIs while dual is probing or after hard close.
|
|
746
|
+
* Active committed12 / committed13 / pure 1.2 (none) are allowed.
|
|
747
|
+
*/
|
|
748
|
+
assertReadyForApplicationApi(op) {
|
|
749
|
+
if (this.dualPhase === "closed" || this.associationTornDown) {
|
|
750
|
+
throw new Error(`DTLS association is closed; cannot ${op}`);
|
|
751
|
+
}
|
|
752
|
+
if (this.dualPhase === "probing") {
|
|
753
|
+
throw new Error(`DTLS dual probing in progress; cannot ${op} until version is committed`);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Point both UDP onData and carrier inject at the association dispatcher.
|
|
758
|
+
* Used on dual probing entry, after commit12 soft-dispose of 1.3, and after
|
|
759
|
+
* commit13 so carrier.inject never becomes a no-op or engine-only path that
|
|
760
|
+
* bypasses closed/committed guards.
|
|
761
|
+
*/
|
|
762
|
+
bindAssociationInbound(engineWithCarrier) {
|
|
763
|
+
this.transport.socket.onData = this.udpOnMessage;
|
|
764
|
+
if (engineWithCarrier) {
|
|
765
|
+
this.associationCarrier = engineWithCarrier.getHandshakeCarrier();
|
|
766
|
+
}
|
|
767
|
+
else if (!this.associationCarrier) {
|
|
768
|
+
this.associationCarrier =
|
|
769
|
+
this.engine13?.getHandshakeCarrier() ??
|
|
770
|
+
this.parkedEngine13?.getHandshakeCarrier();
|
|
771
|
+
}
|
|
772
|
+
const carrier = this.associationCarrier;
|
|
773
|
+
if (carrier && !carrier.isClosed()) {
|
|
774
|
+
carrier.setInjectHandler((bytes, peer, opts) => this.associationInject(bytes, peer, opts));
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* carrier.inject / dual demux entry: same path as UDP onData so 1.3 SH/HRR
|
|
779
|
+
* commits via association (restores engine13) rather than a silent park complete.
|
|
780
|
+
*
|
|
781
|
+
* When `peer` is omitted, address is filled from `transport.rinfo` (then
|
|
782
|
+
* association pin) before the peer gate — so inject of association-path
|
|
783
|
+
* datagrams without an explicit peer still matches the pin.
|
|
784
|
+
*/
|
|
785
|
+
associationInject(bytes, peer, opts) {
|
|
786
|
+
if (this.dualPhase === "closed")
|
|
787
|
+
return;
|
|
788
|
+
if (this.associationCarrier?.isStaleInboundInject?.())
|
|
789
|
+
return;
|
|
790
|
+
// Parse peer first; do NOT write transport.rinfo until peer gate accepts
|
|
791
|
+
// (otherwise spoofed inject redirects 1.2 Flight / app send via rinfo).
|
|
792
|
+
let addr;
|
|
793
|
+
if (peer != null) {
|
|
794
|
+
if (Array.isArray(peer)) {
|
|
795
|
+
addr = [peer[0], peer[1]];
|
|
796
|
+
}
|
|
797
|
+
else if (typeof peer === "string") {
|
|
798
|
+
const i = peer.lastIndexOf(":");
|
|
799
|
+
if (i > 0) {
|
|
800
|
+
addr = [peer.slice(0, i), Number(peer.slice(i + 1))];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
else if (peer.address != null && peer.port != null) {
|
|
804
|
+
addr = [peer.address, peer.port];
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// Peer omitted: fill from last rinfo, then association pin (TX ownership).
|
|
808
|
+
if (!addr) {
|
|
809
|
+
const t = this.options.transport;
|
|
810
|
+
if (t.rinfo?.address != null && t.rinfo?.port != null) {
|
|
811
|
+
addr = [t.rinfo.address, t.rinfo.port];
|
|
812
|
+
}
|
|
813
|
+
else if (this.dualAssociationPeerAddr) {
|
|
814
|
+
addr = [
|
|
815
|
+
this.dualAssociationPeerAddr[0],
|
|
816
|
+
this.dualAssociationPeerAddr[1],
|
|
817
|
+
];
|
|
818
|
+
}
|
|
819
|
+
else if (this.transport.pinnedPeer) {
|
|
820
|
+
addr = [this.transport.pinnedPeer[0], this.transport.pinnedPeer[1]];
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
// Peer gate before mutating shared transport.rinfo (all phases with a pin:
|
|
824
|
+
// pure/none, probing, committed12/13). isAssociationPeer is true when unpinned.
|
|
825
|
+
if (!this.isAssociationPeer(addr)) {
|
|
826
|
+
log("dual association: inject drop non-association peer (rinfo unchanged)", (0, cookie_1.peerKeyFromAddr)(addr ? [addr[0], addr[1]] : undefined));
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
if (addr) {
|
|
830
|
+
const t = this.options.transport;
|
|
831
|
+
t.rinfo = { address: addr[0], port: addr[1] };
|
|
832
|
+
}
|
|
833
|
+
return this.udpOnMessage(Buffer.from(bytes), addr, opts);
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* True when inbound source may deliver for this association.
|
|
837
|
+
* Same policy as 1.3 {@link Dtls13Connection.allowsAssociationPeer}:
|
|
838
|
+
* - no pin yet: allow
|
|
839
|
+
* - authenticated-single-peer: always allow (transport is identity;
|
|
840
|
+
* addressless and alternate 5-tuples are not an auth boundary)
|
|
841
|
+
* - datagram-address: require matching peer key
|
|
842
|
+
*
|
|
843
|
+
* After dual → 1.2 the 1.3 candidate is gone; this fallback must still
|
|
844
|
+
* honor peerIdentityMode (do not require 5-tuple match on ICE).
|
|
845
|
+
*/
|
|
846
|
+
isAssociationPeer(addr) {
|
|
847
|
+
const peer = addr ? [addr[0], addr[1]] : undefined;
|
|
848
|
+
const candidate = this.engine13 ?? this.parkedEngine13;
|
|
849
|
+
if (candidate) {
|
|
850
|
+
return candidate.matchesAssociationPeer(peer);
|
|
851
|
+
}
|
|
852
|
+
if (this.peerIdentityMode === "authenticated-single-peer")
|
|
853
|
+
return true;
|
|
854
|
+
const expected = this.dualAssociationPeerKey;
|
|
855
|
+
if (!expected)
|
|
856
|
+
return true;
|
|
857
|
+
const key = (0, cookie_1.peerKeyFromAddr)(peer);
|
|
858
|
+
if (!key || key === "unknown")
|
|
859
|
+
return false;
|
|
860
|
+
return key === expected;
|
|
861
|
+
}
|
|
862
|
+
/** Commit dual probe to DTLS 1.2: stop 1.3 candidate and alert suppression. */
|
|
863
|
+
commitDualTo12() {
|
|
864
|
+
if (this.dualPhase === "committed12" ||
|
|
865
|
+
this.dualPhase === "committed13" ||
|
|
866
|
+
this.dualPhase === "closed") {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
log("dual association: commit DTLS 1.2");
|
|
870
|
+
// The current legacy handler is the owner that selected DTLS 1.2. Keep
|
|
871
|
+
// its ownership token valid so a later parse/validation error (for example
|
|
872
|
+
// malformed use_srtp) is reported as a current-association failure rather
|
|
873
|
+
// than being mistaken for a stale callback. Ownership is invalidated
|
|
874
|
+
// only when the 1.2 candidate is actually abandoned (close/renegotiation
|
|
875
|
+
// or commit to DTLS 1.3).
|
|
876
|
+
this.dualPhase = "committed12";
|
|
877
|
+
this.dualResume = undefined;
|
|
878
|
+
// Soft-dispose parked 1.3 (stops RTO via closed + flightId-scoped
|
|
879
|
+
// scheduleRetransmit; equivalent to 1.2 cancelFlightTimers /
|
|
880
|
+
// flightTxGeneration bump). Do not hard-close the shared carrier.
|
|
881
|
+
if (this.parkedEngine13) {
|
|
882
|
+
// Remember carrier before soft dispose so inject can be rebound.
|
|
883
|
+
this.associationCarrier = this.parkedEngine13.getHandshakeCarrier();
|
|
884
|
+
// Drop bridge before soft close so stale engine events cannot fire.
|
|
885
|
+
this.unbridgeEngine13();
|
|
886
|
+
this.parkedEngine13.releaseForVersionFallback();
|
|
887
|
+
this.parkedEngine13 = undefined;
|
|
888
|
+
}
|
|
889
|
+
// Reclaim carrier.inject → association 1.2 path (not the no-op left by
|
|
890
|
+
// releaseForVersionFallback). UDP onData already points here from probing.
|
|
891
|
+
this.bindAssociationInbound();
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Dual negotiation extensions: advertise all configured versions in
|
|
895
|
+
* preference order and keep key_share / 0x1301 so a 1.3-capable server can
|
|
896
|
+
* still select 1.3 after an unauthenticated HVR. 1.2-only peers ignore 1.3
|
|
897
|
+
* extensions. HVR never finalizes the version.
|
|
898
|
+
*/
|
|
899
|
+
setupExtensionsForDualCookiePath() {
|
|
900
|
+
this.extensions = [];
|
|
901
|
+
this.setupExtensions();
|
|
902
|
+
// supported_versions in local preference order (protocolVersions)
|
|
903
|
+
const sv = supportedVersions_1.SupportedVersions.forClient((0, version_1.protocolVersionsToWire)(this.protocolVersions));
|
|
904
|
+
this.extensions.unshift(sv.clientExtension);
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* After HVR: continue dual negotiation with the **same** ClientHello (same
|
|
908
|
+
* random) plus DTLS 1.2 legacy cookie. Never treat HVR as final version pick.
|
|
909
|
+
* Aborts silently if the association closes or commits to 1.3 mid-flight.
|
|
910
|
+
*/
|
|
911
|
+
async continueDualAfterHvr(cookie) {
|
|
912
|
+
const gen = this.associationGen;
|
|
913
|
+
if (!this.isDualCookiePathActive(gen))
|
|
914
|
+
return;
|
|
915
|
+
try {
|
|
916
|
+
if (this.dualResume) {
|
|
917
|
+
await this.resendDualClientHelloWithCookie(cookie, gen);
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
await this.sendDualNegotiationClientHello(cookie, gen);
|
|
921
|
+
}
|
|
922
|
+
catch (err) {
|
|
923
|
+
// close / version commit during Flight1 — do not surface as public onError
|
|
924
|
+
if (!this.isDualCookiePathActive(gen))
|
|
925
|
+
return;
|
|
926
|
+
throw err;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Resend the dual CH already exported from the 1.3 engine (or prior dual CH),
|
|
931
|
+
* only adding/replacing the legacy cookie for the DTLS 1.2 cookie path.
|
|
932
|
+
*
|
|
933
|
+
* **Important:** dualResume keeps the original CH-A body (no legacy cookie).
|
|
934
|
+
* A legitimate dual 1.3 server may still answer CH-A (HRR/SH) after a
|
|
935
|
+
* spoofed/stale HVR; 1.3 resume must prime with the CH the server saw.
|
|
936
|
+
* Random + ECDHE keyPair are unchanged so flight2 / key_share stay aligned.
|
|
937
|
+
*/
|
|
938
|
+
async resendDualClientHelloWithCookie(legacyCookie, gen = this.associationGen) {
|
|
939
|
+
if (!this.isDualCookiePathActive(gen))
|
|
940
|
+
return;
|
|
941
|
+
if (!this.dualResume) {
|
|
942
|
+
throw new Error("dual resume ClientHello missing for HVR cookie path");
|
|
943
|
+
}
|
|
944
|
+
// Build cookie CH from original dualResume without mutating 1.3 resume material.
|
|
945
|
+
const hello = hello_1.ClientHello.deSerialize(this.dualResume.clientHelloBody);
|
|
946
|
+
hello.cookie = legacyCookie ? Buffer.from(legacyCookie) : Buffer.from([]);
|
|
947
|
+
// HVR cookie path: merge 1.2-only extensions (EMS, renegotiation_info)
|
|
948
|
+
// that CH-A omitted. Cookie-less SH-only park (Chrome ICE skips HVR)
|
|
949
|
+
// must retransmit CH-A bit-identically — the server already answered
|
|
950
|
+
// that hello, and a mutated CH desyncs the 1.2 transcript.
|
|
951
|
+
if (legacyCookie && legacyCookie.length > 0) {
|
|
952
|
+
const have = new Set(hello.extensions.map((e) => e.type));
|
|
953
|
+
for (const ext of this.extensions) {
|
|
954
|
+
if (!have.has(ext.type)) {
|
|
955
|
+
hello.extensions.push(ext);
|
|
956
|
+
have.add(ext.type);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
// Clear messageSeq so Flight1 re-assigns seq 0 for this transmission
|
|
961
|
+
hello.messageSeq = undefined;
|
|
962
|
+
if (!this.isDualCookiePathActive(gen))
|
|
963
|
+
return;
|
|
964
|
+
await new flight1_1.Flight1(this.transport, this.dtls, this.cipher).exec(this.extensions, hello);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Build & send dual CH: versions in preference order, 1.3 suites/extensions
|
|
968
|
+
* + 1.2 suites for true dual peers. Stores ECDHE material for possible 1.3
|
|
969
|
+
* resume when ServerHello selects 1.3.
|
|
970
|
+
*/
|
|
971
|
+
async sendDualNegotiationClientHello(legacyCookie, gen = this.associationGen) {
|
|
972
|
+
if (!this.isDualCookiePathActive(gen))
|
|
973
|
+
return;
|
|
974
|
+
const named = this.options.namedGroups?.length && this.options.namedGroups.length > 0
|
|
975
|
+
? [...this.options.namedGroups]
|
|
976
|
+
: [
|
|
977
|
+
const_1.NamedCurveAlgorithm.x25519_29,
|
|
978
|
+
const_1.NamedCurveAlgorithm.secp256r1_23,
|
|
979
|
+
];
|
|
980
|
+
const group = named[0];
|
|
981
|
+
const keyPair = (0, namedCurve_1.generateKeyPair)(group);
|
|
982
|
+
const curves = ellipticCurves_1.EllipticCurves.createEmpty();
|
|
983
|
+
curves.data = named;
|
|
984
|
+
// 1.3 CertificateVerify schemes + rsa_pkcs1 for DTLS 1.2 peers
|
|
985
|
+
const schemes = [...signatureAlgorithms_1.DEFAULT_SIGNATURE_SCHEMES];
|
|
986
|
+
if (!schemes.includes(0x0401))
|
|
987
|
+
schemes.push(0x0401);
|
|
988
|
+
// Preference order from Options.protocolVersions (not hard-coded 1.3-first)
|
|
989
|
+
const wireVersions = (0, version_1.protocolVersionsToWire)(this.protocolVersions);
|
|
990
|
+
const extensions = [
|
|
991
|
+
supportedVersions_1.SupportedVersions.forClient(wireVersions).clientExtension,
|
|
992
|
+
curves.extension,
|
|
993
|
+
keyShare_1.KeyShare.forClient([{ group, keyExchange: keyPair.publicKey }])
|
|
994
|
+
.clientExtension,
|
|
995
|
+
signatureAlgorithms_1.SignatureAlgorithms.create(schemes).extension,
|
|
996
|
+
...this.extensions.filter((e) => e.type !== supportedVersions_1.SupportedVersions.type &&
|
|
997
|
+
e.type !== ellipticCurves_1.EllipticCurves.type &&
|
|
998
|
+
e.type !== signatureAlgorithms_1.SignatureAlgorithms.type &&
|
|
999
|
+
e.type !== keyShare_1.KeyShare.type &&
|
|
1000
|
+
e.type !== cookie_1.CookieExtension.type),
|
|
1001
|
+
];
|
|
1002
|
+
// Suite list: when preferring 1.2, list 1.2 suites first (cosmetic / legacy peers)
|
|
1003
|
+
const prefer13 = this.protocolVersions[0] === version_1.DtlsVersion.V1_3;
|
|
1004
|
+
const suite13 = const_1.CipherSuite.TLS_AES_128_GCM_SHA256_0x1301;
|
|
1005
|
+
const suites12 = [
|
|
1006
|
+
const_1.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195,
|
|
1007
|
+
const_1.CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199,
|
|
1008
|
+
];
|
|
1009
|
+
const cipherSuites = prefer13
|
|
1010
|
+
? [suite13, ...suites12]
|
|
1011
|
+
: [...suites12, suite13];
|
|
1012
|
+
const hello = new hello_1.ClientHello({ major: 255 - 1, minor: 255 - 2 }, new random_1.DtlsRandom(), Buffer.from([]), legacyCookie ? Buffer.from(legacyCookie) : Buffer.from([]), cipherSuites, [0], extensions);
|
|
1013
|
+
if (!this.isDualCookiePathActive(gen))
|
|
1014
|
+
return;
|
|
1015
|
+
const body = hello.serialize();
|
|
1016
|
+
this.dualResume = {
|
|
1017
|
+
clientHelloBody: Buffer.from(body),
|
|
1018
|
+
keyPair: {
|
|
1019
|
+
publicKey: Buffer.from(keyPair.publicKey),
|
|
1020
|
+
privateKey: Buffer.from(keyPair.privateKey),
|
|
1021
|
+
curve: group,
|
|
1022
|
+
},
|
|
1023
|
+
group,
|
|
1024
|
+
};
|
|
1025
|
+
// Flight retransmit until HVR (flight 3) or we stop on 1.3 resume
|
|
1026
|
+
if (!this.isDualCookiePathActive(gen))
|
|
1027
|
+
return;
|
|
1028
|
+
await new flight1_1.Flight1(this.transport, this.dtls, this.cipher).exec(this.extensions, hello);
|
|
1029
|
+
}
|
|
1030
|
+
/** 32-byte ServerHello.random for DOWNGRD checks. */
|
|
1031
|
+
serverHelloRandom32(sh) {
|
|
1032
|
+
return random_1.DtlsRandom.bytes32(sh.random);
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* During dual probing, classify a ServerHello body before version commit.
|
|
1036
|
+
* - dtls13: supported_versions selected 1.3 (and suite consistent)
|
|
1037
|
+
* - dtls12: fully parsed legitimate 1.2 SH (cipher, legacy version, optional SV)
|
|
1038
|
+
* - drop: malformed / inconsistent wire (keep parked 1.3, no commit)
|
|
1039
|
+
* - error: actionable protocol failure (e.g. unknown selected version)
|
|
1040
|
+
*/
|
|
1041
|
+
classifyProbingServerHello(fragment) {
|
|
1042
|
+
let sh;
|
|
1043
|
+
try {
|
|
1044
|
+
sh = hello_2.ServerHello.deSerialize(fragment);
|
|
1045
|
+
}
|
|
1046
|
+
catch (e) {
|
|
1047
|
+
return {
|
|
1048
|
+
kind: "drop",
|
|
1049
|
+
reason: e instanceof Error ? e.message : "ServerHello parse failed",
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
// Required fields must be present after deserialize
|
|
1053
|
+
if (!sh.serverVersion ||
|
|
1054
|
+
sh.cipherSuite == null ||
|
|
1055
|
+
sh.random?.random_bytes == null ||
|
|
1056
|
+
!Buffer.isBuffer(sh.sessionId)) {
|
|
1057
|
+
return { kind: "drop", reason: "ServerHello incomplete fields" };
|
|
1058
|
+
}
|
|
1059
|
+
// Round-trip: reject trailing garbage / incomplete extension parse
|
|
1060
|
+
try {
|
|
1061
|
+
const round = sh.serialize();
|
|
1062
|
+
if (round.length !== fragment.length) {
|
|
1063
|
+
return {
|
|
1064
|
+
kind: "drop",
|
|
1065
|
+
reason: `ServerHello length mismatch serialize=${round.length} wire=${fragment.length}`,
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
catch (e) {
|
|
1070
|
+
return {
|
|
1071
|
+
kind: "drop",
|
|
1072
|
+
reason: e instanceof Error ? e.message : "ServerHello re-serialize failed",
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
const legacyWire = (0, version_1.wireVersionToNumber)(sh.serverVersion);
|
|
1076
|
+
// DTLS ServerHello.legacy_version is DTLS 1.2 (0xfefd) for both 1.2 and 1.3
|
|
1077
|
+
if (legacyWire !== version_1.DTLS_1_2_VERSION) {
|
|
1078
|
+
return {
|
|
1079
|
+
kind: "drop",
|
|
1080
|
+
reason: `unexpected ServerHello.serverVersion 0x${legacyWire.toString(16)}`,
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
const versionsExt = sh.extensions?.find((e) => e.type === supportedVersions_1.SupportedVersions.type);
|
|
1084
|
+
if (versionsExt) {
|
|
1085
|
+
let sv;
|
|
1086
|
+
try {
|
|
1087
|
+
sv = supportedVersions_1.SupportedVersions.fromData(versionsExt.data, true);
|
|
1088
|
+
}
|
|
1089
|
+
catch (e) {
|
|
1090
|
+
return {
|
|
1091
|
+
kind: "drop",
|
|
1092
|
+
reason: e instanceof Error ? e.message : "supported_versions parse failed",
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
if (sv.selected === version_1.DTLS_1_3_VERSION) {
|
|
1096
|
+
// 1.3 selection should use a 1.3 suite
|
|
1097
|
+
if (sh.cipherSuite === const_1.CipherSuite.TLS_AES_128_GCM_SHA256_0x1301) {
|
|
1098
|
+
return { kind: "dtls13", sh };
|
|
1099
|
+
}
|
|
1100
|
+
// Inconsistent: 1.3 selected with 1.2 suite — do not commit either way
|
|
1101
|
+
return {
|
|
1102
|
+
kind: "drop",
|
|
1103
|
+
reason: "supported_versions=1.3 but cipher suite is not TLS 1.3",
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
if (sv.selected === version_1.DTLS_1_2_VERSION) {
|
|
1107
|
+
// fall through to 1.2 suite checks
|
|
1108
|
+
}
|
|
1109
|
+
else if (sv.selected != null) {
|
|
1110
|
+
return {
|
|
1111
|
+
kind: "error",
|
|
1112
|
+
error: new version_1.ProtocolVersionError(`unsupported ServerHello selected version 0x${sv.selected.toString(16)}`),
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
return { kind: "drop", reason: "supported_versions missing selected" };
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
// DTLS 1.2 path: reject TLS 1.3-only suite
|
|
1120
|
+
if (sh.cipherSuite === const_1.CipherSuite.TLS_AES_128_GCM_SHA256_0x1301) {
|
|
1121
|
+
return {
|
|
1122
|
+
kind: "drop",
|
|
1123
|
+
reason: "TLS 1.3 cipher suite without DTLS 1.3 selected version",
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
// Known 1.2 suites we negotiate (reject unknown / garbage suite codes)
|
|
1127
|
+
const suite12ok = sh.cipherSuite ===
|
|
1128
|
+
const_1.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256_49195 ||
|
|
1129
|
+
sh.cipherSuite ===
|
|
1130
|
+
const_1.CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256_49199;
|
|
1131
|
+
if (!suite12ok) {
|
|
1132
|
+
return {
|
|
1133
|
+
kind: "drop",
|
|
1134
|
+
reason: `unknown or unsupported DTLS 1.2 cipher suite 0x${Number(sh.cipherSuite).toString(16)}`,
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
// Null compression only
|
|
1138
|
+
if (sh.compressionMethod !== 0) {
|
|
1139
|
+
return {
|
|
1140
|
+
kind: "drop",
|
|
1141
|
+
reason: `unsupported compression_method ${sh.compressionMethod}`,
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
return {
|
|
1145
|
+
kind: "dtls12",
|
|
1146
|
+
sh,
|
|
1147
|
+
hasDowngradeSentinel: (0, version_1.hasTlsDowngradeSentinel)(this.serverHelloRandom32(sh)),
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* True when a DTLSPlaintext datagram contains ServerHello/HRR that selects
|
|
1152
|
+
* DTLS 1.3 via supported_versions (extension type 43).
|
|
1153
|
+
*/
|
|
1154
|
+
datagramSelectsDtls13(data) {
|
|
1155
|
+
try {
|
|
1156
|
+
let off = 0;
|
|
1157
|
+
while (off + 13 <= data.length) {
|
|
1158
|
+
const contentType = data[off];
|
|
1159
|
+
const contentLen = data.readUInt16BE(off + 11);
|
|
1160
|
+
if (contentLen < 0 || off + 13 + contentLen > data.length)
|
|
1161
|
+
break;
|
|
1162
|
+
const body = data.subarray(off + 13, off + 13 + contentLen);
|
|
1163
|
+
if (contentType === const_3.ContentType.handshake && body.length >= 12) {
|
|
1164
|
+
const msgType = body[0];
|
|
1165
|
+
if (msgType === const_2.HandshakeType.server_hello_2) {
|
|
1166
|
+
// DTLS HS fragment: type(1) length(3) message_seq(2)
|
|
1167
|
+
// fragment_offset(3) fragment_length(3) + body
|
|
1168
|
+
const fragLen = (body[9] << 16) | (body[10] << 8) | body[11];
|
|
1169
|
+
const hsBody = body.subarray(12, 12 + Math.min(fragLen, body.length - 12));
|
|
1170
|
+
if (hsBody.length >= 2) {
|
|
1171
|
+
try {
|
|
1172
|
+
const sh = hello_2.ServerHello.deSerialize(hsBody);
|
|
1173
|
+
const versionsExt = sh.extensions.find((e) => e.type === supportedVersions_1.SupportedVersions.type);
|
|
1174
|
+
if (versionsExt) {
|
|
1175
|
+
const sv = supportedVersions_1.SupportedVersions.fromData(versionsExt.data, true);
|
|
1176
|
+
if (sv.selected === version_1.DTLS_1_3_VERSION)
|
|
1177
|
+
return true;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
catch {
|
|
1181
|
+
// not a complete ServerHello — keep scanning
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
off += 13 + contentLen;
|
|
1187
|
+
if (contentLen === 0)
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
catch {
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Dual path: ServerHello/HRR selected DTLS 1.3 — prefer unparking the parked
|
|
1198
|
+
* CH-A engine (keeps transcript continuity); else prime a fresh engine from
|
|
1199
|
+
* dualResume and reinject the datagram.
|
|
1200
|
+
*/
|
|
1201
|
+
resumeDtls13FromDualPath(datagram, rxGeneration) {
|
|
1202
|
+
if (this.dualPhase === "closed" || this.dualPhase === "committed12") {
|
|
1203
|
+
// Late 1.3 after close or 1.2 commit must not reverse the association.
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
// A ServerHello accepted by the old ICE carrier must not select a DTLS
|
|
1207
|
+
// version for the new carrier generation. This dispatcher path commits
|
|
1208
|
+
// synchronously, so it needs the same receive-generation check as the
|
|
1209
|
+
// asynchronous legacy handshake path.
|
|
1210
|
+
if (!this.isCurrentRxGeneration(rxGeneration)) {
|
|
1211
|
+
log("dual association: drop stale ServerHello generation");
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const rinfo = this.options.transport.rinfo;
|
|
1215
|
+
const parked = this.parkedEngine13;
|
|
1216
|
+
const material = this.dualResume;
|
|
1217
|
+
// No parked engine and no CH-A material: cannot complete 1.3 resume.
|
|
1218
|
+
// Tear down association (do not leave dualPhase=committed13 without engine).
|
|
1219
|
+
if ((!parked || parked.isClosed()) && !material) {
|
|
1220
|
+
this.reportLegacy12Fatal(new version_1.ProtocolVersionError("dual path selected DTLS 1.3 but dual ClientHello material is missing"));
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
// Stop 1.2 Flight1 retransmit by advancing flight only — never set fatalError
|
|
1224
|
+
// for a successful version commit (would surface as delayed public onError).
|
|
1225
|
+
if (!this.isCurrentRxGeneration(rxGeneration)) {
|
|
1226
|
+
log("dual association: ServerHello generation changed before commit");
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
this.abortLegacy12Flight();
|
|
1230
|
+
this.invalidateLegacy12HandshakeOwnership();
|
|
1231
|
+
this.dualPhase = "committed13";
|
|
1232
|
+
// Invalidate in-flight 1.2 handleHandshakes / Flight5 after version commit.
|
|
1233
|
+
this.associationGen++;
|
|
1234
|
+
this.flight5 = undefined;
|
|
1235
|
+
this.parkedEngine13 = undefined;
|
|
1236
|
+
this.dualResume = undefined;
|
|
1237
|
+
if (parked && !parked.isClosed()) {
|
|
1238
|
+
log("dual association: ServerHello selected DTLS 1.3 — unpark parked engine");
|
|
1239
|
+
parked.unparkFromDualProbe();
|
|
1240
|
+
// Events already bridged at startEngine13; re-own public engine13 handle.
|
|
1241
|
+
this.engine13 = parked;
|
|
1242
|
+
// Association keeps UDP + carrier.inject; engine RX only via injectDatagram.
|
|
1243
|
+
this.bindAssociationInbound(parked);
|
|
1244
|
+
// Wake association-level readiness waiters after the parked candidate is
|
|
1245
|
+
// active again and before the triggering datagram is reprocessed.
|
|
1246
|
+
this.notifyEngine13Selected();
|
|
1247
|
+
parked.injectDatagram(datagram, rinfo, rxGeneration);
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
// material is defined: early return when both parked and material missing.
|
|
1251
|
+
const resumeMaterial = material;
|
|
1252
|
+
log("dual association: ServerHello selected DTLS 1.3 — resume 1.3 engine from dualResume");
|
|
1253
|
+
const engine = new connection_1.Dtls13Connection({
|
|
1254
|
+
transport: this.options.transport,
|
|
1255
|
+
cert: this.options.cert,
|
|
1256
|
+
key: this.options.key,
|
|
1257
|
+
srtpProfiles: this.options.srtpProfiles,
|
|
1258
|
+
extendedMasterSecret: this.options.extendedMasterSecret,
|
|
1259
|
+
certificateRequest: this.options.certificateRequest,
|
|
1260
|
+
addressValidation: this.options.addressValidation,
|
|
1261
|
+
peerIdentityMode: this.peerIdentityMode,
|
|
1262
|
+
groups: this.options.namedGroups
|
|
1263
|
+
? [...this.options.namedGroups]
|
|
1264
|
+
: undefined,
|
|
1265
|
+
mtu: this.options.mtu,
|
|
1266
|
+
maxEarlyAppDataRecords: this.options.maxEarlyAppDataRecords,
|
|
1267
|
+
maxEarlyAppDataBytes: this.options.maxEarlyAppDataBytes,
|
|
1268
|
+
// Same injected carrier instance as Epic 2; soft HVR detach must not
|
|
1269
|
+
// have permanently closed it (releaseForVersionFallback).
|
|
1270
|
+
carrier: this.options.handshakeCarrier,
|
|
1271
|
+
offeredProtocolVersions: this.protocolVersions,
|
|
1272
|
+
}, abstract_1.SessionType.CLIENT);
|
|
1273
|
+
// Prime with original CH-A (pre-cookie) so transcript/ECDHE match the
|
|
1274
|
+
// server response for the first dual ClientHello, not a post-HVR rewrite.
|
|
1275
|
+
engine.primeFromSentClientHello(resumeMaterial);
|
|
1276
|
+
this.bridgeEngine13(engine);
|
|
1277
|
+
// Constructor stole transport.onData / inject — reclaim for association.
|
|
1278
|
+
this.bindAssociationInbound(engine);
|
|
1279
|
+
// Full datagram reinject so coalesced epoch-2 records are not lost
|
|
1280
|
+
engine.injectDatagram(datagram, rinfo, rxGeneration);
|
|
82
1281
|
}
|
|
83
1282
|
async connect() {
|
|
1283
|
+
// Terminal / probing must not fall through to pure 1.2 Flight1 or re-HS.
|
|
1284
|
+
if (this.dualPhase === "closed" || this.associationTornDown) {
|
|
1285
|
+
throw new Error("DTLS association is closed; cannot connect");
|
|
1286
|
+
}
|
|
1287
|
+
if (this.dualPhase === "probing") {
|
|
1288
|
+
throw new Error("DTLS dual probing in progress; connect() already started (wait for version commit)");
|
|
1289
|
+
}
|
|
1290
|
+
// Pin 1.2 TX destination from configured rinfo before any flight retransmit.
|
|
1291
|
+
// replace: connect() is the client association start of truth for peer TX.
|
|
1292
|
+
this.pinSendPeerFromTransportRinfo("replace");
|
|
1293
|
+
this.pinAssociationPeer(this.transport.pinnedPeer
|
|
1294
|
+
? [this.transport.pinnedPeer[0], this.transport.pinnedPeer[1]]
|
|
1295
|
+
: undefined);
|
|
1296
|
+
if (this.engine13) {
|
|
1297
|
+
await this.engine13.connect();
|
|
1298
|
+
// After 1.3 connect pin, sync association pin for dual fallout.
|
|
1299
|
+
const eng = this.engine13;
|
|
1300
|
+
if (eng) {
|
|
1301
|
+
this.pinAssociationPeer(eng.getPeerAddr(), eng.getExpectedPeerKey());
|
|
1302
|
+
}
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
await this.connect12();
|
|
1306
|
+
}
|
|
1307
|
+
async connect12() {
|
|
1308
|
+
this.pinSendPeerFromTransportRinfo("replace");
|
|
1309
|
+
this.pinAssociationPeer(this.transport.pinnedPeer
|
|
1310
|
+
? [this.transport.pinnedPeer[0], this.transport.pinnedPeer[1]]
|
|
1311
|
+
: undefined);
|
|
84
1312
|
await new flight1_1.Flight1(this.transport, this.dtls, this.cipher).exec(this.extensions);
|
|
85
1313
|
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Epoch-0 fatal illegal_parameter (47) only — used while dual-probing to
|
|
1316
|
+
* ignore DTLS 1.3 servers rejecting a non-empty legacy_cookie ClientHello.
|
|
1317
|
+
* Must not swallow epoch≥1 or non-illegal_parameter actionable alerts.
|
|
1318
|
+
*/
|
|
1319
|
+
datagramIsEpoch0IllegalParameterAlert(data) {
|
|
1320
|
+
try {
|
|
1321
|
+
if (data.length < 15)
|
|
1322
|
+
return false;
|
|
1323
|
+
const contentType = data[0];
|
|
1324
|
+
if (contentType !== const_3.ContentType.alert)
|
|
1325
|
+
return false;
|
|
1326
|
+
// DTLSPlaintext: type(1) version(2) epoch(2) seq(6) length(2) body
|
|
1327
|
+
const epoch = data.readUInt16BE(3);
|
|
1328
|
+
if (epoch !== 0)
|
|
1329
|
+
return false;
|
|
1330
|
+
const contentLen = data.readUInt16BE(11);
|
|
1331
|
+
if (contentLen < 2 || 13 + contentLen > data.length)
|
|
1332
|
+
return false;
|
|
1333
|
+
const level = data[13];
|
|
1334
|
+
const description = data[14];
|
|
1335
|
+
return level >= 2 && description === const_3.AlertDesc.IllegalParameter;
|
|
1336
|
+
}
|
|
1337
|
+
catch {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
86
1341
|
}
|
|
87
1342
|
exports.DtlsClient = DtlsClient;
|
|
88
1343
|
//# sourceMappingURL=client.js.map
|