werift 0.28.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 +182 -2
- package/lib/common/src/transport.d.ts +39 -5
- package/lib/common/src/transport.js +32 -7
- package/lib/common/src/transport.js.map +1 -1
- 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 +1257 -16
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +45 -0
- package/lib/dtls/src/context/dtls.js +114 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +13 -0
- package/lib/dtls/src/context/transport.js +29 -1
- 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 +13 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +16 -0
- package/lib/dtls/src/flight/flight.js +109 -8
- 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 +8 -0
- 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 +6 -1
- package/lib/dtls/src/index.js +116 -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 +6 -0
- package/lib/dtls/src/record/const.js +6 -0
- 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.js +24 -16
- 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 +367 -20
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +379 -35
- package/lib/dtls/src/socket.js +1105 -132
- 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/consent.d.ts +78 -1
- package/lib/ice/src/consent.js +236 -24
- package/lib/ice/src/consent.js.map +1 -1
- 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 +265 -9
- package/lib/ice/src/ice.js +1624 -236
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +197 -6
- package/lib/ice/src/iceBase.js +157 -7
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +2 -0
- package/lib/ice/src/index.js +4 -1
- package/lib/ice/src/index.js.map +1 -1
- 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/hostInterfaces.d.ts +13 -2
- package/lib/ice/src/internal/hostInterfaces.js +16 -4
- package/lib/ice/src/internal/hostInterfaces.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/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 +40 -0
- package/lib/ice/src/nomination/selectionReplacement.js +65 -7
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -1
- 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 +29 -0
- package/lib/ice/src/stun/protocol.js +91 -4
- 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 +1 -0
- package/lib/ice/src/stun/tcpProtocol.js +14 -2
- 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 +23 -0
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +21 -2
- package/lib/ice/src/turn/protocol.js +93 -8
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +9 -0
- 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/message.d.ts +15 -2
- package/lib/ice-server/src/stun/message.js +156 -25
- 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 +19568 -3106
- package/lib/nonstandard/index.mjs +2539 -1175
- package/lib/polyfill/dom.mjs +33210 -16872
- package/lib/polyfill/index.mjs +33345 -17013
- 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/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 +81 -5
- package/lib/sctp/src/sctp.js +273 -28
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +11 -1
- package/lib/webrtc/src/api/compatibilityOptions.js +11 -1
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -1
- package/lib/webrtc/src/api/peerConfig.d.ts +210 -13
- package/lib/webrtc/src/api/peerConfig.js +100 -5
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +10 -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/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/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 +6 -0
- package/lib/webrtc/src/media/router.js +39 -1
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +56 -6
- package/lib/webrtc/src/media/rtpReceiver.js +165 -15
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +1 -1
- package/lib/webrtc/src/media/rtpSender.js +4 -3
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +29 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +31 -9
- package/lib/webrtc/src/media/rtpTransceiver.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 +103 -11
- package/lib/webrtc/src/media/track.js +241 -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/transportActivation.d.ts +4 -0
- package/lib/webrtc/src/negotiation/transportActivation.js +112 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +25 -4
- package/lib/webrtc/src/negotiationTransaction.js +27 -6
- 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 +44 -8
- package/lib/webrtc/src/peerConnection.js +88 -9
- 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 +6 -2
- 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 +2 -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 +158 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +38 -2
- package/lib/webrtc/src/sdp.js +84 -3
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +19 -9
- package/lib/webrtc/src/sdpManager.js +26 -4
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +11 -2
- package/lib/webrtc/src/secureTransportManager.js +84 -5
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +5 -2
- package/lib/webrtc/src/transceiverManager.js +42 -14
- 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 +150 -55
- package/lib/webrtc/src/transport/dtls.js +1017 -556
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +35 -2
- package/lib/webrtc/src/transport/ice.js +147 -14
- 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 +126 -2
- package/lib/webrtc/src/transport/sctp.js +747 -134
- 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 +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 +7 -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,6 +1,6 @@
|
|
|
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
5
|
const alert_1 = require("./alert");
|
|
6
6
|
const const_1 = require("./cipher/const");
|
|
@@ -10,20 +10,32 @@ const cipher_1 = require("./context/cipher");
|
|
|
10
10
|
const dtls_1 = require("./context/dtls");
|
|
11
11
|
const srtp_1 = require("./context/srtp");
|
|
12
12
|
const transport_1 = require("./context/transport");
|
|
13
|
+
const cookie_1 = require("./handshake/extensions/cookie");
|
|
13
14
|
const ellipticCurves_1 = require("./handshake/extensions/ellipticCurves");
|
|
14
15
|
const extendedMasterSecret_1 = require("./handshake/extensions/extendedMasterSecret");
|
|
15
16
|
const renegotiationIndication_1 = require("./handshake/extensions/renegotiationIndication");
|
|
16
17
|
const signature_1 = require("./handshake/extensions/signature");
|
|
17
18
|
const useSrtp_1 = require("./handshake/extensions/useSrtp");
|
|
18
19
|
const common_1 = require("./imports/common");
|
|
20
|
+
const peer_1 = require("./peer");
|
|
19
21
|
const builder_1 = require("./record/builder");
|
|
20
22
|
const const_2 = require("./record/const");
|
|
21
|
-
const
|
|
23
|
+
const reassembler_1 = require("./record/message/reassembler");
|
|
22
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; } });
|
|
23
27
|
const { decode, types } = common_1.binaryData;
|
|
24
28
|
const log = (0, common_1.debug)("werift-dtls : packages/dtls/src/socket.ts : log");
|
|
25
29
|
const err = (0, common_1.debug)("werift-dtls : packages/dtls/src/socket.ts : err");
|
|
26
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
|
+
}
|
|
27
39
|
constructor(options, sessionType) {
|
|
28
40
|
Object.defineProperty(this, "options", {
|
|
29
41
|
enumerable: true,
|
|
@@ -98,29 +110,57 @@ class DtlsSocket {
|
|
|
98
110
|
writable: true,
|
|
99
111
|
value: new srtp_1.SrtpContext()
|
|
100
112
|
});
|
|
101
|
-
Object.defineProperty(this, "
|
|
113
|
+
Object.defineProperty(this, "_connected", {
|
|
102
114
|
enumerable: true,
|
|
103
115
|
configurable: true,
|
|
104
116
|
writable: true,
|
|
105
117
|
value: false
|
|
106
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", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: false
|
|
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
|
+
});
|
|
107
141
|
Object.defineProperty(this, "extensions", {
|
|
108
142
|
enumerable: true,
|
|
109
143
|
configurable: true,
|
|
110
144
|
writable: true,
|
|
111
145
|
value: []
|
|
112
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
|
+
*/
|
|
113
152
|
Object.defineProperty(this, "onHandleHandshakes", {
|
|
114
153
|
enumerable: true,
|
|
115
154
|
configurable: true,
|
|
116
155
|
writable: true,
|
|
117
156
|
value: void 0
|
|
118
157
|
});
|
|
119
|
-
|
|
158
|
+
/** Partially received handshake messages (RFC 6347 §4.2.3). */
|
|
159
|
+
Object.defineProperty(this, "reassembler", {
|
|
120
160
|
enumerable: true,
|
|
121
161
|
configurable: true,
|
|
122
162
|
writable: true,
|
|
123
|
-
value:
|
|
163
|
+
value: new reassembler_1.HandshakeReassembler()
|
|
124
164
|
});
|
|
125
165
|
/** close_notify or a fatal alert was sent: no record is sent any more. */
|
|
126
166
|
Object.defineProperty(this, "alertSent", {
|
|
@@ -146,74 +186,59 @@ class DtlsSocket {
|
|
|
146
186
|
writable: true,
|
|
147
187
|
value: false
|
|
148
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
|
|
235
|
+
});
|
|
149
236
|
Object.defineProperty(this, "udpOnMessage", {
|
|
150
237
|
enumerable: true,
|
|
151
238
|
configurable: true,
|
|
152
239
|
writable: true,
|
|
153
|
-
value: (data) => {
|
|
154
|
-
|
|
155
|
-
return;
|
|
156
|
-
const packets = (0, receive_1.parsePacket)(data);
|
|
157
|
-
for (const packet of packets) {
|
|
158
|
-
// An alert earlier in this datagram may have ended the connection.
|
|
159
|
-
if (this.ended)
|
|
160
|
-
return;
|
|
161
|
-
try {
|
|
162
|
-
const messages = (0, receive_1.parsePlainText)(this.dtls, this.cipher)(packet);
|
|
163
|
-
for (const message of messages) {
|
|
164
|
-
// An alert earlier in this record (e.g. close_notify followed by a
|
|
165
|
-
// fatal alert) may have ended the connection: the rest is ignored.
|
|
166
|
-
if (this.ended)
|
|
167
|
-
return;
|
|
168
|
-
switch (message.type) {
|
|
169
|
-
case const_2.ContentType.handshake:
|
|
170
|
-
{
|
|
171
|
-
// Once the handshake completed, a handshake record of an
|
|
172
|
-
// epoch older than the peer's authenticated one (a plaintext
|
|
173
|
-
// epoch-0 Certificate, ClientHello, ...) is unauthenticated:
|
|
174
|
-
// anyone on the path can inject it, so it must not change
|
|
175
|
-
// the session (overwrite the peer certificate and fail its
|
|
176
|
-
// check, or reset the session through renegotiation()). It
|
|
177
|
-
// is dropped. A legitimate retransmission of the peer's last
|
|
178
|
-
// flight still carries its Finished at the current epoch.
|
|
179
|
-
if (this.connected &&
|
|
180
|
-
packet.recordLayerHeader.epoch < this.dtls.remoteEpoch) {
|
|
181
|
-
log(this.dtls.sessionId, "drop a stale-epoch handshake record after the handshake", packet.recordLayerHeader.epoch);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
const handshake = message.data;
|
|
185
|
-
const handshakes = this.handleFragmentHandshake([handshake]);
|
|
186
|
-
const assembled = Object.values(handshakes.reduce((acc, cur) => {
|
|
187
|
-
if (!acc[cur.msg_type])
|
|
188
|
-
acc[cur.msg_type] = [];
|
|
189
|
-
acc[cur.msg_type].push(cur);
|
|
190
|
-
return acc;
|
|
191
|
-
}, {}))
|
|
192
|
-
.map((v) => fragment_1.FragmentedHandshake.assemble(v))
|
|
193
|
-
.sort((a, b) => a.msg_type - b.msg_type);
|
|
194
|
-
this.onHandleHandshakes(assembled).catch((error) => {
|
|
195
|
-
err(this.dtls.sessionId, "onHandleHandshakes error", error);
|
|
196
|
-
this.notify(this.onError, error);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
200
|
-
case const_2.ContentType.applicationData:
|
|
201
|
-
{
|
|
202
|
-
this.notify(this.onData, message.data);
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
case const_2.ContentType.alert:
|
|
206
|
-
this.handleAlert(message.data);
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
// An invalid record (e.g. failed to decrypt) is discarded
|
|
213
|
-
// (RFC 6347 §4.1.2.1).
|
|
214
|
-
err(this.dtls.sessionId, "catch udpOnMessage error", error);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
240
|
+
value: (data, addr, meta) => {
|
|
241
|
+
this.handleUdpDatagram(data, addr, meta);
|
|
217
242
|
}
|
|
218
243
|
});
|
|
219
244
|
Object.defineProperty(this, "waitForReady", {
|
|
@@ -222,69 +247,655 @@ class DtlsSocket {
|
|
|
222
247
|
writable: true,
|
|
223
248
|
value: (condition) => new Promise(async (r, f) => {
|
|
224
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
|
+
}
|
|
225
254
|
if (condition()) {
|
|
226
255
|
r();
|
|
227
|
-
|
|
256
|
+
return;
|
|
228
257
|
}
|
|
229
|
-
|
|
230
|
-
|
|
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
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
f(new Error("association closed during waitForReady"));
|
|
266
|
+
return;
|
|
231
267
|
}
|
|
232
268
|
}
|
|
233
|
-
f("waitForReady timeout");
|
|
269
|
+
f(new Error("waitForReady timeout"));
|
|
234
270
|
})
|
|
235
271
|
});
|
|
236
272
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
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.
|
|
239
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
|
+
});
|
|
294
|
+
/**send application data */
|
|
240
295
|
Object.defineProperty(this, "send", {
|
|
241
296
|
enumerable: true,
|
|
242
297
|
configurable: true,
|
|
243
298
|
writable: true,
|
|
244
299
|
value: async (buf, addr) => {
|
|
245
|
-
|
|
246
|
-
|
|
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");
|
|
247
304
|
return;
|
|
248
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
|
+
}
|
|
249
316
|
const pkt = (0, builder_1.createPlaintext)(this.dtls)([{ type: const_2.ContentType.applicationData, fragment: buf }], ++this.dtls.recordSequenceNumber)[0];
|
|
250
|
-
|
|
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);
|
|
251
320
|
}
|
|
252
321
|
});
|
|
253
322
|
this.options = options;
|
|
254
323
|
this.sessionType = sessionType;
|
|
324
|
+
this.protocolVersions = (0, version_1.normalizeProtocolVersions)(this.options.protocolVersions);
|
|
255
325
|
this.dtls = new dtls_1.DtlsContext(this.options, this.sessionType);
|
|
256
326
|
this.cipher = new cipher_1.CipherContext(this.sessionType, this.options.cert, this.options.key, this.options.signatureHash);
|
|
257
327
|
this.transport = new transport_1.TransportContext(this.options.transport);
|
|
258
328
|
this.setupExtensions();
|
|
259
329
|
this.transport.socket.onData = this.udpOnMessage;
|
|
260
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
|
+
}
|
|
261
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
|
+
}
|
|
262
586
|
log("renegotiation", this.sessionType);
|
|
587
|
+
this.invalidateLegacy12HandshakeOwnership();
|
|
263
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();
|
|
264
596
|
this.cipher = new cipher_1.CipherContext(this.sessionType, this.options.cert, this.options.key, this.options.signatureHash);
|
|
265
597
|
this.dtls = new dtls_1.DtlsContext(this.options, this.sessionType);
|
|
266
598
|
this.srtp = new srtp_1.SrtpContext();
|
|
267
599
|
this.extensions = [];
|
|
268
|
-
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);
|
|
269
656
|
}
|
|
270
657
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
658
|
+
* Resolved peer-identity policy for this association.
|
|
659
|
+
* Prefer explicit {@link Options.peerIdentityMode}; otherwise infer from
|
|
660
|
+
* transport.peerAuthenticated / addressValidation for backward compatibility.
|
|
274
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. */
|
|
275
883
|
alertFlushed() {
|
|
276
884
|
return this.alertSending ?? Promise.resolve();
|
|
277
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
|
+
}
|
|
278
894
|
/** Whether the connection ended (alert, or close()). */
|
|
279
895
|
get terminated() {
|
|
280
896
|
return this.ended;
|
|
281
897
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Whether the handshake must not go on: the connection ended, or this side
|
|
284
|
-
* sent close_notify (RFC 5246 §7.2.1: nothing is sent after it, so a
|
|
285
|
-
* handshake that would answer or complete stops; records received after it
|
|
286
|
-
* are still processed, to receive the peer's close_notify).
|
|
287
|
-
*/
|
|
898
|
+
/** Whether this handshake must stop after a terminal alert or close. */
|
|
288
899
|
get handshakeStopped() {
|
|
289
900
|
return this.ended || this.alertSent;
|
|
290
901
|
}
|
|
@@ -307,6 +918,17 @@ class DtlsSocket {
|
|
|
307
918
|
* a throwing listener does not leave the socket ended but unreported.
|
|
308
919
|
*/
|
|
309
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
|
+
}
|
|
310
932
|
const action = (0, alert_1.classifyAlert)(alert);
|
|
311
933
|
if (action === "ignore") {
|
|
312
934
|
log(this.dtls.sessionId, "ignore warning alert", alert);
|
|
@@ -314,28 +936,53 @@ class DtlsSocket {
|
|
|
314
936
|
return;
|
|
315
937
|
}
|
|
316
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();
|
|
317
942
|
// Retransmitting a handshake flight makes no sense any more.
|
|
318
943
|
this.transport.stopFlights();
|
|
319
944
|
if (action === "close") {
|
|
320
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);
|
|
321
951
|
// RFC 5246 §7.2.1: respond with close_notify; nothing is sent after it.
|
|
322
952
|
void this.sendAlert(const_2.AlertLevel.warning, const_2.AlertDesc.CloseNotify);
|
|
323
953
|
// The connection is over: the socket closes its transport once the
|
|
324
954
|
// reply has been sent or timed out, like after a fatal alert (the
|
|
325
955
|
// application does not need to call close()).
|
|
326
|
-
void this.alertFlushed().then(() => this.
|
|
327
|
-
this.notify(this.onAlert, alert);
|
|
328
|
-
this.notify(this.onClose);
|
|
956
|
+
void this.alertFlushed().then(() => this.finishPeerCloseNotify());
|
|
329
957
|
}
|
|
330
958
|
else {
|
|
331
959
|
err(this.dtls.sessionId, "received fatal alert", alert);
|
|
332
960
|
// A fatal alert is not answered (RFC 5246 §7.2.2).
|
|
333
961
|
this.alertSent = true;
|
|
334
|
-
this.
|
|
335
|
-
this.notify(this.onAlert, alert);
|
|
336
|
-
this.notify(this.onError, new alert_1.DtlsAlertError(alert, "remote"));
|
|
962
|
+
this.failFromRemoteAlert(alert, new alert_1.DtlsAlertError(alert, "remote"));
|
|
337
963
|
}
|
|
338
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
|
+
}
|
|
339
986
|
/**
|
|
340
987
|
* Send an alert to the peer, protected with the current epoch (plaintext
|
|
341
988
|
* before ChangeCipherSpec, encrypted after it).
|
|
@@ -470,6 +1117,9 @@ class DtlsSocket {
|
|
|
470
1117
|
* the caller, e.g. the onError notification of a received fatal alert.
|
|
471
1118
|
*/
|
|
472
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();
|
|
473
1123
|
return this.transport.close().catch((error) => {
|
|
474
1124
|
err(this.dtls.sessionId, "failed to close transport", error);
|
|
475
1125
|
});
|
|
@@ -477,7 +1127,8 @@ class DtlsSocket {
|
|
|
477
1127
|
setupExtensions() {
|
|
478
1128
|
log(this.dtls.sessionId, "support srtpProfiles", this.options.srtpProfiles);
|
|
479
1129
|
if (this.options.srtpProfiles && this.options.srtpProfiles.length > 0) {
|
|
480
|
-
|
|
1130
|
+
// Empty MKI payload (length byte is written by UseSRTP.serialize).
|
|
1131
|
+
const useSrtp = useSrtp_1.UseSRTP.create(this.options.srtpProfiles, Buffer.alloc(0));
|
|
481
1132
|
this.extensions.push(useSrtp.extension);
|
|
482
1133
|
}
|
|
483
1134
|
{
|
|
@@ -502,54 +1153,180 @@ class DtlsSocket {
|
|
|
502
1153
|
this.extensions.push(renegotiationIndication.extension);
|
|
503
1154
|
}
|
|
504
1155
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
});
|
|
514
|
-
if (this.bufferFragmentedHandshakes.length > 1) {
|
|
515
|
-
const [last] = this.bufferFragmentedHandshakes.slice(-1);
|
|
516
|
-
if (last.fragment_offset + last.fragment_length === last.length) {
|
|
517
|
-
handshakes = [...this.bufferFragmentedHandshakes, ...handshakes];
|
|
518
|
-
this.bufferFragmentedHandshakes = [];
|
|
519
|
-
}
|
|
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();
|
|
520
1164
|
}
|
|
521
|
-
return handshakes; // return un fragmented handshakes
|
|
522
1165
|
}
|
|
523
1166
|
/**
|
|
524
|
-
*
|
|
525
|
-
*
|
|
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).
|
|
526
1200
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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.
|
|
534
1252
|
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
|
|
538
|
-
|
|
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(() => { });
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
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.
|
|
539
1310
|
*/
|
|
540
1311
|
async close(options = {}) {
|
|
541
|
-
|
|
542
|
-
|
|
1312
|
+
const sending = options.notify && !this.engine13
|
|
1313
|
+
? this.sendAlert(const_2.AlertLevel.warning, const_2.AlertDesc.CloseNotify, {
|
|
543
1314
|
...(options.timeoutMs !== undefined && {
|
|
544
1315
|
timeoutMs: options.timeoutMs,
|
|
545
1316
|
}),
|
|
546
|
-
})
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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;
|
|
550
1326
|
}
|
|
551
|
-
|
|
552
|
-
this.
|
|
1327
|
+
// DTLS 1.2 server (and any non-overridden close): terminal + onClose once.
|
|
1328
|
+
this.closeLegacy12Association(true, false);
|
|
1329
|
+
await sending;
|
|
553
1330
|
// Closing the transport now would drop an alert handed to it but not
|
|
554
1331
|
// yet written (a UDP datagram goes out on a later tick).
|
|
555
1332
|
await this.alertFlushed();
|
|
@@ -557,6 +1334,10 @@ class DtlsSocket {
|
|
|
557
1334
|
await this.closeTransport();
|
|
558
1335
|
}
|
|
559
1336
|
extractSessionKeys(keyLength, saltLength) {
|
|
1337
|
+
this.assertReadyForApplicationApi("extractSessionKeys");
|
|
1338
|
+
if (this.engine13) {
|
|
1339
|
+
return this.engine13.extractSessionKeys(keyLength, saltLength);
|
|
1340
|
+
}
|
|
560
1341
|
const keyingMaterial = this.exportKeyingMaterial("EXTRACTOR-dtls_srtp", keyLength * 2 + saltLength * 2);
|
|
561
1342
|
const { clientKey, serverKey, clientSalt, serverSalt } = decode(keyingMaterial, {
|
|
562
1343
|
clientKey: types.buffer(keyLength),
|
|
@@ -582,11 +1363,203 @@ class DtlsSocket {
|
|
|
582
1363
|
}
|
|
583
1364
|
}
|
|
584
1365
|
exportKeyingMaterial(label, length) {
|
|
1366
|
+
this.assertReadyForApplicationApi("exportKeyingMaterial");
|
|
1367
|
+
if (this.engine13) {
|
|
1368
|
+
return this.engine13.exportKeyingMaterial(label, length);
|
|
1369
|
+
}
|
|
585
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);
|
|
586
1371
|
}
|
|
587
1372
|
get remoteCertificate() {
|
|
1373
|
+
this.assertReadyForApplicationApi("remoteCertificate");
|
|
1374
|
+
if (this.engine13) {
|
|
1375
|
+
return this.engine13.remoteCertificate;
|
|
1376
|
+
}
|
|
588
1377
|
return this.cipher.remoteCertificate;
|
|
589
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
|
+
}
|
|
590
1563
|
}
|
|
591
1564
|
exports.DtlsSocket = DtlsSocket;
|
|
592
1565
|
/** Default upper bound (ms) for waiting until an alert has been sent. */
|