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/socket.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DtlsSocket = void 0;
|
|
3
|
+
exports.DtlsVersion = exports.DtlsSocket = void 0;
|
|
4
4
|
const promises_1 = require("timers/promises");
|
|
5
|
+
const alert_1 = require("./alert");
|
|
5
6
|
const const_1 = require("./cipher/const");
|
|
6
7
|
const prf_1 = require("./cipher/prf");
|
|
7
8
|
const abstract_1 = require("./cipher/suites/abstract");
|
|
@@ -9,20 +10,32 @@ const cipher_1 = require("./context/cipher");
|
|
|
9
10
|
const dtls_1 = require("./context/dtls");
|
|
10
11
|
const srtp_1 = require("./context/srtp");
|
|
11
12
|
const transport_1 = require("./context/transport");
|
|
13
|
+
const cookie_1 = require("./handshake/extensions/cookie");
|
|
12
14
|
const ellipticCurves_1 = require("./handshake/extensions/ellipticCurves");
|
|
13
15
|
const extendedMasterSecret_1 = require("./handshake/extensions/extendedMasterSecret");
|
|
14
16
|
const renegotiationIndication_1 = require("./handshake/extensions/renegotiationIndication");
|
|
15
17
|
const signature_1 = require("./handshake/extensions/signature");
|
|
16
18
|
const useSrtp_1 = require("./handshake/extensions/useSrtp");
|
|
17
19
|
const common_1 = require("./imports/common");
|
|
20
|
+
const peer_1 = require("./peer");
|
|
18
21
|
const builder_1 = require("./record/builder");
|
|
19
22
|
const const_2 = require("./record/const");
|
|
20
|
-
const
|
|
23
|
+
const reassembler_1 = require("./record/message/reassembler");
|
|
21
24
|
const receive_1 = require("./record/receive");
|
|
25
|
+
const version_1 = require("./version");
|
|
26
|
+
Object.defineProperty(exports, "DtlsVersion", { enumerable: true, get: function () { return version_1.DtlsVersion; } });
|
|
22
27
|
const { decode, types } = common_1.binaryData;
|
|
23
28
|
const log = (0, common_1.debug)("werift-dtls : packages/dtls/src/socket.ts : log");
|
|
24
29
|
const err = (0, common_1.debug)("werift-dtls : packages/dtls/src/socket.ts : err");
|
|
25
30
|
class DtlsSocket {
|
|
31
|
+
get connected() {
|
|
32
|
+
return this._connected;
|
|
33
|
+
}
|
|
34
|
+
set connected(value) {
|
|
35
|
+
this._connected = value;
|
|
36
|
+
if (value)
|
|
37
|
+
this.legacyReadinessReached = true;
|
|
38
|
+
}
|
|
26
39
|
constructor(options, sessionType) {
|
|
27
40
|
Object.defineProperty(this, "options", {
|
|
28
41
|
enumerable: true,
|
|
@@ -48,18 +61,31 @@ class DtlsSocket {
|
|
|
48
61
|
writable: true,
|
|
49
62
|
value: new common_1.Event()
|
|
50
63
|
});
|
|
64
|
+
/**
|
|
65
|
+
* Fires with a {@link DtlsAlertError} when the connection ends with a fatal
|
|
66
|
+
* alert (received from the peer, or sent by this side when it rejected the
|
|
67
|
+
* peer certificate), and with other errors raised by the handshake.
|
|
68
|
+
*/
|
|
51
69
|
Object.defineProperty(this, "onError", {
|
|
52
70
|
enumerable: true,
|
|
53
71
|
configurable: true,
|
|
54
72
|
writable: true,
|
|
55
73
|
value: new common_1.Event()
|
|
56
74
|
});
|
|
75
|
+
/** Fires once when the peer closed the connection with close_notify. */
|
|
57
76
|
Object.defineProperty(this, "onClose", {
|
|
58
77
|
enumerable: true,
|
|
59
78
|
configurable: true,
|
|
60
79
|
writable: true,
|
|
61
80
|
value: new common_1.Event()
|
|
62
81
|
});
|
|
82
|
+
/** Fires for every alert received from the peer (before onClose / onError). */
|
|
83
|
+
Object.defineProperty(this, "onAlert", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: new common_1.Event()
|
|
88
|
+
});
|
|
63
89
|
Object.defineProperty(this, "transport", {
|
|
64
90
|
enumerable: true,
|
|
65
91
|
configurable: true,
|
|
@@ -84,74 +110,135 @@ class DtlsSocket {
|
|
|
84
110
|
writable: true,
|
|
85
111
|
value: new srtp_1.SrtpContext()
|
|
86
112
|
});
|
|
87
|
-
Object.defineProperty(this, "
|
|
113
|
+
Object.defineProperty(this, "_connected", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: false
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* DTLS 1.2 readiness latch. 1.2 has no separate milestones, so the first
|
|
121
|
+
* `connected` edge reaches all three at once; like the 1.3 engine latch it
|
|
122
|
+
* never resets on close or renegotiation.
|
|
123
|
+
*/
|
|
124
|
+
Object.defineProperty(this, "legacyReadinessReached", {
|
|
88
125
|
enumerable: true,
|
|
89
126
|
configurable: true,
|
|
90
127
|
writable: true,
|
|
91
128
|
value: false
|
|
92
129
|
});
|
|
130
|
+
/**
|
|
131
|
+
* Milestones the selected DTLS 1.3 engine reached, kept per milestone when
|
|
132
|
+
* that engine is retired (close / failure), so readiness and its waiters
|
|
133
|
+
* keep reporting exactly what was reached.
|
|
134
|
+
*/
|
|
135
|
+
Object.defineProperty(this, "retiredEngine13Readiness", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
configurable: true,
|
|
138
|
+
writable: true,
|
|
139
|
+
value: void 0
|
|
140
|
+
});
|
|
93
141
|
Object.defineProperty(this, "extensions", {
|
|
94
142
|
enumerable: true,
|
|
95
143
|
configurable: true,
|
|
96
144
|
writable: true,
|
|
97
145
|
value: []
|
|
98
146
|
});
|
|
147
|
+
/**
|
|
148
|
+
* Assembled handshake handler. `peer` is the source of the datagram that
|
|
149
|
+
* produced these messages (explicit UDP/inject addr) — async handlers must
|
|
150
|
+
* reply to this address rather than reading mutable transport.rinfo.
|
|
151
|
+
*/
|
|
99
152
|
Object.defineProperty(this, "onHandleHandshakes", {
|
|
100
153
|
enumerable: true,
|
|
101
154
|
configurable: true,
|
|
102
155
|
writable: true,
|
|
103
156
|
value: void 0
|
|
104
157
|
});
|
|
105
|
-
|
|
158
|
+
/** Partially received handshake messages (RFC 6347 §4.2.3). */
|
|
159
|
+
Object.defineProperty(this, "reassembler", {
|
|
106
160
|
enumerable: true,
|
|
107
161
|
configurable: true,
|
|
108
162
|
writable: true,
|
|
109
|
-
value:
|
|
163
|
+
value: new reassembler_1.HandshakeReassembler()
|
|
164
|
+
});
|
|
165
|
+
/** close_notify or a fatal alert was sent: no record is sent any more. */
|
|
166
|
+
Object.defineProperty(this, "alertSent", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true,
|
|
169
|
+
writable: true,
|
|
170
|
+
value: false
|
|
171
|
+
});
|
|
172
|
+
/** The alert that is being sent (shared with concurrent close calls). */
|
|
173
|
+
Object.defineProperty(this, "alertSending", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
configurable: true,
|
|
176
|
+
writable: true,
|
|
177
|
+
value: void 0
|
|
178
|
+
});
|
|
179
|
+
/**
|
|
180
|
+
* The connection ended (close_notify / fatal alert sent or received, or
|
|
181
|
+
* close()): received records are no longer processed.
|
|
182
|
+
*/
|
|
183
|
+
Object.defineProperty(this, "ended", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: false
|
|
188
|
+
});
|
|
189
|
+
/** A received close_notify is a half-close: later application sends are ignored. */
|
|
190
|
+
/** When set, DTLS 1.3 engine owns the transport and crypto state. */
|
|
191
|
+
Object.defineProperty(this, "engine13", {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
configurable: true,
|
|
194
|
+
writable: true,
|
|
195
|
+
value: void 0
|
|
196
|
+
});
|
|
197
|
+
/**
|
|
198
|
+
* Bridge subscriptions for the active / parked 1.3 candidate.
|
|
199
|
+
* Disposed on hard close, version commit to 1.2, or re-bridge so dead
|
|
200
|
+
* candidates cannot surface stale onConnect / onError / onClose.
|
|
201
|
+
*/
|
|
202
|
+
Object.defineProperty(this, "engine13Bridge", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
writable: true,
|
|
206
|
+
value: new common_1.EventDisposer()
|
|
207
|
+
});
|
|
208
|
+
/** Opaque carrier generation provider for the DTLS 1.3 RX queue. */
|
|
209
|
+
Object.defineProperty(this, "rxGenerationProvider", {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
configurable: true,
|
|
212
|
+
writable: true,
|
|
213
|
+
value: void 0
|
|
214
|
+
});
|
|
215
|
+
/** Ownership epoch for asynchronous DTLS 1.2 handshake handlers. */
|
|
216
|
+
Object.defineProperty(this, "legacy12HandshakeOwnership", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
configurable: true,
|
|
219
|
+
writable: true,
|
|
220
|
+
value: 0
|
|
221
|
+
});
|
|
222
|
+
/** Wakes readiness waiters when a dual-stack association selects 1.3. */
|
|
223
|
+
Object.defineProperty(this, "onEngine13Selected", {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
configurable: true,
|
|
226
|
+
writable: true,
|
|
227
|
+
value: new common_1.Event()
|
|
228
|
+
});
|
|
229
|
+
/** Negotiated / configured protocol versions (priority order). */
|
|
230
|
+
Object.defineProperty(this, "protocolVersions", {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
configurable: true,
|
|
233
|
+
writable: true,
|
|
234
|
+
value: void 0
|
|
110
235
|
});
|
|
111
236
|
Object.defineProperty(this, "udpOnMessage", {
|
|
112
237
|
enumerable: true,
|
|
113
238
|
configurable: true,
|
|
114
239
|
writable: true,
|
|
115
|
-
value: (data) => {
|
|
116
|
-
|
|
117
|
-
for (const packet of packets) {
|
|
118
|
-
try {
|
|
119
|
-
const messages = (0, receive_1.parsePlainText)(this.dtls, this.cipher)(packet);
|
|
120
|
-
for (const message of messages) {
|
|
121
|
-
switch (message.type) {
|
|
122
|
-
case const_2.ContentType.handshake:
|
|
123
|
-
{
|
|
124
|
-
const handshake = message.data;
|
|
125
|
-
const handshakes = this.handleFragmentHandshake([handshake]);
|
|
126
|
-
const assembled = Object.values(handshakes.reduce((acc, cur) => {
|
|
127
|
-
if (!acc[cur.msg_type])
|
|
128
|
-
acc[cur.msg_type] = [];
|
|
129
|
-
acc[cur.msg_type].push(cur);
|
|
130
|
-
return acc;
|
|
131
|
-
}, {}))
|
|
132
|
-
.map((v) => fragment_1.FragmentedHandshake.assemble(v))
|
|
133
|
-
.sort((a, b) => a.msg_type - b.msg_type);
|
|
134
|
-
this.onHandleHandshakes(assembled).catch((error) => {
|
|
135
|
-
err(this.dtls.sessionId, "onHandleHandshakes error", error);
|
|
136
|
-
this.onError.execute(error);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
140
|
-
case const_2.ContentType.applicationData:
|
|
141
|
-
{
|
|
142
|
-
this.onData.execute(message.data);
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
case const_2.ContentType.alert:
|
|
146
|
-
this.onClose.execute();
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
err(this.dtls.sessionId, "catch udpOnMessage error", error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
240
|
+
value: (data, addr, meta) => {
|
|
241
|
+
this.handleUdpDatagram(data, addr, meta);
|
|
155
242
|
}
|
|
156
243
|
});
|
|
157
244
|
Object.defineProperty(this, "waitForReady", {
|
|
@@ -160,48 +247,888 @@ class DtlsSocket {
|
|
|
160
247
|
writable: true,
|
|
161
248
|
value: (condition) => new Promise(async (r, f) => {
|
|
162
249
|
for (let i = 0; i < 10; i++) {
|
|
250
|
+
if (this.associationTornDown || this.associationAbort.signal.aborted) {
|
|
251
|
+
f(new Error("association closed during waitForReady"));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
163
254
|
if (condition()) {
|
|
164
255
|
r();
|
|
165
|
-
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
// AbortSignal: close/fatal cancels this sleep immediately.
|
|
260
|
+
await (0, promises_1.setTimeout)(100 * i, undefined, {
|
|
261
|
+
signal: this.associationAbort.signal,
|
|
262
|
+
});
|
|
166
263
|
}
|
|
167
|
-
|
|
168
|
-
|
|
264
|
+
catch {
|
|
265
|
+
f(new Error("association closed during waitForReady"));
|
|
266
|
+
return;
|
|
169
267
|
}
|
|
170
268
|
}
|
|
171
|
-
f("waitForReady timeout");
|
|
269
|
+
f(new Error("waitForReady timeout"));
|
|
172
270
|
})
|
|
173
271
|
});
|
|
272
|
+
/**
|
|
273
|
+
* True after association hard/graceful/fatal teardown so Public APIs stay
|
|
274
|
+
* disabled for pure 1.2, pure 1.3, and dual paths alike (even if transport
|
|
275
|
+
* close is still racing or engine13 has already been cleared).
|
|
276
|
+
* Dual client also flips dualPhase=closed; this flag is the base guard.
|
|
277
|
+
*/
|
|
278
|
+
Object.defineProperty(this, "associationTornDown", {
|
|
279
|
+
enumerable: true,
|
|
280
|
+
configurable: true,
|
|
281
|
+
writable: true,
|
|
282
|
+
value: false
|
|
283
|
+
});
|
|
284
|
+
/**
|
|
285
|
+
* Cancels pending {@link waitForReady} association sleeps on terminal teardown.
|
|
286
|
+
* Replaced only if a future multi-HS redesign needs a fresh controller mid-life.
|
|
287
|
+
*/
|
|
288
|
+
Object.defineProperty(this, "associationAbort", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
configurable: true,
|
|
291
|
+
writable: true,
|
|
292
|
+
value: new AbortController()
|
|
293
|
+
});
|
|
174
294
|
/**send application data */
|
|
175
295
|
Object.defineProperty(this, "send", {
|
|
176
296
|
enumerable: true,
|
|
177
297
|
configurable: true,
|
|
178
298
|
writable: true,
|
|
179
299
|
value: async (buf, addr) => {
|
|
300
|
+
// Once the connection ended (an alert sent or received, close_notify,
|
|
301
|
+
// close()), application data is dropped without rejecting.
|
|
302
|
+
if (this.alertSent || this.ended || this.associationTornDown) {
|
|
303
|
+
log(this.dtls.sessionId, "drop application data after the connection ended");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
this.assertReadyForApplicationApi("send");
|
|
307
|
+
if (this.engine13) {
|
|
308
|
+
await this.engine13.send(buf);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Pure 1.2 only after version commit / handshake; require pin so we never
|
|
312
|
+
// fall back to spoofed last-rinfo when the caller omits addr.
|
|
313
|
+
if (!addr && !this.transport.pinnedPeer) {
|
|
314
|
+
this.pinSendPeerFromTransportRinfo("set-if-empty");
|
|
315
|
+
}
|
|
180
316
|
const pkt = (0, builder_1.createPlaintext)(this.dtls)([{ type: const_2.ContentType.applicationData, fragment: buf }], ++this.dtls.recordSequenceNumber)[0];
|
|
181
|
-
|
|
317
|
+
// Prefer explicit addr, else TransportContext.pinnedPeer (association pin).
|
|
318
|
+
// Never rely solely on last UDP rinfo (spoof hijack).
|
|
319
|
+
await this.transport.sendApplication(this.cipher.encryptPacket(pkt).serialize(), addr);
|
|
182
320
|
}
|
|
183
321
|
});
|
|
184
322
|
this.options = options;
|
|
185
323
|
this.sessionType = sessionType;
|
|
324
|
+
this.protocolVersions = (0, version_1.normalizeProtocolVersions)(this.options.protocolVersions);
|
|
186
325
|
this.dtls = new dtls_1.DtlsContext(this.options, this.sessionType);
|
|
187
326
|
this.cipher = new cipher_1.CipherContext(this.sessionType, this.options.cert, this.options.key, this.options.signatureHash);
|
|
188
327
|
this.transport = new transport_1.TransportContext(this.options.transport);
|
|
189
328
|
this.setupExtensions();
|
|
190
329
|
this.transport.socket.onData = this.udpOnMessage;
|
|
191
330
|
}
|
|
331
|
+
/** True when this socket is operating on the DTLS 1.3 engine. */
|
|
332
|
+
get isDtls13() {
|
|
333
|
+
return !!this.engine13;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* @internal Cryptographic readiness; SDP authentication is deliberately absent.
|
|
337
|
+
*
|
|
338
|
+
* Lifecycle contract (DTLS 1.2 and 1.3 alike): each milestone latches to
|
|
339
|
+
* true once for the association and never returns to false, including on
|
|
340
|
+
* close, failure or renegotiation. Termination is reported through
|
|
341
|
+
* onClose / onError, not by readiness going back to false.
|
|
342
|
+
*/
|
|
343
|
+
get readiness() {
|
|
344
|
+
if (this.engine13)
|
|
345
|
+
return { ...this.engine13.readiness };
|
|
346
|
+
if (this.retiredEngine13Readiness) {
|
|
347
|
+
return { ...this.retiredEngine13Readiness };
|
|
348
|
+
}
|
|
349
|
+
const reached = this.legacyReadinessReached;
|
|
350
|
+
return {
|
|
351
|
+
writeReady: reached,
|
|
352
|
+
peerHandshakeAuthenticated: reached,
|
|
353
|
+
handshakeComplete: reached,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/** @internal Association-lifetime DTLS 1.3 retransmissions. */
|
|
357
|
+
get totalRetransmitCount() {
|
|
358
|
+
return this.engine13?.totalRetransmitCount ?? 0;
|
|
359
|
+
}
|
|
360
|
+
/** @internal Read-only snapshot of the active DTLS 1.3 early-data queue. */
|
|
361
|
+
get earlyDataStats() {
|
|
362
|
+
return (this.engine13?.earlyDataStats ?? {
|
|
363
|
+
bufferedPackets: 0,
|
|
364
|
+
bufferedBytes: 0,
|
|
365
|
+
droppedPackets: 0,
|
|
366
|
+
droppedBytes: 0,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/** @internal */
|
|
370
|
+
async waitForWriteReady() {
|
|
371
|
+
await this.waitForSelectedReadiness("writeReady", (engine) => engine.waitForWriteReady());
|
|
372
|
+
if (!this.engine13)
|
|
373
|
+
return;
|
|
374
|
+
const profile = this.engine13.srtpProfile;
|
|
375
|
+
if (profile !== undefined)
|
|
376
|
+
this.srtp.srtpProfile = profile;
|
|
377
|
+
}
|
|
378
|
+
/** @internal */
|
|
379
|
+
waitForPeerHandshakeAuthenticated() {
|
|
380
|
+
return this.waitForSelectedReadiness("peerHandshakeAuthenticated", (engine) => engine.waitForPeerHandshakeAuthenticated());
|
|
381
|
+
}
|
|
382
|
+
/** @internal */
|
|
383
|
+
waitForHandshakeComplete() {
|
|
384
|
+
return this.waitForSelectedReadiness("handshakeComplete", (engine) => engine.waitForHandshakeComplete());
|
|
385
|
+
}
|
|
386
|
+
/** @internal Drop DTLS 1.3 pre-authentication application records. */
|
|
387
|
+
clearEarlyDataBuffer() {
|
|
388
|
+
this.engine13?.clearEarlyAppData();
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* @internal Opaque carrier generation provider for the DTLS 1.3 RX queue
|
|
392
|
+
* (e.g. ICE generation, owned by the WebRTC layer). Queued datagrams whose
|
|
393
|
+
* accept-time `rxGeneration` differs at execution time are dropped, closing
|
|
394
|
+
* the ICE-restart RX race. Unset = no check.
|
|
395
|
+
*/
|
|
396
|
+
setExpectedRxGeneration(provider) {
|
|
397
|
+
this.rxGenerationProvider = provider;
|
|
398
|
+
if (this.engine13)
|
|
399
|
+
this.engine13.expectedRxGeneration = provider;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Check the carrier generation at every DTLS 1.2 receive boundary.
|
|
403
|
+
*
|
|
404
|
+
* DTLS 1.3 performs this check again when its record queue resumes. The
|
|
405
|
+
* legacy path has asynchronous Flight handlers instead, so the association
|
|
406
|
+
* must reject an old datagram both before parsing and after each await. An
|
|
407
|
+
* unset provider means this socket is being used by the standalone UDP API,
|
|
408
|
+
* where no carrier generation exists and the check is intentionally disabled.
|
|
409
|
+
*/
|
|
410
|
+
isCurrentRxGeneration(rxGeneration) {
|
|
411
|
+
const expected = this.rxGenerationProvider?.();
|
|
412
|
+
if (expected === undefined)
|
|
413
|
+
return true;
|
|
414
|
+
return rxGeneration !== undefined && rxGeneration === expected;
|
|
415
|
+
}
|
|
416
|
+
waitForLegacyReadiness() {
|
|
417
|
+
// Same as the 1.3 latch: a reached milestone stays reached.
|
|
418
|
+
if (this.legacyReadinessReached)
|
|
419
|
+
return Promise.resolve();
|
|
420
|
+
if (this.associationTornDown) {
|
|
421
|
+
return Promise.reject(new Error("DTLS association closed before readiness"));
|
|
422
|
+
}
|
|
423
|
+
return new Promise((resolve, reject) => {
|
|
424
|
+
const connected = this.onConnect.subscribe(() => {
|
|
425
|
+
cleanup();
|
|
426
|
+
resolve();
|
|
427
|
+
});
|
|
428
|
+
const failed = this.onError.subscribe((error) => {
|
|
429
|
+
cleanup();
|
|
430
|
+
reject(error);
|
|
431
|
+
});
|
|
432
|
+
const closed = this.onClose.subscribe(() => {
|
|
433
|
+
cleanup();
|
|
434
|
+
reject(new Error("DTLS association closed before readiness"));
|
|
435
|
+
});
|
|
436
|
+
const cleanup = () => {
|
|
437
|
+
connected.unSubscribe();
|
|
438
|
+
failed.unSubscribe();
|
|
439
|
+
closed.unSubscribe();
|
|
440
|
+
};
|
|
441
|
+
if (this.connected) {
|
|
442
|
+
cleanup();
|
|
443
|
+
resolve();
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Wait for the readiness milestone owned by the selected protocol engine.
|
|
449
|
+
* A dual-stack server has no 1.3 engine until ClientHello is classified, so
|
|
450
|
+
* choosing the legacy latch at call time would accidentally turn 0.5-RTT
|
|
451
|
+
* readiness into a full-handshake wait.
|
|
452
|
+
*/
|
|
453
|
+
waitForSelectedReadiness(milestone, wait13) {
|
|
454
|
+
// Readiness is a latch (see `readiness`): a milestone already reached
|
|
455
|
+
// stays reached after close, for dual-stack / 1.3 configs exactly as for
|
|
456
|
+
// 1.2-only. Check it before the terminal state.
|
|
457
|
+
if (this.readiness[milestone])
|
|
458
|
+
return Promise.resolve();
|
|
459
|
+
if (!this.protocolVersions.includes(version_1.DtlsVersion.V1_3)) {
|
|
460
|
+
return this.waitForLegacyReadiness();
|
|
461
|
+
}
|
|
462
|
+
if (this.associationTornDown) {
|
|
463
|
+
return Promise.reject(new Error("DTLS association closed before readiness"));
|
|
464
|
+
}
|
|
465
|
+
return new Promise((resolve, reject) => {
|
|
466
|
+
const disposer = new common_1.EventDisposer();
|
|
467
|
+
let settled = false;
|
|
468
|
+
let attachedEngine;
|
|
469
|
+
let waitGeneration = 0;
|
|
470
|
+
const cleanup = () => {
|
|
471
|
+
disposer.dispose();
|
|
472
|
+
attachedEngine = undefined;
|
|
473
|
+
waitGeneration++;
|
|
474
|
+
};
|
|
475
|
+
const resolveReady = () => {
|
|
476
|
+
if (settled)
|
|
477
|
+
return;
|
|
478
|
+
settled = true;
|
|
479
|
+
cleanup();
|
|
480
|
+
resolve();
|
|
481
|
+
};
|
|
482
|
+
const rejectReady = (error) => {
|
|
483
|
+
if (settled)
|
|
484
|
+
return;
|
|
485
|
+
settled = true;
|
|
486
|
+
cleanup();
|
|
487
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
488
|
+
};
|
|
489
|
+
const attachCurrentEngine = () => {
|
|
490
|
+
const engine = this.engine13;
|
|
491
|
+
if (settled || !engine || attachedEngine === engine)
|
|
492
|
+
return;
|
|
493
|
+
attachedEngine = engine;
|
|
494
|
+
const generation = ++waitGeneration;
|
|
495
|
+
void wait13(engine).then(() => {
|
|
496
|
+
// A candidate that was parked/released for DTLS 1.2 is not the
|
|
497
|
+
// association's selected readiness source. Wait for the legacy
|
|
498
|
+
// onConnect edge instead of resolving from a stale candidate.
|
|
499
|
+
if (settled ||
|
|
500
|
+
generation !== waitGeneration ||
|
|
501
|
+
this.engine13 !== engine) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
resolveReady();
|
|
505
|
+
}, (error) => {
|
|
506
|
+
if (settled || generation !== waitGeneration)
|
|
507
|
+
return;
|
|
508
|
+
attachedEngine = undefined;
|
|
509
|
+
if (this.isSoftVersionSelectionError(error)) {
|
|
510
|
+
// DtlsVersionSelected is an internal dual-stack transition, not
|
|
511
|
+
// a readiness failure. The association now owns the waiter and
|
|
512
|
+
// will resolve it from the committed 1.2 onConnect (or attach a
|
|
513
|
+
// newly selected 1.3 engine).
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
rejectReady(error);
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
const observeCurrentAssociation = () => {
|
|
520
|
+
if (settled)
|
|
521
|
+
return;
|
|
522
|
+
if (this.engine13) {
|
|
523
|
+
attachCurrentEngine();
|
|
524
|
+
}
|
|
525
|
+
else if (this.connected) {
|
|
526
|
+
resolveReady();
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
this.onEngine13Selected
|
|
530
|
+
.subscribe(observeCurrentAssociation)
|
|
531
|
+
.disposer(disposer);
|
|
532
|
+
this.onConnect
|
|
533
|
+
.subscribe(() => {
|
|
534
|
+
// DTLS 1.3 onConnect is not handshakeComplete for the three
|
|
535
|
+
// readiness milestones; the engine waiter remains authoritative.
|
|
536
|
+
if (!this.engine13)
|
|
537
|
+
resolveReady();
|
|
538
|
+
})
|
|
539
|
+
.disposer(disposer);
|
|
540
|
+
this.onError
|
|
541
|
+
.subscribe((error) => {
|
|
542
|
+
// The dual client normally filters this transition before it reaches
|
|
543
|
+
// the public socket event. Keep the association waiter tolerant if a
|
|
544
|
+
// subclass exposes it during the handoff.
|
|
545
|
+
if (this.isSoftVersionSelectionError(error)) {
|
|
546
|
+
observeCurrentAssociation();
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
rejectReady(error);
|
|
550
|
+
})
|
|
551
|
+
.disposer(disposer);
|
|
552
|
+
this.onClose
|
|
553
|
+
.subscribe(() => {
|
|
554
|
+
rejectReady(new Error("DTLS association closed before readiness"));
|
|
555
|
+
})
|
|
556
|
+
.disposer(disposer);
|
|
557
|
+
// Close the subscribe-before-state-check race, including a 1.3 engine
|
|
558
|
+
// constructed before this waiter was registered.
|
|
559
|
+
observeCurrentAssociation();
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
/** A dual 1.3 probe uses this rejection to transition to the 1.2 owner. */
|
|
563
|
+
isSoftVersionSelectionError(error) {
|
|
564
|
+
if (!this.protocolVersions.includes(version_1.DtlsVersion.V1_2))
|
|
565
|
+
return false;
|
|
566
|
+
const candidate = error;
|
|
567
|
+
return ((error instanceof version_1.DtlsVersionSelected ||
|
|
568
|
+
candidate.name === "DtlsVersionSelected" ||
|
|
569
|
+
candidate.code === "version_selected") &&
|
|
570
|
+
candidate.version === version_1.DtlsVersion.V1_2);
|
|
571
|
+
}
|
|
192
572
|
renegotiation() {
|
|
573
|
+
// Terminal association must not re-init flight/cipher state (invariant:
|
|
574
|
+
// reconnect / renegotiation on a closed association is prohibited).
|
|
575
|
+
if (this.associationTornDown) {
|
|
576
|
+
const error = new Error("DTLS association is closed; cannot renegotiation");
|
|
577
|
+
this.notify(this.onError, error);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (this.engine13) {
|
|
581
|
+
// DTLS 1.3 renegotiation is not defined; reject.
|
|
582
|
+
const error = new Error("renegotiation is not supported after DTLS 1.3 handshake");
|
|
583
|
+
this.notify(this.onError, error);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
193
586
|
log("renegotiation", this.sessionType);
|
|
587
|
+
this.invalidateLegacy12HandshakeOwnership();
|
|
194
588
|
this.connected = false;
|
|
589
|
+
// Cancel retransmit timers on the *old* context before abandoning it.
|
|
590
|
+
// Otherwise Flight.transmit sleeps keep firing against a detached DtlsContext
|
|
591
|
+
// and can still TX after renegotiation replaces cipher/dtls.
|
|
592
|
+
this.abortLegacy12Flight();
|
|
593
|
+
this.abortAssociationWaits();
|
|
594
|
+
// Fresh AbortController for the new handshake waits (previous signal aborted).
|
|
595
|
+
this.associationAbort = new AbortController();
|
|
195
596
|
this.cipher = new cipher_1.CipherContext(this.sessionType, this.options.cert, this.options.key, this.options.signatureHash);
|
|
196
597
|
this.dtls = new dtls_1.DtlsContext(this.options, this.sessionType);
|
|
197
598
|
this.srtp = new srtp_1.SrtpContext();
|
|
198
599
|
this.extensions = [];
|
|
199
|
-
this.
|
|
600
|
+
this.reassembler.clear();
|
|
601
|
+
this.setupExtensions();
|
|
602
|
+
}
|
|
603
|
+
/** Normalize host so 0.0.0.0 / :: match loopback pin keys used by Flight. */
|
|
604
|
+
normalizePeerHost(host) {
|
|
605
|
+
return (0, peer_1.normalizeLoopbackHost)(host);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Resolve inbound peer for RX ownership: explicit UDP/inject addr first,
|
|
609
|
+
* else last transport rinfo (may be spoofed — always gate with pin).
|
|
610
|
+
*/
|
|
611
|
+
resolveInboundPeer(addr) {
|
|
612
|
+
if (addr != null && addr[0] != null && addr[1] != null) {
|
|
613
|
+
return [addr[0], addr[1]];
|
|
614
|
+
}
|
|
615
|
+
// Some Transport implementations expose Node's AddressInfo object instead
|
|
616
|
+
// of the tuple shape; normalize it before cookie pinning and RX checks.
|
|
617
|
+
const addressInfo = addr;
|
|
618
|
+
if (addressInfo?.address != null && addressInfo.port != null) {
|
|
619
|
+
return [addressInfo.address, addressInfo.port];
|
|
620
|
+
}
|
|
621
|
+
const r = this.options.transport.rinfo;
|
|
622
|
+
if (r?.address != null && r?.port != null) {
|
|
623
|
+
return [r.address, r.port];
|
|
624
|
+
}
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* True when inbound source matches association TX/RX pin, or no pin yet
|
|
629
|
+
* (pre-cookie server / pre-connect). After pin, unknown or non-pin peer
|
|
630
|
+
* must not drive handshake / app / alert lifecycle (RX ownership).
|
|
631
|
+
*
|
|
632
|
+
* Peer-authentication vs address pin are separate:
|
|
633
|
+
* - UDP 5-tuple pin: require matching source address when present
|
|
634
|
+
* - authenticated-single-peer transport (ICE / peerAuthenticated): the
|
|
635
|
+
* transport path is the identity; addressless RX is accepted even if a
|
|
636
|
+
* pin was set for TX convenience (WebRTC does not pass rinfo into DTLS)
|
|
637
|
+
*/
|
|
638
|
+
matchesPinnedPeer(addr) {
|
|
639
|
+
// Transport identity is the peer: 5-tuple is not an auth boundary.
|
|
640
|
+
// Accept addressless and alternate addresses (ICE may not expose stable rinfo).
|
|
641
|
+
if (this.isAuthenticatedSinglePeerTransport())
|
|
642
|
+
return true;
|
|
643
|
+
// No association pin: every source is processed.
|
|
644
|
+
if (this.peerIdentityMode === "unpinned")
|
|
645
|
+
return true;
|
|
646
|
+
const pin = this.transport.pinnedPeer;
|
|
647
|
+
if (!pin)
|
|
648
|
+
return true;
|
|
649
|
+
if (!addr) {
|
|
650
|
+
// datagram-address after pin: addressless RX is a drop.
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
const a = [this.normalizePeerHost(addr[0]), addr[1]];
|
|
654
|
+
const p = [this.normalizePeerHost(pin[0]), pin[1]];
|
|
655
|
+
return (0, cookie_1.peerKeyFromAddr)(a) === (0, cookie_1.peerKeyFromAddr)(p);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Resolved peer-identity policy for this association.
|
|
659
|
+
* Prefer explicit {@link Options.peerIdentityMode}; otherwise infer from
|
|
660
|
+
* transport.peerAuthenticated / addressValidation for backward compatibility.
|
|
661
|
+
*/
|
|
662
|
+
get peerIdentityMode() {
|
|
663
|
+
return (0, peer_1.resolvePeerIdentityMode)({
|
|
664
|
+
peerIdentityMode: this.options.peerIdentityMode,
|
|
665
|
+
addressValidation: this.options.addressValidation,
|
|
666
|
+
transport: this.options.transport,
|
|
667
|
+
offersDtls13: this.protocolVersions.includes(version_1.DtlsVersion.V1_3),
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Transport path already authenticates a single peer (ICE / equivalent).
|
|
672
|
+
* Distinct from TransportContext.pinnedPeer (UDP return-routability).
|
|
673
|
+
* Driven by {@link peerIdentityMode} (public Options) when set.
|
|
674
|
+
*/
|
|
675
|
+
isAuthenticatedSinglePeerTransport() {
|
|
676
|
+
return this.peerIdentityMode === "authenticated-single-peer";
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* After keys exist (connected or write epoch advanced), only epoch>0 records
|
|
680
|
+
* are cryptographically authenticated for lifecycle alerts. Epoch-0 fatal /
|
|
681
|
+
* close_notify must not tear down a post-handshake association (unauth DoS).
|
|
682
|
+
*/
|
|
683
|
+
isAuthenticatedLegacy12Record(epoch, contentType) {
|
|
684
|
+
if (epoch > 0)
|
|
685
|
+
return true;
|
|
686
|
+
// Before keys exist every record is epoch 0.
|
|
687
|
+
if (!this.connected && this.dtls.epoch === 0)
|
|
688
|
+
return true;
|
|
689
|
+
// The peer may still send a plaintext (epoch-0) alert after this side
|
|
690
|
+
// advanced its write epoch, e.g. the server's bad_certificate answering
|
|
691
|
+
// the client's Flight5 before its own ChangeCipherSpec. Only alerts are
|
|
692
|
+
// accepted there, and only until the handshake completed.
|
|
693
|
+
return contentType === "alert" && !this.connected;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Peer-auth boundary for DTLS 1.2 association lifecycle (alerts / HS errors).
|
|
697
|
+
*
|
|
698
|
+
* - UDP pin after cookie / connect (classic return-routability / datagram-address)
|
|
699
|
+
* - authenticated-single-peer transport (ICE peerAuthenticated / ice-authenticated):
|
|
700
|
+
* AEAD-protected records must not be treated as "pre-auth" merely because
|
|
701
|
+
* the transport does not expose a 5-tuple (WebRTC IceTransport).
|
|
702
|
+
*
|
|
703
|
+
* These modes are not interchangeable for TX routing (pin still owns UDP TX),
|
|
704
|
+
* but either is sufficient for association-lifecycle alert decisions.
|
|
705
|
+
*/
|
|
706
|
+
hasAssociationPeerAuth() {
|
|
707
|
+
// Without ICE identity or the unpinned mode, an association (client or
|
|
708
|
+
// server) stays silent until its return-routability pin is established.
|
|
709
|
+
return (0, peer_1.associationHasPeerAuth)({
|
|
710
|
+
hasPinnedPeer: !!this.transport.pinnedPeer,
|
|
711
|
+
identityMode: this.peerIdentityMode,
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Check ownership before an asynchronous legacy handshake rejection is
|
|
716
|
+
* allowed to change association state.
|
|
717
|
+
*
|
|
718
|
+
* The receive path validates these conditions before starting the async
|
|
719
|
+
* handler, but a later rejection resumes outside that synchronous boundary.
|
|
720
|
+
* A DTLS 1.2 handler from an old ICE generation, a released dual candidate,
|
|
721
|
+
* or a changed peer pin must be discarded instead of failing the current
|
|
722
|
+
* association.
|
|
723
|
+
*/
|
|
724
|
+
ownsLegacy12Handshake(ownership, rxGeneration, peer) {
|
|
725
|
+
return (ownership === this.legacy12HandshakeOwnership &&
|
|
726
|
+
!this.associationTornDown &&
|
|
727
|
+
!this.engine13 &&
|
|
728
|
+
this.isCurrentRxGeneration(rxGeneration) &&
|
|
729
|
+
this.matchesPinnedPeer(peer));
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Invalidate legacy handshake callbacks that no longer own the association.
|
|
733
|
+
* Used by dual-version selection and renegotiation before replacing the
|
|
734
|
+
* lower-level state while keeping the public socket alive.
|
|
735
|
+
*/
|
|
736
|
+
invalidateLegacy12HandshakeOwnership() {
|
|
737
|
+
this.legacy12HandshakeOwnership++;
|
|
738
|
+
}
|
|
739
|
+
/** Restore transport.rinfo to pin so spoof sources do not stick for later TX fallbacks. */
|
|
740
|
+
restorePinnedRinfo() {
|
|
741
|
+
const pin = this.transport.pinnedPeer;
|
|
742
|
+
if (!pin)
|
|
743
|
+
return;
|
|
744
|
+
const t = this.options.transport;
|
|
745
|
+
t.rinfo = { address: pin[0], port: pin[1] };
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Process one UDP datagram on the DTLS 1.2 record path.
|
|
749
|
+
* Subclasses (dual client) may intercept before calling this.
|
|
750
|
+
*
|
|
751
|
+
* RX ownership (when pin set): drop non-pin peers before parse/decrypt so
|
|
752
|
+
* spoofed UDP / carrier inject cannot deliver app data or force terminal
|
|
753
|
+
* via unauthenticated alerts.
|
|
754
|
+
*/
|
|
755
|
+
handleUdpDatagram(data, addr, meta) {
|
|
756
|
+
// Terminal association: drop all RX (no onData / handshake resume after fatal).
|
|
757
|
+
if (this.associationTornDown || this.ended)
|
|
758
|
+
return;
|
|
759
|
+
// ICE restart can occur after the datagram has been accepted by the
|
|
760
|
+
// transport but before this handler starts. Reject that stale generation
|
|
761
|
+
// before parse/decrypt so it cannot advance a DTLS 1.2 association.
|
|
762
|
+
if (!this.isCurrentRxGeneration(meta?.rxGeneration))
|
|
763
|
+
return;
|
|
764
|
+
const peer = this.resolveInboundPeer(addr);
|
|
765
|
+
// Association peer pin owns RX as well as TX once set (cookie / connect).
|
|
766
|
+
if (!this.matchesPinnedPeer(peer)) {
|
|
767
|
+
log(this.dtls.sessionId, "DTLS 1.2: drop RX from non-association peer", (0, cookie_1.peerKeyFromAddr)(peer
|
|
768
|
+
? [this.normalizePeerHost(peer[0]), peer[1]]
|
|
769
|
+
: undefined), (0, cookie_1.peerKeyFromAddr)(this.transport.pinnedPeer
|
|
770
|
+
? [this.transport.pinnedPeer[0], this.transport.pinnedPeer[1]]
|
|
771
|
+
: undefined));
|
|
772
|
+
this.restorePinnedRinfo();
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const packets = (0, receive_1.parsePacket)(data);
|
|
776
|
+
for (const packet of packets) {
|
|
777
|
+
// An alert earlier in this datagram may have ended the connection.
|
|
778
|
+
if (this.ended)
|
|
779
|
+
return;
|
|
780
|
+
try {
|
|
781
|
+
// Re-check: async fatal during multi-record datagram must stop mid-loop.
|
|
782
|
+
if (this.associationTornDown)
|
|
783
|
+
return;
|
|
784
|
+
// A synchronous callback for an earlier record may restart ICE. The
|
|
785
|
+
// remainder of this datagram belongs to the old generation too.
|
|
786
|
+
if (!this.isCurrentRxGeneration(meta?.rxGeneration))
|
|
787
|
+
return;
|
|
788
|
+
const recordEpoch = packet.recordLayerHeader.epoch;
|
|
789
|
+
const messages = (0, receive_1.parsePlainText)(this.dtls, this.cipher)(packet);
|
|
790
|
+
for (const message of messages) {
|
|
791
|
+
if (this.associationTornDown)
|
|
792
|
+
return;
|
|
793
|
+
if (this.ended || !this.isCurrentRxGeneration(meta?.rxGeneration))
|
|
794
|
+
return;
|
|
795
|
+
switch (message.type) {
|
|
796
|
+
case const_2.ContentType.handshake:
|
|
797
|
+
{
|
|
798
|
+
// Post-handshake epoch-0 HS is unauthenticated plaintext — same
|
|
799
|
+
// invariant as DTLS 1.3 (drop without lifecycle change). Must not
|
|
800
|
+
// call renegotiation() / reset cipher on garbage or spoofed CH.
|
|
801
|
+
if (!this.isAuthenticatedLegacy12Record(recordEpoch, "handshake") ||
|
|
802
|
+
(this.connected && recordEpoch < this.dtls.remoteEpoch)) {
|
|
803
|
+
log(this.dtls.sessionId, "DTLS 1.2: drop unauthenticated handshake record", recordEpoch, this.connected);
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
const handshake = message.data;
|
|
807
|
+
const assembled = this.handleFragmentHandshake([handshake], packet.recordLayerHeader.epoch).sort((a, b) => a.msg_type - b.msg_type);
|
|
808
|
+
// Pass the datagram source so async Flight2 / protocol alerts
|
|
809
|
+
// do not depend on mutable UdpTransport.rinfo after await.
|
|
810
|
+
const ownership = this.legacy12HandshakeOwnership;
|
|
811
|
+
this.onHandleHandshakes(assembled, peer, meta).catch((error) => {
|
|
812
|
+
err(this.dtls.sessionId, "onHandleHandshakes error", error);
|
|
813
|
+
const e = error instanceof Error ? error : new Error(String(error));
|
|
814
|
+
// Reject resumes after the async handshake boundary. The
|
|
815
|
+
// datagram may belong to an old ICE generation or to a
|
|
816
|
+
// released dual-stack candidate; neither may tear down a
|
|
817
|
+
// current association.
|
|
818
|
+
if (!this.ownsLegacy12Handshake(ownership, meta?.rxGeneration, peer)) {
|
|
819
|
+
log(this.dtls.sessionId, "DTLS 1.2: drop stale async handshake error", e.message);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
// Pre-cookie / unpinned: drop per-source only — never tear down
|
|
823
|
+
// the listening association (unauthenticated DoS).
|
|
824
|
+
if (!this.hasAssociationPeerAuth()) {
|
|
825
|
+
log(this.dtls.sessionId, "DTLS 1.2: drop pre-auth handshake error (no association fatal)", e.message);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
// Post-pin: handshake failure is association-fatal.
|
|
829
|
+
this.reportLegacy12Fatal(e);
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
break;
|
|
833
|
+
case const_2.ContentType.applicationData:
|
|
834
|
+
{
|
|
835
|
+
// Never deliver app data after association terminal teardown.
|
|
836
|
+
if (this.associationTornDown || this.ended)
|
|
837
|
+
return;
|
|
838
|
+
// App data is always epoch>0 AEAD; unauthenticated epoch-0 must not deliver.
|
|
839
|
+
if (!this.isAuthenticatedLegacy12Record(recordEpoch, "applicationData")) {
|
|
840
|
+
log(this.dtls.sessionId, "DTLS 1.2: drop unauthenticated application_data", recordEpoch);
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
this.notify(this.onData, message.data);
|
|
844
|
+
// onData is synchronous and may trigger ICE restart. Do not
|
|
845
|
+
// continue processing another record from the old datagram.
|
|
846
|
+
if (!this.isCurrentRxGeneration(meta?.rxGeneration))
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
break;
|
|
850
|
+
case const_2.ContentType.alert:
|
|
851
|
+
{
|
|
852
|
+
const alert = message.data;
|
|
853
|
+
if (!alert)
|
|
854
|
+
break;
|
|
855
|
+
// Pre-cookie (no pin): any alert is unauthenticated — drop only.
|
|
856
|
+
if (!this.hasAssociationPeerAuth() &&
|
|
857
|
+
!(this.connected && recordEpoch > 0)) {
|
|
858
|
+
log(this.dtls.sessionId, "DTLS 1.2: ignore pre-auth alert (no association fatal)", (0, const_2.alertDescName)(alert.description) ?? alert.description);
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
// Unauthenticated (epoch-0 after keys) alerts must not change
|
|
862
|
+
// association lifecycle — only AEAD-protected records may.
|
|
863
|
+
if (!this.isAuthenticatedLegacy12Record(recordEpoch, "alert")) {
|
|
864
|
+
log(this.dtls.sessionId, "DTLS 1.2: ignore unauthenticated alert (no terminal)", (0, const_2.alertDescName)(alert.description) ?? alert.description, "epoch", recordEpoch);
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
// Alert records can contain multiple alerts; each remains in
|
|
868
|
+
// the authenticated peer / epoch boundary above.
|
|
869
|
+
this.handleAlert(alert);
|
|
870
|
+
}
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
// An invalid record (e.g. failed to decrypt) is discarded
|
|
877
|
+
// (RFC 6347 §4.1.2.1).
|
|
878
|
+
err(this.dtls.sessionId, "catch udpOnMessage error", error);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
/** Resolves once an in-flight alert has been handed to the transport. */
|
|
883
|
+
alertFlushed() {
|
|
884
|
+
return this.alertSending ?? Promise.resolve();
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* A local close() ended the connection: received records are no longer
|
|
888
|
+
* processed and no handshake flight is (re)sent.
|
|
889
|
+
*/
|
|
890
|
+
markEndedByLocalClose() {
|
|
891
|
+
this.ended = true;
|
|
892
|
+
this.transport.stopFlights();
|
|
893
|
+
}
|
|
894
|
+
/** Whether the connection ended (alert, or close()). */
|
|
895
|
+
get terminated() {
|
|
896
|
+
return this.ended;
|
|
897
|
+
}
|
|
898
|
+
/** Whether this handshake must stop after a terminal alert or close. */
|
|
899
|
+
get handshakeStopped() {
|
|
900
|
+
return this.ended || this.alertSent;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Run the listeners of an event this socket reports, each isolated
|
|
904
|
+
* (`Event.executeIsolated`): a listener's exception is logged, so an
|
|
905
|
+
* application listener can never interrupt the socket's own processing
|
|
906
|
+
* (ending the connection, closing the transport, the receive loop) nor
|
|
907
|
+
* skip a listener registered after it.
|
|
908
|
+
*/
|
|
909
|
+
notify(event, ...args) {
|
|
910
|
+
// Per listener: one that throws neither skips the later listeners (e.g.
|
|
911
|
+
// werift's own, if the application subscribed first) nor this socket.
|
|
912
|
+
event.executeIsolated((error) => err(this.dtls.sessionId, "event listener failed", error), ...args);
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* RFC 5246 §7.2: react to an alert received from the peer. The connection
|
|
916
|
+
* is ended (flights stopped, close_notify answered or the transport
|
|
917
|
+
* closed) before any listener runs, and each notification is isolated, so
|
|
918
|
+
* a throwing listener does not leave the socket ended but unreported.
|
|
919
|
+
*/
|
|
920
|
+
handleAlert(alert) {
|
|
921
|
+
if (this.ended || this.associationTornDown)
|
|
922
|
+
return;
|
|
923
|
+
if (alert.description === const_2.AlertDesc.ProtocolVersion) {
|
|
924
|
+
// protocol_version at any level: the peer rejected the version, so the
|
|
925
|
+
// association fails with ProtocolVersionError (not a silent timeout).
|
|
926
|
+
err(this.dtls.sessionId, "received protocol_version alert", alert);
|
|
927
|
+
this.alertSent = true;
|
|
928
|
+
this.transport.stopFlights();
|
|
929
|
+
this.failFromRemoteAlert(alert, new version_1.ProtocolVersionError("peer rejected protocol version (alert protocol_version)"));
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const action = (0, alert_1.classifyAlert)(alert);
|
|
933
|
+
if (action === "ignore") {
|
|
934
|
+
log(this.dtls.sessionId, "ignore warning alert", alert);
|
|
935
|
+
this.notify(this.onAlert, alert);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
this.ended = true;
|
|
939
|
+
// Spec: tests/server.test.ts › "frees partial handshake fragments when
|
|
940
|
+
// the connection ends by receiving a fatal alert / close_notify"
|
|
941
|
+
this.reassembler.clear();
|
|
942
|
+
// Retransmitting a handshake flight makes no sense any more.
|
|
943
|
+
this.transport.stopFlights();
|
|
944
|
+
if (action === "close") {
|
|
945
|
+
log(this.dtls.sessionId, "received close_notify");
|
|
946
|
+
this.abortLegacy12Flight();
|
|
947
|
+
this.connected = false;
|
|
948
|
+
this.associationTornDown = true;
|
|
949
|
+
this.abortAssociationWaits();
|
|
950
|
+
this.notify(this.onAlert, alert);
|
|
951
|
+
// RFC 5246 §7.2.1: respond with close_notify; nothing is sent after it.
|
|
952
|
+
void this.sendAlert(const_2.AlertLevel.warning, const_2.AlertDesc.CloseNotify);
|
|
953
|
+
// The connection is over: the socket closes its transport once the
|
|
954
|
+
// reply has been sent or timed out, like after a fatal alert (the
|
|
955
|
+
// application does not need to call close()).
|
|
956
|
+
void this.alertFlushed().then(() => this.finishPeerCloseNotify());
|
|
957
|
+
}
|
|
958
|
+
else {
|
|
959
|
+
err(this.dtls.sessionId, "received fatal alert", alert);
|
|
960
|
+
// A fatal alert is not answered (RFC 5246 §7.2.2).
|
|
961
|
+
this.alertSent = true;
|
|
962
|
+
this.failFromRemoteAlert(alert, new alert_1.DtlsAlertError(alert, "remote"));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Fatal teardown for a received alert: the association is torn down before
|
|
967
|
+
* the listeners run, then onAlert and onError fire once each. A fatal alert
|
|
968
|
+
* is not a close, so onClose does not fire.
|
|
969
|
+
*/
|
|
970
|
+
failFromRemoteAlert(alert, error) {
|
|
971
|
+
if (!this.failLegacy12Association(error))
|
|
972
|
+
return;
|
|
973
|
+
this.notify(this.onAlert, alert);
|
|
974
|
+
this.notify(this.onError, error);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* After the reply to the peer's close_notify was sent (or timed out):
|
|
978
|
+
* fire onClose once and close the transport. The dual client overrides it
|
|
979
|
+
* to also hard-close its 1.3 candidates and carrier.
|
|
980
|
+
*/
|
|
981
|
+
finishPeerCloseNotify() {
|
|
982
|
+
this.clearSendPeerPin();
|
|
983
|
+
this.notify(this.onClose);
|
|
984
|
+
return this.closeTransport();
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Send an alert to the peer, protected with the current epoch (plaintext
|
|
988
|
+
* before ChangeCipherSpec, encrypted after it).
|
|
989
|
+
*
|
|
990
|
+
* Resolves once the transport has sent the record, or after `timeoutMs`
|
|
991
|
+
* (default {@link DtlsSocket.AlertSendTimeoutMs}). It never rejects: a
|
|
992
|
+
* failed send is only logged. Nothing is sent once close_notify or a fatal
|
|
993
|
+
* alert has been sent or the transport is closed. Sending close_notify or a
|
|
994
|
+
* fatal alert also stops the handshake flights (no retransmission). The
|
|
995
|
+
* record is handed to the transport synchronously, so closing the socket
|
|
996
|
+
* right after calling this does not drop it.
|
|
997
|
+
*
|
|
998
|
+
* A fatal alert ends the connection like a fatal error this side detected
|
|
999
|
+
* itself: `onError` fires synchronously with a local {@link DtlsAlertError},
|
|
1000
|
+
* and the transport is closed once the alert has been sent (the returned
|
|
1001
|
+
* promise resolves after that).
|
|
1002
|
+
*/
|
|
1003
|
+
sendAlert(level, description, options = {}) {
|
|
1004
|
+
if (level === const_2.AlertLevel.fatal) {
|
|
1005
|
+
return this.endWithFatalAlert(description, undefined, options);
|
|
1006
|
+
}
|
|
1007
|
+
return this.transmitAlert(level, description, options);
|
|
1008
|
+
}
|
|
1009
|
+
/** Encode, protect and send one alert record (see {@link sendAlert}). */
|
|
1010
|
+
transmitAlert(level, description, options) {
|
|
1011
|
+
if (this.alertSent || this.transport.closed) {
|
|
1012
|
+
// A concurrent caller waits for the alert that is still being sent.
|
|
1013
|
+
return this.alertSending ?? Promise.resolve();
|
|
1014
|
+
}
|
|
1015
|
+
if (level === const_2.AlertLevel.fatal || description === const_2.AlertDesc.CloseNotify) {
|
|
1016
|
+
this.alertSent = true;
|
|
1017
|
+
// A terminating alert ends the handshake too: no handshake flight is
|
|
1018
|
+
// sent or retransmitted after it.
|
|
1019
|
+
this.transport.stopFlights();
|
|
1020
|
+
}
|
|
1021
|
+
if (level === const_2.AlertLevel.fatal) {
|
|
1022
|
+
this.ended = true;
|
|
1023
|
+
}
|
|
1024
|
+
let sending;
|
|
1025
|
+
try {
|
|
1026
|
+
const record = (0, alert_1.createAlertRecord)(this.dtls, this.cipher, {
|
|
1027
|
+
level,
|
|
1028
|
+
description,
|
|
1029
|
+
});
|
|
1030
|
+
log(this.dtls.sessionId, "send alert", {
|
|
1031
|
+
level,
|
|
1032
|
+
description,
|
|
1033
|
+
epoch: this.dtls.epoch,
|
|
1034
|
+
sequenceNumber: this.dtls.recordSequenceNumber,
|
|
1035
|
+
});
|
|
1036
|
+
sending = this.transport.send(record);
|
|
1037
|
+
}
|
|
1038
|
+
catch (error) {
|
|
1039
|
+
err(this.dtls.sessionId, "failed to send alert", error);
|
|
1040
|
+
return Promise.resolve();
|
|
1041
|
+
}
|
|
1042
|
+
const timeoutMs = options.timeoutMs ?? DtlsSocket.AlertSendTimeoutMs;
|
|
1043
|
+
const timer = new AbortController();
|
|
1044
|
+
const done = Promise.race([
|
|
1045
|
+
sending,
|
|
1046
|
+
(0, promises_1.setTimeout)(timeoutMs, undefined, { signal: timer.signal }).then(() => {
|
|
1047
|
+
log(this.dtls.sessionId, "alert send timeout", timeoutMs);
|
|
1048
|
+
}),
|
|
1049
|
+
])
|
|
1050
|
+
.catch((error) => {
|
|
1051
|
+
if (timer.signal.aborted)
|
|
1052
|
+
return;
|
|
1053
|
+
err(this.dtls.sessionId, "failed to send alert", error);
|
|
1054
|
+
})
|
|
1055
|
+
.finally(() => timer.abort())
|
|
1056
|
+
// A UDP transport hands the datagram to the socket on a later tick
|
|
1057
|
+
// (dgram resolves the address asynchronously): closing the socket
|
|
1058
|
+
// right after send() resolved would drop the alert.
|
|
1059
|
+
.then(() => (0, promises_1.setImmediate)());
|
|
1060
|
+
this.alertSending = done;
|
|
1061
|
+
return done;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Abort the handshake (or the connection) because this side detected a
|
|
1065
|
+
* fatal error: see {@link endWithFatalAlert}.
|
|
1066
|
+
*/
|
|
1067
|
+
abortWithFatalAlert(description, reason) {
|
|
1068
|
+
void this.endWithFatalAlert(description, reason);
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* The single ending path for a fatal alert sent by this side (the public
|
|
1072
|
+
* {@link sendAlert} and an internal abort): send the alert, stop the
|
|
1073
|
+
* flights, report a local {@link DtlsAlertError} on onError (once), and
|
|
1074
|
+
* close the transport once the alert has been sent or timed out. Does
|
|
1075
|
+
* nothing more once the connection already ended.
|
|
1076
|
+
*/
|
|
1077
|
+
endWithFatalAlert(description, reason, options = {}) {
|
|
1078
|
+
if (this.ended || this.alertSent || this.transport.closed) {
|
|
1079
|
+
return this.alertSending ?? Promise.resolve();
|
|
1080
|
+
}
|
|
1081
|
+
const sending = this.transmitAlert(const_2.AlertLevel.fatal, description, options);
|
|
1082
|
+
this.ended = true;
|
|
1083
|
+
this.transport.stopFlights();
|
|
1084
|
+
// The transport closes once the alert was sent, whatever a listener does.
|
|
1085
|
+
const done = sending.then(() => this.closeTransport());
|
|
1086
|
+
this.alertSending = done;
|
|
1087
|
+
this.notify(this.onError, new alert_1.DtlsAlertError({ level: const_2.AlertLevel.fatal, description }, "local", reason));
|
|
1088
|
+
return done;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Call `options.verifyRemoteCertificate` with the received peer
|
|
1092
|
+
* certificate. When it returns false or throws, the handshake is aborted
|
|
1093
|
+
* with a fatal bad_certificate alert and false is returned.
|
|
1094
|
+
*/
|
|
1095
|
+
verifyRemoteCertificate() {
|
|
1096
|
+
const verify = this.options.verifyRemoteCertificate;
|
|
1097
|
+
if (!verify)
|
|
1098
|
+
return true;
|
|
1099
|
+
const certificate = this.cipher.remoteCertificate;
|
|
1100
|
+
let reason;
|
|
1101
|
+
try {
|
|
1102
|
+
if (certificate && verify(Buffer.from(certificate))) {
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
catch (error) {
|
|
1107
|
+
reason = error;
|
|
1108
|
+
}
|
|
1109
|
+
err(this.dtls.sessionId, "remote certificate rejected", reason);
|
|
1110
|
+
this.abortWithFatalAlert(const_2.AlertDesc.BadCertificate, reason);
|
|
1111
|
+
return false;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Close the transport (once; concurrent callers share the same close) and
|
|
1115
|
+
* resolve when it has closed. A failure (a rejection or a synchronous
|
|
1116
|
+
* throw of the transport's close()) is only logged: it never interrupts
|
|
1117
|
+
* the caller, e.g. the onError notification of a received fatal alert.
|
|
1118
|
+
*/
|
|
1119
|
+
closeTransport() {
|
|
1120
|
+
// Spec: tests/server.test.ts › "frees partial handshake fragments when
|
|
1121
|
+
// the connection ends by sending a fatal alert / close()"
|
|
1122
|
+
this.reassembler.clear();
|
|
1123
|
+
return this.transport.close().catch((error) => {
|
|
1124
|
+
err(this.dtls.sessionId, "failed to close transport", error);
|
|
1125
|
+
});
|
|
200
1126
|
}
|
|
201
1127
|
setupExtensions() {
|
|
202
1128
|
log(this.dtls.sessionId, "support srtpProfiles", this.options.srtpProfiles);
|
|
203
1129
|
if (this.options.srtpProfiles && this.options.srtpProfiles.length > 0) {
|
|
204
|
-
|
|
1130
|
+
// Empty MKI payload (length byte is written by UseSRTP.serialize).
|
|
1131
|
+
const useSrtp = useSrtp_1.UseSRTP.create(this.options.srtpProfiles, Buffer.alloc(0));
|
|
205
1132
|
this.extensions.push(useSrtp.extension);
|
|
206
1133
|
}
|
|
207
1134
|
{
|
|
@@ -226,28 +1153,191 @@ class DtlsSocket {
|
|
|
226
1153
|
this.extensions.push(renegotiationIndication.extension);
|
|
227
1154
|
}
|
|
228
1155
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
1156
|
+
/**
|
|
1157
|
+
* Aborts association-owned async waits ({@link waitForReady} sleeps).
|
|
1158
|
+
* Invoked on every terminal transition so pending timers/promises cancel
|
|
1159
|
+
* immediately (not only "wake later and check torn-down").
|
|
1160
|
+
*/
|
|
1161
|
+
abortAssociationWaits() {
|
|
1162
|
+
if (!this.associationAbort.signal.aborted) {
|
|
1163
|
+
this.associationAbort.abort();
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns the handshake messages that `messages` (received in a record of
|
|
1168
|
+
* `epoch`) complete. Spec: `tests/server.test.ts` › "handleFragmentHandshake
|
|
1169
|
+
* returns a message only once every byte was received"
|
|
1170
|
+
*/
|
|
1171
|
+
handleFragmentHandshake(messages, epoch = 0) {
|
|
1172
|
+
const handshakes = [];
|
|
1173
|
+
for (const message of messages) {
|
|
1174
|
+
const handshake = this.reassembler.add(message, epoch);
|
|
1175
|
+
if (handshake)
|
|
1176
|
+
handshakes.push(handshake);
|
|
1177
|
+
}
|
|
1178
|
+
return handshakes;
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Guard for send / exporter / remoteCertificate.
|
|
1182
|
+
* Dual client overrides to reject `closed` and `probing` (no 1.2 fallthrough).
|
|
1183
|
+
*/
|
|
1184
|
+
assertReadyForApplicationApi(op) {
|
|
1185
|
+
if (this.associationTornDown) {
|
|
1186
|
+
throw new Error(`DTLS association is closed; cannot ${op}`);
|
|
1187
|
+
}
|
|
1188
|
+
// Engine may enter closing (onClosing) before associationTornDown if a
|
|
1189
|
+
// direct engine path races; still reject Public API.
|
|
1190
|
+
if (this.engine13?.isClosed()) {
|
|
1191
|
+
throw new Error(`DTLS association is closed; cannot ${op}`);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Normalize and store association TX peer pin on TransportContext.
|
|
1196
|
+
*
|
|
1197
|
+
* Why association-owned: UdpTransport.rinfo is overwritten by every inbound
|
|
1198
|
+
* datagram (including spoof). Flight retransmit and application send must not
|
|
1199
|
+
* follow last-rinfo alone (ticket peer-pinning / TX ownership).
|
|
1200
|
+
*
|
|
1201
|
+
* @param mode `set-if-empty` keeps the first authenticated pin (server Flight4 /
|
|
1202
|
+
* connect). `replace` is for dual association re-pin / client connect.
|
|
1203
|
+
*/
|
|
1204
|
+
pinSendPeer(addr, mode = "set-if-empty") {
|
|
1205
|
+
if (!addr || addr[0] == null || addr[1] == null)
|
|
1206
|
+
return;
|
|
1207
|
+
// "unpinned": TX follows the transport's last remote address.
|
|
1208
|
+
if (this.peerIdentityMode === "unpinned")
|
|
1209
|
+
return;
|
|
1210
|
+
if (mode === "set-if-empty" && this.transport.pinnedPeer)
|
|
1211
|
+
return;
|
|
1212
|
+
this.transport.pinnedPeer = (0, peer_1.normalizePeerTuple)([addr[0], addr[1]]);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Pin from last transport rinfo when present.
|
|
1216
|
+
* Default mode is `set-if-empty` (keeps an existing authenticated pin).
|
|
1217
|
+
* Pass `replace` when the association deliberately re-pins (e.g. client connect).
|
|
1218
|
+
*/
|
|
1219
|
+
pinSendPeerFromTransportRinfo(mode = "set-if-empty") {
|
|
1220
|
+
const r = this.options.transport.rinfo;
|
|
1221
|
+
if (r?.address != null && r?.port != null) {
|
|
1222
|
+
this.pinSendPeer([r.address, r.port], mode);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
/** Clear TX pin on association terminal teardown. */
|
|
1226
|
+
clearSendPeerPin() {
|
|
1227
|
+
this.transport.pinnedPeer = undefined;
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Cancel pending DTLS 1.2 flight retransmit sleeps only (leave flight number).
|
|
1231
|
+
* Use on successful handshake complete so Flight4/Flight5 sleep does not
|
|
1232
|
+
* linger until the next RTO after onConnect.
|
|
1233
|
+
*/
|
|
1234
|
+
cancelLegacy12FlightTimers() {
|
|
1235
|
+
this.dtls.cancelFlightTimers();
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Abort legacy DTLS 1.2 flight: optional fatalError, flight=99, cancel timers.
|
|
1239
|
+
* Use on close / fatal alert / version commit away from 1.2 — not on
|
|
1240
|
+
* successful handshake complete (that only needs cancelLegacy12FlightTimers).
|
|
1241
|
+
*/
|
|
1242
|
+
abortLegacy12Flight(error) {
|
|
1243
|
+
if (error)
|
|
1244
|
+
this.dtls.fatalError = error;
|
|
1245
|
+
this.dtls.flight = 99;
|
|
1246
|
+
this.dtls.cancelFlightTimers();
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Association-wide fatal teardown for DTLS 1.2 (TLS: immediate connection end).
|
|
1250
|
+
* Stops flight timers, clears connected, closes transport, disables Public API.
|
|
1251
|
+
* Dual client overrides to also set dualPhase=closed and close carrier/candidates.
|
|
1252
|
+
*
|
|
1253
|
+
* @returns true when the association was torn down now (false when it was
|
|
1254
|
+
* already terminal), so the caller fires onError once.
|
|
1255
|
+
*/
|
|
1256
|
+
failLegacy12Association(error) {
|
|
1257
|
+
if (this.associationTornDown)
|
|
1258
|
+
return false;
|
|
1259
|
+
this.abortLegacy12Flight(error);
|
|
1260
|
+
this.connected = false;
|
|
1261
|
+
this.associationTornDown = true;
|
|
1262
|
+
this.ended = true;
|
|
1263
|
+
this.abortAssociationWaits();
|
|
1264
|
+
this.clearSendPeerPin();
|
|
1265
|
+
void this.transport.close().catch(() => { });
|
|
1266
|
+
return true;
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Tear down the 1.2 association then fire onError once (no onClose: it is
|
|
1270
|
+
* reserved for close_notify and a local close()).
|
|
1271
|
+
* Used for fatal alerts, handshake failures, probing DOWNGRD / classify error,
|
|
1272
|
+
* and ProtocolVersionError paths. Idempotent: concurrent terminal paths must
|
|
1273
|
+
* not double-fire public events.
|
|
1274
|
+
*/
|
|
1275
|
+
reportLegacy12Fatal(error) {
|
|
1276
|
+
// failLegacy12Association returns false when already terminal.
|
|
1277
|
+
if (!this.failLegacy12Association(error))
|
|
1278
|
+
return;
|
|
1279
|
+
this.notify(this.onError, error);
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Local close for pure DTLS 1.2 (server and non-overridden paths).
|
|
1283
|
+
* Terminal transition + optional single public onClose (client dual uses
|
|
1284
|
+
* closeAssociationHard instead).
|
|
1285
|
+
*/
|
|
1286
|
+
closeLegacy12Association(firePublicOnClose = true, closeTransport = true) {
|
|
1287
|
+
if (this.associationTornDown)
|
|
1288
|
+
return;
|
|
1289
|
+
this.abortLegacy12Flight();
|
|
1290
|
+
this.connected = false;
|
|
1291
|
+
this.associationTornDown = true;
|
|
1292
|
+
this.ended = true;
|
|
1293
|
+
this.reassembler.clear();
|
|
1294
|
+
this.abortAssociationWaits();
|
|
1295
|
+
this.clearSendPeerPin();
|
|
1296
|
+
if (firePublicOnClose) {
|
|
1297
|
+
this.notify(this.onClose);
|
|
1298
|
+
}
|
|
1299
|
+
if (closeTransport) {
|
|
1300
|
+
void this.transport.close().catch(() => { });
|
|
244
1301
|
}
|
|
245
|
-
return handshakes; // return un fragmented handshakes
|
|
246
1302
|
}
|
|
247
|
-
|
|
248
|
-
|
|
1303
|
+
/**
|
|
1304
|
+
* Close this association. The Public API becomes terminal synchronously
|
|
1305
|
+
* (send() right after close() drops the data), before any await. DTLS 1.2
|
|
1306
|
+
* optionally sends close_notify first; an alert already handed to the
|
|
1307
|
+
* transport is flushed before the transport closes. A live DTLS 1.3 engine
|
|
1308
|
+
* sends its close_notify and closes the transport itself
|
|
1309
|
+
* (teardownAssociation), so it is not closed here.
|
|
1310
|
+
*/
|
|
1311
|
+
async close(options = {}) {
|
|
1312
|
+
const sending = options.notify && !this.engine13
|
|
1313
|
+
? this.sendAlert(const_2.AlertLevel.warning, const_2.AlertDesc.CloseNotify, {
|
|
1314
|
+
...(options.timeoutMs !== undefined && {
|
|
1315
|
+
timeoutMs: options.timeoutMs,
|
|
1316
|
+
}),
|
|
1317
|
+
})
|
|
1318
|
+
: undefined;
|
|
1319
|
+
this.markEndedByLocalClose();
|
|
1320
|
+
if (this.engine13) {
|
|
1321
|
+
// onClosing from the engine is idempotent with prepareAssociationClosed.
|
|
1322
|
+
this.prepareAssociationClosedFromEngine();
|
|
1323
|
+
this.engine13.close();
|
|
1324
|
+
await this.alertFlushed();
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
// DTLS 1.2 server (and any non-overridden close): terminal + onClose once.
|
|
1328
|
+
this.closeLegacy12Association(true, false);
|
|
1329
|
+
await sending;
|
|
1330
|
+
// Closing the transport now would drop an alert handed to it but not
|
|
1331
|
+
// yet written (a UDP datagram goes out on a later tick).
|
|
1332
|
+
await this.alertFlushed();
|
|
1333
|
+
// Waits for a close already in progress (e.g. after a fatal alert).
|
|
1334
|
+
await this.closeTransport();
|
|
249
1335
|
}
|
|
250
1336
|
extractSessionKeys(keyLength, saltLength) {
|
|
1337
|
+
this.assertReadyForApplicationApi("extractSessionKeys");
|
|
1338
|
+
if (this.engine13) {
|
|
1339
|
+
return this.engine13.extractSessionKeys(keyLength, saltLength);
|
|
1340
|
+
}
|
|
251
1341
|
const keyingMaterial = this.exportKeyingMaterial("EXTRACTOR-dtls_srtp", keyLength * 2 + saltLength * 2);
|
|
252
1342
|
const { clientKey, serverKey, clientSalt, serverSalt } = decode(keyingMaterial, {
|
|
253
1343
|
clientKey: types.buffer(keyLength),
|
|
@@ -273,11 +1363,210 @@ class DtlsSocket {
|
|
|
273
1363
|
}
|
|
274
1364
|
}
|
|
275
1365
|
exportKeyingMaterial(label, length) {
|
|
1366
|
+
this.assertReadyForApplicationApi("exportKeyingMaterial");
|
|
1367
|
+
if (this.engine13) {
|
|
1368
|
+
return this.engine13.exportKeyingMaterial(label, length);
|
|
1369
|
+
}
|
|
276
1370
|
return (0, prf_1.exportKeyingMaterial)(label, length, this.cipher.masterSecret, this.cipher.localRandom.serialize(), this.cipher.remoteRandom.serialize(), this.sessionType === abstract_1.SessionType.CLIENT);
|
|
277
1371
|
}
|
|
278
1372
|
get remoteCertificate() {
|
|
1373
|
+
this.assertReadyForApplicationApi("remoteCertificate");
|
|
1374
|
+
if (this.engine13) {
|
|
1375
|
+
return this.engine13.remoteCertificate;
|
|
1376
|
+
}
|
|
279
1377
|
return this.cipher.remoteCertificate;
|
|
280
1378
|
}
|
|
1379
|
+
/** Request KeyUpdate on DTLS 1.3 connections. */
|
|
1380
|
+
async keyUpdate(requestUpdate = false) {
|
|
1381
|
+
this.assertReadyForApplicationApi("keyUpdate");
|
|
1382
|
+
if (!this.engine13) {
|
|
1383
|
+
throw new Error("KeyUpdate is only available for DTLS 1.3");
|
|
1384
|
+
}
|
|
1385
|
+
await this.engine13.keyUpdate(requestUpdate);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* @internal Keep the selected DTLS 1.3 engine's milestones before dropping
|
|
1389
|
+
* it. The 1.2 latch must not stand in for them: it reaches all three at once.
|
|
1390
|
+
*/
|
|
1391
|
+
retireSelectedEngine13() {
|
|
1392
|
+
const engine = this.engine13;
|
|
1393
|
+
if (!engine)
|
|
1394
|
+
return;
|
|
1395
|
+
const reached = engine.readiness;
|
|
1396
|
+
const previous = this.retiredEngine13Readiness;
|
|
1397
|
+
this.retiredEngine13Readiness = {
|
|
1398
|
+
writeReady: reached.writeReady || !!previous?.writeReady,
|
|
1399
|
+
peerHandshakeAuthenticated: reached.peerHandshakeAuthenticated ||
|
|
1400
|
+
!!previous?.peerHandshakeAuthenticated,
|
|
1401
|
+
handshakeComplete: reached.handshakeComplete || !!previous?.handshakeComplete,
|
|
1402
|
+
};
|
|
1403
|
+
this.engine13 = undefined;
|
|
1404
|
+
}
|
|
1405
|
+
/** Drop bridge subscriptions for a disposed or replaced 1.3 candidate. */
|
|
1406
|
+
unbridgeEngine13() {
|
|
1407
|
+
this.engine13Bridge.dispose();
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Association-level fatal teardown after a non-soft 1.3 engine error.
|
|
1411
|
+
* Clears public engine13 (isDtls13 → false), stops bridge callbacks, and
|
|
1412
|
+
* hard-disposes candidate resources. HVR dual soft transition must not call
|
|
1413
|
+
* this (filterError swallows DtlsVersionSelected before we reach here).
|
|
1414
|
+
*
|
|
1415
|
+
* Subclasses (dual client) override to also flip dualPhase → closed and
|
|
1416
|
+
* tear down parked candidates / 1.2 flight timers.
|
|
1417
|
+
*
|
|
1418
|
+
* @returns true when the association was torn down now (the caller fires
|
|
1419
|
+
* onError afterwards, so handlers observe isDtls13 === false first).
|
|
1420
|
+
*/
|
|
1421
|
+
failAssociationFromEngine13(_err) {
|
|
1422
|
+
// Terminal for pure 1.3 and dual-server 1.3: same Public-API disable as 1.2.
|
|
1423
|
+
// Without associationTornDown, send/exporter fall through to an empty 1.2
|
|
1424
|
+
// cipher path after engine13 is cleared (role/version asymmetry / P1).
|
|
1425
|
+
if (this.associationTornDown && !this.engine13) {
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
this.connected = false;
|
|
1429
|
+
this.associationTornDown = true;
|
|
1430
|
+
this.ended = true;
|
|
1431
|
+
this.abortAssociationWaits();
|
|
1432
|
+
this.clearSendPeerPin();
|
|
1433
|
+
// Unbridge first so subsequent engine onClose/onError cannot re-enter or
|
|
1434
|
+
// double-fire public callbacks when fail() continues to onClose.
|
|
1435
|
+
this.unbridgeEngine13();
|
|
1436
|
+
const eng = this.engine13;
|
|
1437
|
+
this.retireSelectedEngine13();
|
|
1438
|
+
if (eng) {
|
|
1439
|
+
// Soft ProtocolVersionError leaves carrier open; hard fail may already
|
|
1440
|
+
// have closed it. Always force resource dispose without re-firing events.
|
|
1441
|
+
eng.hardDisposeResources();
|
|
1442
|
+
}
|
|
1443
|
+
// Always close transport (hardDispose does not). Double-close is fine.
|
|
1444
|
+
void this.transport.close().catch(() => { });
|
|
1445
|
+
// Engine hard-fail would have fired onClose after onError, but unbridge
|
|
1446
|
+
// removed that subscription — association owns the single public onClose.
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Before public onClose for engine teardown: mark association closed so
|
|
1451
|
+
* re-entrant client.close() inside onClose handlers is idempotent and
|
|
1452
|
+
* Public APIs reject (send/exporter/cert) without 1.2 fallthrough.
|
|
1453
|
+
* Dual client also sets dualPhase → closed here.
|
|
1454
|
+
*/
|
|
1455
|
+
prepareAssociationClosedFromEngine() {
|
|
1456
|
+
this.connected = false;
|
|
1457
|
+
this.associationTornDown = true;
|
|
1458
|
+
this.abortAssociationWaits();
|
|
1459
|
+
this.clearSendPeerPin();
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* After engine onClose (peer close_notify or local engine close) has been
|
|
1463
|
+
* delivered publicly: drop the 1.3 handle. Dual client overrides to also
|
|
1464
|
+
* hard-close carrier / transport / candidates.
|
|
1465
|
+
*/
|
|
1466
|
+
onEngine13PeerOrLocalClose() {
|
|
1467
|
+
// Idempotent terminal mark (prepareAssociationClosedFromEngine already ran).
|
|
1468
|
+
this.associationTornDown = true;
|
|
1469
|
+
this.connected = false;
|
|
1470
|
+
this.clearSendPeerPin();
|
|
1471
|
+
this.unbridgeEngine13();
|
|
1472
|
+
this.retireSelectedEngine13();
|
|
1473
|
+
void this.transport.close().catch(() => { });
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Wire DTLS 1.3 engine events onto this socket.
|
|
1477
|
+
* @param engine DTLS 1.3 connection to bridge.
|
|
1478
|
+
* @param options Optional bridge options. When `options.filterError` returns
|
|
1479
|
+
* true, swallow the error (e.g. dual-stack version mismatch handled by
|
|
1480
|
+
* transparent fallback without public onError).
|
|
1481
|
+
*/
|
|
1482
|
+
bridgeEngine13(engine, options) {
|
|
1483
|
+
// Replace any prior bridge so only the current candidate is public.
|
|
1484
|
+
this.unbridgeEngine13();
|
|
1485
|
+
this.engine13 = engine;
|
|
1486
|
+
if (this.rxGenerationProvider) {
|
|
1487
|
+
engine.expectedRxGeneration = this.rxGenerationProvider;
|
|
1488
|
+
}
|
|
1489
|
+
engine.onConnect
|
|
1490
|
+
.subscribe(() => {
|
|
1491
|
+
// Terminal mid-handshake: do not flip connected back to true / re-fire.
|
|
1492
|
+
if (this.associationTornDown)
|
|
1493
|
+
return;
|
|
1494
|
+
this.connected = true;
|
|
1495
|
+
// Bridge negotiated use_srtp into public DtlsSocket.srtp (DTLS 1.2 path parity)
|
|
1496
|
+
const profile = engine.srtpProfile;
|
|
1497
|
+
if (profile !== undefined) {
|
|
1498
|
+
this.srtp.srtpProfile = profile;
|
|
1499
|
+
}
|
|
1500
|
+
this.notify(this.onConnect);
|
|
1501
|
+
})
|
|
1502
|
+
.disposer(this.engine13Bridge);
|
|
1503
|
+
engine.onData
|
|
1504
|
+
.subscribe((data) => this.notify(this.onData, data))
|
|
1505
|
+
.disposer(this.engine13Bridge);
|
|
1506
|
+
// Graceful close start (local close / peer close_notify): Public API off
|
|
1507
|
+
// immediately — before async close_notify completes.
|
|
1508
|
+
engine.onClosing
|
|
1509
|
+
.subscribe(() => {
|
|
1510
|
+
this.prepareAssociationClosedFromEngine();
|
|
1511
|
+
})
|
|
1512
|
+
.disposer(this.engine13Bridge);
|
|
1513
|
+
engine.onError
|
|
1514
|
+
.subscribe((e) => {
|
|
1515
|
+
// HVR soft dual transition only: do not public-error or fatal-teardown.
|
|
1516
|
+
if (options?.filterError?.(e))
|
|
1517
|
+
return;
|
|
1518
|
+
this.connected = false;
|
|
1519
|
+
// Tear down association before public onError so handlers observe
|
|
1520
|
+
// isDtls13 === false and dualPhase === closed (client override).
|
|
1521
|
+
// A fatal error ends the association with onError only: onClose is
|
|
1522
|
+
// reserved for close_notify and a local close() (as for DTLS 1.2).
|
|
1523
|
+
this.failAssociationFromEngine13(e);
|
|
1524
|
+
this.notify(this.onError, e);
|
|
1525
|
+
})
|
|
1526
|
+
.disposer(this.engine13Bridge);
|
|
1527
|
+
engine.onClose
|
|
1528
|
+
.subscribe(() => {
|
|
1529
|
+
// Mark closed before public onClose so handlers that call close()
|
|
1530
|
+
// re-entrantly do not double-fire onClose. (Often already set via onClosing.)
|
|
1531
|
+
this.prepareAssociationClosedFromEngine();
|
|
1532
|
+
// Fire public onClose while engine13 is still inspectable. Isolated:
|
|
1533
|
+
// a throwing listener must not skip the association close below.
|
|
1534
|
+
this.notify(this.onClose);
|
|
1535
|
+
// Then association-level close: carrier/transport/candidates.
|
|
1536
|
+
this.onEngine13PeerOrLocalClose();
|
|
1537
|
+
})
|
|
1538
|
+
.disposer(this.engine13Bridge);
|
|
1539
|
+
this.notifyEngine13Selected();
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Notify association-level readiness waiters that DTLS 1.3 is active.
|
|
1543
|
+
*
|
|
1544
|
+
* A dual-stack client can resume a parked candidate without rebuilding its
|
|
1545
|
+
* event bridge, so that path must share the same selection notification as a
|
|
1546
|
+
* freshly created engine.
|
|
1547
|
+
*/
|
|
1548
|
+
notifyEngine13Selected() {
|
|
1549
|
+
this.onEngine13Selected.execute();
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Send a fatal DTLSPlaintext alert (used for protocol_version mismatch).
|
|
1553
|
+
* @param description Alert description code.
|
|
1554
|
+
* @param dest Explicit peer for this reply. Required pre-cookie so a concurrent
|
|
1555
|
+
* spoof cannot redirect via mutable transport.rinfo; post-pin falls back to
|
|
1556
|
+
* TransportContext.pinnedPeer when omitted.
|
|
1557
|
+
*/
|
|
1558
|
+
async sendPlaintextAlert(description, dest) {
|
|
1559
|
+
const alert = Buffer.from([2, description]); // fatal
|
|
1560
|
+
const pkt = (0, builder_1.createPlaintext)(this.dtls)([{ type: const_2.ContentType.alert, fragment: alert }], ++this.dtls.recordSequenceNumber)[0];
|
|
1561
|
+
await this.transport.send(pkt.serialize(), dest);
|
|
1562
|
+
}
|
|
281
1563
|
}
|
|
282
1564
|
exports.DtlsSocket = DtlsSocket;
|
|
1565
|
+
/** Default upper bound (ms) for waiting until an alert has been sent. */
|
|
1566
|
+
Object.defineProperty(DtlsSocket, "AlertSendTimeoutMs", {
|
|
1567
|
+
enumerable: true,
|
|
1568
|
+
configurable: true,
|
|
1569
|
+
writable: true,
|
|
1570
|
+
value: 200
|
|
1571
|
+
});
|
|
283
1572
|
//# sourceMappingURL=socket.js.map
|