werift 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +299 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +51 -10
- package/lib/common/src/transport.js +35 -9
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/carrier/direct.d.ts +67 -0
- package/lib/dtls/src/carrier/direct.js +226 -0
- package/lib/dtls/src/carrier/direct.js.map +1 -0
- package/lib/dtls/src/carrier/types.d.ts +81 -0
- package/lib/dtls/src/carrier/types.js +7 -0
- package/lib/dtls/src/carrier/types.js.map +1 -0
- package/lib/dtls/src/cipher/const.d.ts +6 -0
- package/lib/dtls/src/cipher/const.js +13 -2
- package/lib/dtls/src/cipher/const.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +11 -2
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
- package/lib/dtls/src/cipher/tls13/aead.js +128 -0
- package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/signature.js +149 -0
- package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
- package/lib/dtls/src/client.d.ts +253 -0
- package/lib/dtls/src/client.js +1269 -14
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +47 -0
- package/lib/dtls/src/context/dtls.js +121 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +30 -1
- package/lib/dtls/src/context/transport.js +67 -3
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
- package/lib/dtls/src/engine/v1_3/connection.js +680 -0
- package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
- package/lib/dtls/src/engine/v1_3/host.js +11 -0
- package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
- package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
- package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
- package/lib/dtls/src/engine/v1_3/types.js +113 -0
- package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
- package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
- package/lib/dtls/src/flight/client/flight1.js +9 -3
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
- package/lib/dtls/src/flight/client/flight3.js +24 -4
- package/lib/dtls/src/flight/client/flight3.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +17 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +21 -0
- package/lib/dtls/src/flight/flight.js +119 -9
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
- package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
- package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
- package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
- package/lib/dtls/src/flight/server/flight2.js +29 -105
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +14 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +12 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +10 -0
- package/lib/dtls/src/handshake/const.js +10 -0
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
- package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
- package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/ids.js +11 -0
- package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/unique.js +19 -0
- package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
- package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
- package/lib/dtls/src/handshake/random.d.ts +14 -0
- package/lib/dtls/src/handshake/random.js +24 -0
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/handshake/validation.d.ts +26 -0
- package/lib/dtls/src/handshake/validation.js +32 -0
- package/lib/dtls/src/handshake/validation.js.map +1 -0
- package/lib/dtls/src/index.d.ts +8 -1
- package/lib/dtls/src/index.js +125 -44
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/internal.d.ts +7 -0
- package/lib/dtls/src/internal.js +57 -0
- package/lib/dtls/src/internal.js.map +1 -0
- package/lib/dtls/src/peer.d.ts +49 -0
- package/lib/dtls/src/peer.js +54 -0
- package/lib/dtls/src/peer.js.map +1 -0
- package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
- package/lib/dtls/src/record/antiReplayWindow.js +119 -0
- package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
- package/lib/dtls/src/record/const.d.ts +15 -0
- package/lib/dtls/src/record/const.js +15 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +0 -2
- package/lib/dtls/src/record/message/fragment.js +36 -17
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
- package/lib/dtls/src/record/message/reassembler.js +249 -0
- package/lib/dtls/src/record/message/reassembler.js.map +1 -0
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +58 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
- package/lib/dtls/src/record/v1_3/header.js +95 -0
- package/lib/dtls/src/record/v1_3/header.js.map +1 -0
- package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
- package/lib/dtls/src/record/v1_3/record.js +370 -0
- package/lib/dtls/src/record/v1_3/record.js.map +1 -0
- package/lib/dtls/src/retransmission.d.ts +26 -0
- package/lib/dtls/src/retransmission.js +39 -0
- package/lib/dtls/src/retransmission.js.map +1 -0
- package/lib/dtls/src/server.d.ts +38 -0
- package/lib/dtls/src/server.js +382 -17
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +487 -11
- package/lib/dtls/src/socket.js +1359 -70
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/version.d.ts +89 -0
- package/lib/dtls/src/version.js +204 -0
- package/lib/dtls/src/version.js.map +1 -0
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +126 -0
- package/lib/ice/src/consent.js +470 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -0
- package/lib/ice/src/dns/lookup.js +130 -3
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +9 -0
- package/lib/ice/src/exceptions.js +14 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/failover.d.ts +270 -0
- package/lib/ice/src/failover.js +674 -0
- package/lib/ice/src/failover.js.map +1 -0
- package/lib/ice/src/gatheringError.d.ts +28 -0
- package/lib/ice/src/gatheringError.js +17 -0
- package/lib/ice/src/gatheringError.js.map +1 -0
- package/lib/ice/src/ice.d.ts +486 -78
- package/lib/ice/src/ice.js +2415 -1129
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +404 -14
- package/lib/ice/src/iceBase.js +251 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +3 -0
- package/lib/ice/src/index.js +5 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/datagram.d.ts +37 -0
- package/lib/ice/src/internal/datagram.js +45 -0
- package/lib/ice/src/internal/datagram.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +28 -0
- package/lib/ice/src/internal/hostInterfaces.js +89 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/internal/sped-bind.d.ts +44 -0
- package/lib/ice/src/internal/sped-bind.js +53 -0
- package/lib/ice/src/internal/sped-bind.js.map +1 -0
- package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
- package/lib/ice/src/internal/sped-binding-cache.js +102 -0
- package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
- package/lib/ice/src/internal/sped.d.ts +15 -0
- package/lib/ice/src/internal/sped.js +62 -0
- package/lib/ice/src/internal/sped.js.map +1 -0
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionController.d.ts +111 -0
- package/lib/ice/src/nomination/selectionController.js +172 -0
- package/lib/ice/src/nomination/selectionController.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +178 -0
- package/lib/ice/src/nomination/selectionReplacement.js +429 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
- package/lib/ice/src/sped/draft00/codec.js +59 -0
- package/lib/ice/src/sped/draft00/codec.js.map +1 -0
- package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
- package/lib/ice/src/sped/draft00/constants.js +18 -0
- package/lib/ice/src/sped/draft00/constants.js.map +1 -0
- package/lib/ice/src/sped/draft00/index.d.ts +6 -0
- package/lib/ice/src/sped/draft00/index.js +26 -0
- package/lib/ice/src/sped/draft00/index.js.map +1 -0
- package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
- package/lib/ice/src/sped/draft00/mtu.js +96 -0
- package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
- package/lib/ice/src/sped/draft00/session.d.ts +86 -0
- package/lib/ice/src/sped/draft00/session.js +353 -0
- package/lib/ice/src/sped/draft00/session.js.map +1 -0
- package/lib/ice/src/sped/draft00/types.d.ts +16 -0
- package/lib/ice/src/sped/draft00/types.js +3 -0
- package/lib/ice/src/sped/draft00/types.js.map +1 -0
- package/lib/ice/src/sped/runtime.d.ts +188 -0
- package/lib/ice/src/sped/runtime.js +643 -0
- package/lib/ice/src/sped/runtime.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +38 -2
- package/lib/ice/src/stun/protocol.js +107 -21
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
- package/lib/ice/src/stun/rawAttributeValue.js +6 -0
- package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -1
- package/lib/ice/src/stun/tcpProtocol.js +21 -9
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +4 -0
- package/lib/ice/src/stun/transaction.js +27 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +23 -4
- package/lib/ice/src/turn/protocol.js +99 -11
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +25 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +13 -0
- package/lib/ice/src/utils.js +13 -0
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +43 -3
- package/lib/ice-server/src/stun/message.js +258 -40
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/index.mjs +47427 -25303
- package/lib/nonstandard/index.mjs +3076 -1318
- package/lib/polyfill/dom.mjs +40430 -18730
- package/lib/polyfill/index.mjs +40333 -18639
- package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
- package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
- package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
- package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
- package/lib/rtp/src/extra/processor/webm.js +6 -2
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
- package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +10 -0
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js +4 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +86 -5
- package/lib/sctp/src/sctp.js +354 -75
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +547 -36
- package/lib/webrtc/src/api/peerConfig.js +187 -26
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +87 -2
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +122 -10
- package/lib/webrtc/src/dataChannel.js +214 -20
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
- package/lib/webrtc/src/media/domEventTarget.js +216 -0
- package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
- package/lib/webrtc/src/media/index.d.ts +2 -0
- package/lib/webrtc/src/media/index.js +1 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +5 -0
- package/lib/webrtc/src/media/parameters.js +10 -0
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +245 -51
- package/lib/webrtc/src/media/router.js +702 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +277 -5
- package/lib/webrtc/src/media/rtpReceiver.js +826 -36
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +8 -1
- package/lib/webrtc/src/media/rtpSender.js +13 -6
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +47 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +95 -11
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +13 -0
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +112 -11
- package/lib/webrtc/src/media/track.js +250 -19
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
- package/lib/webrtc/src/media/trackConstraints.js +141 -0
- package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
- package/lib/webrtc/src/negotiation/internalState.js +0 -11
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +12 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +133 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +57 -5
- package/lib/webrtc/src/negotiationTransaction.js +134 -10
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +106 -11
- package/lib/webrtc/src/peerConnection.js +370 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +2 -1
- package/lib/webrtc/src/polyfill/api.js +3 -3
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
- package/lib/webrtc/src/polyfill/dom.js +15 -0
- package/lib/webrtc/src/polyfill/dom.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +8 -3
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.d.ts +1 -1
- package/lib/webrtc/src/polyfill/index.js +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.d.ts +5 -1
- package/lib/webrtc/src/polyfill/install.js +4 -2
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
- package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
- package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +31 -18
- package/lib/webrtc/src/sctpManager.js +162 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +107 -2
- package/lib/webrtc/src/sdp.js +223 -17
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +101 -10
- package/lib/webrtc/src/sdpManager.js +236 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +49 -3
- package/lib/webrtc/src/secureTransportManager.js +166 -12
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +87 -6
- package/lib/webrtc/src/transceiverManager.js +272 -51
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
- package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
- package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
- package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
- package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
- package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-stats.js +134 -0
- package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
- package/lib/webrtc/src/transport/dtls-types.js +11 -0
- package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
- package/lib/webrtc/src/transport/dtls.d.ts +236 -47
- package/lib/webrtc/src/transport/dtls.js +1198 -441
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +95 -5
- package/lib/webrtc/src/transport/ice.js +323 -21
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +149 -2
- package/lib/webrtc/src/transport/sctp.js +826 -128
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/transport/sped.d.ts +139 -0
- package/lib/webrtc/src/transport/sped.js +757 -0
- package/lib/webrtc/src/transport/sped.js.map +1 -0
- package/lib/webrtc/src/types/util.d.ts +6 -0
- package/lib/webrtc/src/types/util.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +34 -1
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/lib/webrtc/src/webidl.d.ts +15 -0
- package/lib/webrtc/src/webidl.js +34 -0
- package/lib/webrtc/src/webidl.js.map +1 -0
- package/package.json +8 -3
- package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
|
@@ -1,36 +1,114 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.RTCDtlsTransport = exports.RTCError = exports.DTLS_ALERT_SEND_TIMEOUT_MS = exports.DtlsStates = exports.RTCDtlsParameters = exports.RTCDtlsFingerprint = exports.RTCCertificate = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
5
|
const promises_1 = require("timers/promises");
|
|
6
|
+
const internal_1 = require("../../../dtls/src/internal");
|
|
7
|
+
const datagram_1 = require("../../../ice/src/internal/datagram");
|
|
8
|
+
const sped_bind_1 = require("../../../ice/src/internal/sped-bind");
|
|
9
|
+
const src_1 = require("../../../sctp/src");
|
|
6
10
|
const helper_1 = require("../helper");
|
|
7
11
|
const common_1 = require("../imports/common");
|
|
8
12
|
const dtls_1 = require("../imports/dtls");
|
|
9
13
|
const rtp_1 = require("../imports/rtp");
|
|
10
14
|
const stats_1 = require("../media/stats");
|
|
11
15
|
const utils_1 = require("../utils");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const dtls_application_gate_1 = require("./dtls-application-gate");
|
|
17
|
+
const dtls_attempt_1 = require("./dtls-attempt");
|
|
18
|
+
const dtls_certificate_1 = require("./dtls-certificate");
|
|
19
|
+
const dtls_fingerprint_1 = require("./dtls-fingerprint");
|
|
20
|
+
const dtls_ice_transport_1 = require("./dtls-ice-transport");
|
|
21
|
+
const dtls_media_queue_1 = require("./dtls-media-queue");
|
|
22
|
+
const dtls_readiness_1 = require("./dtls-readiness");
|
|
23
|
+
const dtls_sped_handshake_1 = require("./dtls-sped-handshake");
|
|
24
|
+
const dtls_srtp_1 = require("./dtls-srtp");
|
|
25
|
+
const dtls_stats_1 = require("./dtls-stats");
|
|
26
|
+
var dtls_certificate_2 = require("./dtls-certificate");
|
|
27
|
+
Object.defineProperty(exports, "RTCCertificate", { enumerable: true, get: function () { return dtls_certificate_2.RTCCertificate; } });
|
|
28
|
+
Object.defineProperty(exports, "RTCDtlsFingerprint", { enumerable: true, get: function () { return dtls_certificate_2.RTCDtlsFingerprint; } });
|
|
29
|
+
Object.defineProperty(exports, "RTCDtlsParameters", { enumerable: true, get: function () { return dtls_certificate_2.RTCDtlsParameters; } });
|
|
30
|
+
var dtls_types_1 = require("./dtls-types");
|
|
31
|
+
Object.defineProperty(exports, "DtlsStates", { enumerable: true, get: function () { return dtls_types_1.DtlsStates; } });
|
|
32
|
+
/**
|
|
33
|
+
* Upper bound (ms) for waiting until close_notify / a fatal alert has been
|
|
34
|
+
* handed to ICE in {@link RTCDtlsTransport.stop}; it adds directly to the
|
|
35
|
+
* time `RTCPeerConnection.close()` takes.
|
|
36
|
+
*/
|
|
37
|
+
exports.DTLS_ALERT_SEND_TIMEOUT_MS = 100;
|
|
38
|
+
/**
|
|
39
|
+
* Minimal `RTCError` (W3C webrtc-pc §10.1) for the DTLS failures that
|
|
40
|
+
* {@link RTCDtlsTransport} reports with its `error` event.
|
|
41
|
+
*
|
|
42
|
+
* - `"fingerprint-failure"`: the remote certificate matched none of the
|
|
43
|
+
* fingerprints of the remote description. `receivedAlert` / `sentAlert` are
|
|
44
|
+
* null, as the spec defines them only for `"dtls-failure"`, although werift
|
|
45
|
+
* still sends a fatal `bad_certificate` (42) to the peer, which in turn
|
|
46
|
+
* reports `"dtls-failure"` with `receivedAlert: 42`.
|
|
47
|
+
* - `"dtls-failure"`: any other DTLS failure, e.g. a fatal alert received
|
|
48
|
+
* (`receivedAlert`) or sent (`sentAlert`).
|
|
49
|
+
*/
|
|
50
|
+
class RTCError extends Error {
|
|
51
|
+
constructor(init, message) {
|
|
52
|
+
super(message);
|
|
53
|
+
Object.defineProperty(this, "errorDetail", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* `"dtls-failure"` only: the fatal alert description received from the
|
|
61
|
+
* peer, otherwise null.
|
|
62
|
+
*/
|
|
63
|
+
Object.defineProperty(this, "receivedAlert", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* `"dtls-failure"` only: the fatal alert description sent to the peer,
|
|
71
|
+
* otherwise null.
|
|
72
|
+
*/
|
|
73
|
+
Object.defineProperty(this, "sentAlert", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
this.name = "OperationError";
|
|
80
|
+
this.errorDetail = init.errorDetail;
|
|
81
|
+
this.receivedAlert = init.receivedAlert ?? null;
|
|
82
|
+
this.sentAlert = init.sentAlert ?? null;
|
|
22
83
|
}
|
|
23
84
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
default:
|
|
31
|
-
return;
|
|
85
|
+
exports.RTCError = RTCError;
|
|
86
|
+
const log = (0, rtp_1.debug)("werift:packages/webrtc/src/transport/dtls.ts");
|
|
87
|
+
class FingerprintMismatchError extends Error {
|
|
88
|
+
constructor() {
|
|
89
|
+
super("remote certificate fingerprint mismatch");
|
|
90
|
+
this.name = "FingerprintMismatchError";
|
|
32
91
|
}
|
|
33
92
|
}
|
|
93
|
+
const certificateVerificationError = (reason) => reason instanceof FingerprintMismatchError
|
|
94
|
+
? new RTCError({ errorDetail: "fingerprint-failure" }, reason.message)
|
|
95
|
+
: new RTCError({ errorDetail: "dtls-failure", sentAlert: dtls_1.AlertDesc.BadCertificate }, String(reason));
|
|
96
|
+
// DTLS over an RTCIceTransport, with the WebRTC rules on top: nothing from
|
|
97
|
+
// the peer (application data, RTP, RTCP) reaches upper layers before its
|
|
98
|
+
// certificate matches the SDP fingerprint.
|
|
99
|
+
//
|
|
100
|
+
// The transport's state is split by concern, each part owning the fields
|
|
101
|
+
// that change together:
|
|
102
|
+
// - TransportAttempts (dtls-attempt.ts): which handshake / authentication
|
|
103
|
+
// attempt owns the continuations (an ICE restart starts a new one);
|
|
104
|
+
// - TransportReadiness (dtls-readiness.ts): write-ready / peer-authenticated
|
|
105
|
+
// / handshake-complete and the handshake timing;
|
|
106
|
+
// - SrtpAccess (dtls-srtp.ts): SRTP keys and the read / write permissions;
|
|
107
|
+
// - InboundApplicationGate (dtls-application-gate.ts) / PreAuthMediaQueue
|
|
108
|
+
// (dtls-media-queue.ts): application data and media held until
|
|
109
|
+
// authentication;
|
|
110
|
+
// - runSpedHandshake (dtls-sped-handshake.ts): the SPED carrier and runtime
|
|
111
|
+
// when PeerConfig.sped is enabled.
|
|
34
112
|
class RTCDtlsTransport {
|
|
35
113
|
constructor(config, iceTransport, localCertificate, srtpProfiles = []) {
|
|
36
114
|
Object.defineProperty(this, "config", {
|
|
@@ -57,11 +135,28 @@ class RTCDtlsTransport {
|
|
|
57
135
|
writable: true,
|
|
58
136
|
value: void 0
|
|
59
137
|
});
|
|
138
|
+
/**
|
|
139
|
+
* @internal The TWCC feedback generator the receivers on this transport
|
|
140
|
+
* share, see `acquireTransportReceiverTWCC`.
|
|
141
|
+
*/
|
|
142
|
+
Object.defineProperty(this, "sharedReceiverTWCC", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true,
|
|
145
|
+
writable: true,
|
|
146
|
+
value: void 0
|
|
147
|
+
});
|
|
148
|
+
/** @internal Set from PeerConfig.sped; not a public RTCDtlsTransport option. */
|
|
149
|
+
Object.defineProperty(this, "sped", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: false
|
|
154
|
+
});
|
|
60
155
|
Object.defineProperty(this, "id", {
|
|
61
156
|
enumerable: true,
|
|
62
157
|
configurable: true,
|
|
63
158
|
writable: true,
|
|
64
|
-
value: (0,
|
|
159
|
+
value: (0, crypto_1.randomUUID)().toString()
|
|
65
160
|
});
|
|
66
161
|
Object.defineProperty(this, "state", {
|
|
67
162
|
enumerable: true,
|
|
@@ -69,17 +164,31 @@ class RTCDtlsTransport {
|
|
|
69
164
|
writable: true,
|
|
70
165
|
value: "new"
|
|
71
166
|
});
|
|
72
|
-
Object.defineProperty(this, "
|
|
167
|
+
Object.defineProperty(this, "_role", {
|
|
73
168
|
enumerable: true,
|
|
74
169
|
configurable: true,
|
|
75
170
|
writable: true,
|
|
76
171
|
value: "auto"
|
|
77
172
|
});
|
|
173
|
+
/**
|
|
174
|
+
* Fires synchronously whenever {@link RTCDtlsTransport.role} changes (a
|
|
175
|
+
* local or remote answer / pranswer, or `start()` resolving `auto`).
|
|
176
|
+
* @see tests/issue/815.test.ts "issue 815: data channel stream IDs follow the DTLS role"
|
|
177
|
+
* @see tests/issue/815.test.ts "the DTLS start resolving auto assigns the IDs of the role it took"
|
|
178
|
+
*/
|
|
179
|
+
Object.defineProperty(this, "onRoleChange", {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
configurable: true,
|
|
182
|
+
writable: true,
|
|
183
|
+
value: new common_1.Event()
|
|
184
|
+
});
|
|
78
185
|
/**
|
|
79
186
|
* Internal: the ICE role when the handshake started. werift sets the ICE role at
|
|
80
187
|
* every offer / answer, so an SCTP association that starts later on this
|
|
81
|
-
* transport takes its client / server side from here, as both peers
|
|
82
|
-
* on it when they started DTLS.
|
|
188
|
+
* transport takes its INIT client / server side from here, as both peers
|
|
189
|
+
* agreed on it when they started DTLS. Data channel stream IDs follow
|
|
190
|
+
* {@link RTCDtlsTransport.role} instead.
|
|
191
|
+
* @see tests/issue/815.test.ts "#815 report: reversed ICE / DTLS roles with channels from both ends do not collide"
|
|
83
192
|
*/
|
|
84
193
|
Object.defineProperty(this, "iceRoleAtStart", {
|
|
85
194
|
enumerable: true,
|
|
@@ -160,6 +269,97 @@ class RTCDtlsTransport {
|
|
|
160
269
|
writable: true,
|
|
161
270
|
value: void 0
|
|
162
271
|
});
|
|
272
|
+
Object.defineProperty(this, "lastError", {
|
|
273
|
+
enumerable: true,
|
|
274
|
+
configurable: true,
|
|
275
|
+
writable: true,
|
|
276
|
+
value: void 0
|
|
277
|
+
});
|
|
278
|
+
Object.defineProperty(this, "startPromise", {
|
|
279
|
+
enumerable: true,
|
|
280
|
+
configurable: true,
|
|
281
|
+
writable: true,
|
|
282
|
+
value: void 0
|
|
283
|
+
});
|
|
284
|
+
Object.defineProperty(this, "settleStart", {
|
|
285
|
+
enumerable: true,
|
|
286
|
+
configurable: true,
|
|
287
|
+
writable: true,
|
|
288
|
+
value: void 0
|
|
289
|
+
});
|
|
290
|
+
/** @internal Notifies SCTP that its pre-authenticated early start was revoked. */
|
|
291
|
+
Object.defineProperty(this, "onEarlyApplicationSendRevoked", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
configurable: true,
|
|
294
|
+
writable: true,
|
|
295
|
+
value: new common_1.Event()
|
|
296
|
+
});
|
|
297
|
+
/** @internal Cancels pre-established associations owned by an old attempt. */
|
|
298
|
+
Object.defineProperty(this, "onEarlyApplicationAttemptCancelled", {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
configurable: true,
|
|
301
|
+
writable: true,
|
|
302
|
+
value: new common_1.Event()
|
|
303
|
+
});
|
|
304
|
+
Object.defineProperty(this, "attempts", {
|
|
305
|
+
enumerable: true,
|
|
306
|
+
configurable: true,
|
|
307
|
+
writable: true,
|
|
308
|
+
value: new dtls_attempt_1.TransportAttempts()
|
|
309
|
+
});
|
|
310
|
+
Object.defineProperty(this, "readiness", {
|
|
311
|
+
enumerable: true,
|
|
312
|
+
configurable: true,
|
|
313
|
+
writable: true,
|
|
314
|
+
value: void 0
|
|
315
|
+
});
|
|
316
|
+
Object.defineProperty(this, "srtpAccess", {
|
|
317
|
+
enumerable: true,
|
|
318
|
+
configurable: true,
|
|
319
|
+
writable: true,
|
|
320
|
+
value: new dtls_srtp_1.SrtpAccess()
|
|
321
|
+
});
|
|
322
|
+
Object.defineProperty(this, "applicationGate", {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
configurable: true,
|
|
325
|
+
writable: true,
|
|
326
|
+
value: void 0
|
|
327
|
+
});
|
|
328
|
+
Object.defineProperty(this, "mediaQueue", {
|
|
329
|
+
enumerable: true,
|
|
330
|
+
configurable: true,
|
|
331
|
+
writable: true,
|
|
332
|
+
value: void 0
|
|
333
|
+
});
|
|
334
|
+
/**
|
|
335
|
+
* WARP early server output was withdrawn for this attempt (SPED abort,
|
|
336
|
+
* direct DTLS fallback); a new attempt allows it again.
|
|
337
|
+
*/
|
|
338
|
+
Object.defineProperty(this, "earlyModeDisabled", {
|
|
339
|
+
enumerable: true,
|
|
340
|
+
configurable: true,
|
|
341
|
+
writable: true,
|
|
342
|
+
value: false
|
|
343
|
+
});
|
|
344
|
+
/** Application data or media left before peer authentication (stats). */
|
|
345
|
+
Object.defineProperty(this, "earlyServerSendUsed", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
configurable: true,
|
|
348
|
+
writable: true,
|
|
349
|
+
value: false
|
|
350
|
+
});
|
|
351
|
+
Object.defineProperty(this, "spedTransport", {
|
|
352
|
+
enumerable: true,
|
|
353
|
+
configurable: true,
|
|
354
|
+
writable: true,
|
|
355
|
+
value: void 0
|
|
356
|
+
});
|
|
357
|
+
Object.defineProperty(this, "iceDatagramSubscription", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
configurable: true,
|
|
360
|
+
writable: true,
|
|
361
|
+
value: void 0
|
|
362
|
+
});
|
|
163
363
|
Object.defineProperty(this, "onStateChange", {
|
|
164
364
|
enumerable: true,
|
|
165
365
|
configurable: true,
|
|
@@ -201,6 +401,25 @@ class RTCDtlsTransport {
|
|
|
201
401
|
writable: true,
|
|
202
402
|
value: void 0
|
|
203
403
|
});
|
|
404
|
+
/**
|
|
405
|
+
* Fires once when the transport becomes `failed`:
|
|
406
|
+
* - the remote certificate matched none of the remote fingerprints:
|
|
407
|
+
* `errorDetail: "fingerprint-failure"` (`receivedAlert` / `sentAlert`
|
|
408
|
+
* null; a fatal `bad_certificate` is still sent to the peer);
|
|
409
|
+
* - a fatal alert received from the peer, or sent by this side (e.g.
|
|
410
|
+
* `bad_certificate` for a certificate it could not verify for another
|
|
411
|
+
* reason), and other DTLS errors: `errorDetail: "dtls-failure"` with
|
|
412
|
+
* `receivedAlert` / `sentAlert`.
|
|
413
|
+
*
|
|
414
|
+
* A close_notify (`closed`) does not fire it. Also delivered as
|
|
415
|
+
* `addEventListener("error", ...)`.
|
|
416
|
+
*/
|
|
417
|
+
Object.defineProperty(this, "onerror", {
|
|
418
|
+
enumerable: true,
|
|
419
|
+
configurable: true,
|
|
420
|
+
writable: true,
|
|
421
|
+
value: void 0
|
|
422
|
+
});
|
|
204
423
|
Object.defineProperty(this, "remoteParameters", {
|
|
205
424
|
enumerable: true,
|
|
206
425
|
configurable: true,
|
|
@@ -234,13 +453,16 @@ class RTCDtlsTransport {
|
|
|
234
453
|
configurable: true,
|
|
235
454
|
writable: true,
|
|
236
455
|
value: async (data) => {
|
|
237
|
-
if (this.
|
|
238
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
456
|
+
if (this.dropForDebug("outbound"))
|
|
239
457
|
return;
|
|
240
|
-
}
|
|
241
458
|
if (!this.dtls) {
|
|
242
459
|
throw new Error("dtls not established");
|
|
243
460
|
}
|
|
461
|
+
if (!this.readiness.peerAuthenticated &&
|
|
462
|
+
!this.isEarlyServerOutboundReady()) {
|
|
463
|
+
throw new src_1.SCTPSendPermissionRevokedError("DTLS peer is not authenticated");
|
|
464
|
+
}
|
|
465
|
+
this.noteEarlyServerSend();
|
|
244
466
|
await this.dtls.send(data);
|
|
245
467
|
}
|
|
246
468
|
});
|
|
@@ -250,26 +472,97 @@ class RTCDtlsTransport {
|
|
|
250
472
|
writable: true,
|
|
251
473
|
value: void 0
|
|
252
474
|
});
|
|
253
|
-
this.config = config;
|
|
254
475
|
this.iceTransport = iceTransport;
|
|
255
476
|
this.localCertificate = localCertificate;
|
|
256
477
|
this.srtpProfiles = srtpProfiles;
|
|
478
|
+
// Keep the transport-local policy independent from the caller's mutable
|
|
479
|
+
// PeerConfig object. setConfiguration() updates this copy explicitly.
|
|
480
|
+
this.config = {
|
|
481
|
+
...config,
|
|
482
|
+
warp: config.warp ? { ...config.warp } : undefined,
|
|
483
|
+
};
|
|
257
484
|
this.localCertificate ?? (this.localCertificate = RTCDtlsTransport.localCertificate);
|
|
485
|
+
this.readiness = new dtls_readiness_1.TransportReadiness({
|
|
486
|
+
onAttemptChanged: this.attempts.onChanged,
|
|
487
|
+
onStateChange: this.onStateChange,
|
|
488
|
+
isTerminated: () => this.isTerminated(),
|
|
489
|
+
lastError: () => this.lastError,
|
|
490
|
+
});
|
|
491
|
+
this.applicationGate = new dtls_application_gate_1.InboundApplicationGate((data) => this.dataReceiver?.(data));
|
|
492
|
+
this.mediaQueue = new dtls_media_queue_1.PreAuthMediaQueue(this.bufferEarlyMedia);
|
|
493
|
+
// start() までの到着も落とさないよう、ICE datagram 購読は生成直後に開始
|
|
494
|
+
// する。認証前の到着は gate / mediaQueue 側で保持し、上位へは出さない。
|
|
495
|
+
const ice = this.iceTransport.connection;
|
|
496
|
+
this.iceDatagramSubscription = (0, datagram_1.connectionDatagramEvent)(ice).subscribe((ctx) => this.onIceDatagram(ctx));
|
|
497
|
+
}
|
|
498
|
+
/** WARP: the DTLS server may send before the peer is authenticated. */
|
|
499
|
+
get allowsEarlyServerData() {
|
|
500
|
+
return this.config.warp?.allowEarlyServerData === true;
|
|
501
|
+
}
|
|
502
|
+
/** WARP: keep (instead of drop) media that arrives before authentication. */
|
|
503
|
+
get bufferEarlyMedia() {
|
|
504
|
+
return this.config.warp?.earlyMediaPolicy === "buffer";
|
|
505
|
+
}
|
|
506
|
+
get liveIceGeneration() {
|
|
507
|
+
return this.iceTransport.connection.generation;
|
|
508
|
+
}
|
|
509
|
+
get isFinalState() {
|
|
510
|
+
return this.state === "closed" || this.state === "failed";
|
|
511
|
+
}
|
|
512
|
+
/** @internal Update the live WARP policy without leaving a stale snapshot. */
|
|
513
|
+
updateWarpConfig(warp) {
|
|
514
|
+
const previousAllowEarlyServerData = this.allowsEarlyServerData;
|
|
515
|
+
const previousPolicy = this.config.warp?.earlyMediaPolicy ?? "drop";
|
|
516
|
+
const nextWarp = {
|
|
517
|
+
allowEarlyServerData: warp?.allowEarlyServerData === true,
|
|
518
|
+
earlyMediaPolicy: warp?.earlyMediaPolicy ?? "drop",
|
|
519
|
+
sendBeforeNomination: warp?.sendBeforeNomination === true,
|
|
520
|
+
};
|
|
521
|
+
this.config.warp = nextWarp;
|
|
522
|
+
this.spedTransport?.setEarlyApplicationSendEnabled(nextWarp.allowEarlyServerData);
|
|
523
|
+
this.spedTransport?.setSendBeforeNomination(nextWarp.sendBeforeNomination);
|
|
524
|
+
// Early server send exists only on SPED transports; never revoke (and so
|
|
525
|
+
// never cancel an SCTP start) on the default non-SPED path.
|
|
526
|
+
if (this.sped &&
|
|
527
|
+
previousAllowEarlyServerData &&
|
|
528
|
+
!nextWarp.allowEarlyServerData) {
|
|
529
|
+
this.onEarlyApplicationSendRevoked.execute();
|
|
530
|
+
}
|
|
531
|
+
if (previousPolicy !== nextWarp.earlyMediaPolicy) {
|
|
532
|
+
// A policy change invalidates protected media accumulated under the old
|
|
533
|
+
// policy; the old retention timer is disposed with its queue.
|
|
534
|
+
this.mediaQueue.renew(this.bufferEarlyMedia);
|
|
535
|
+
}
|
|
536
|
+
// A live policy change can happen after DTLS 1.3 write-ready. Re-run the
|
|
537
|
+
// same key-install edge used by markWriteReady so enabling early outbound
|
|
538
|
+
// cannot leave permissions true while SRTP remains unavailable.
|
|
539
|
+
this.ensureEarlySrtpKeys();
|
|
540
|
+
this.updateSrtpPermissions();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* The DTLS role: `auto` until a description or the handshake start decides
|
|
544
|
+
* it. Data channel stream IDs follow it (client even, server odd).
|
|
545
|
+
* @see tests/issue/815.test.ts "issue 815: data channel stream IDs follow the DTLS role"
|
|
546
|
+
*/
|
|
547
|
+
get role() {
|
|
548
|
+
return this._role;
|
|
549
|
+
}
|
|
550
|
+
set role(role) {
|
|
551
|
+
if (role === this._role)
|
|
552
|
+
return;
|
|
553
|
+
this._role = role;
|
|
554
|
+
this.onRoleChange.executeIsolated((error) => log("onRoleChange listener failed", error), role);
|
|
258
555
|
}
|
|
259
556
|
get localParameters() {
|
|
260
|
-
return new RTCDtlsParameters(this.localCertificate ? this.localCertificate.getFingerprints() : [], this.role);
|
|
557
|
+
return new dtls_certificate_1.RTCDtlsParameters(this.localCertificate ? this.localCertificate.getFingerprints() : [], this.role);
|
|
261
558
|
}
|
|
262
559
|
/**
|
|
263
560
|
* Generates a new self-signed certificate (ECDSA P-256 / SHA-256) on every call.
|
|
264
|
-
* Used by an RTCPeerConnection created with `certificateScope: "
|
|
561
|
+
* Used by an RTCPeerConnection created with `certificateScope: "standard"`
|
|
265
562
|
* when `RTCConfiguration.certificates` is not given.
|
|
266
563
|
*/
|
|
267
564
|
static async generateCertificate() {
|
|
268
|
-
|
|
269
|
-
signature: dtls_1.SignatureAlgorithm.ecdsa_3,
|
|
270
|
-
hash: dtls_1.HashAlgorithm.sha256_4,
|
|
271
|
-
}, dtls_1.NamedCurveAlgorithm.secp256r1_23);
|
|
272
|
-
return new RTCCertificate(keyPem, certPem, signatureHash);
|
|
565
|
+
return (0, dtls_certificate_1.createSelfSignedCertificate)();
|
|
273
566
|
}
|
|
274
567
|
/**
|
|
275
568
|
* Returns the default certificate cached for the whole process
|
|
@@ -286,17 +579,56 @@ class RTCDtlsTransport {
|
|
|
286
579
|
return this.localCertificatePromise;
|
|
287
580
|
}
|
|
288
581
|
setRemoteParams(remoteParameters) {
|
|
289
|
-
|
|
582
|
+
// A new remote SDP supersedes the previous authentication assertion.
|
|
583
|
+
// Keep alternatives advertised by this SDP, but never let an old
|
|
584
|
+
// fingerprint remain valid across an ICE restart / re-negotiation.
|
|
585
|
+
const fingerprints = (0, dtls_fingerprint_1.deduplicateFingerprints)(remoteParameters.fingerprints);
|
|
290
586
|
const role = remoteParameters.role === "auto" && this.remoteParameters?.role
|
|
291
587
|
? this.remoteParameters.role
|
|
292
588
|
: remoteParameters.role;
|
|
293
|
-
this.remoteParameters = new RTCDtlsParameters(fingerprints, role);
|
|
589
|
+
this.remoteParameters = new dtls_certificate_1.RTCDtlsParameters(fingerprints, role);
|
|
590
|
+
// 接続済み transport に新 fingerprint が来たら現 association の証明書で
|
|
591
|
+
// 再検証する。不一致は旧 SDP に基づく認証状態の残留を許さず失敗させる。
|
|
592
|
+
if (this.readiness.peerAuthenticated && !this.isTerminated()) {
|
|
593
|
+
try {
|
|
594
|
+
this.verifyRemoteCertificateFingerprint();
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
this.failAuthenticatedTransport(toError(error));
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* 認証済み association の事後失敗処理。fingerprint 不一致の再検証など、
|
|
603
|
+
* handshake 完了後に認証が崩れた場合に状態・gate・queue を確実に落とす。
|
|
604
|
+
*/
|
|
605
|
+
failAuthenticatedTransport(error) {
|
|
606
|
+
this.readiness.revokePeerAuthentication();
|
|
607
|
+
this.lastError = error;
|
|
608
|
+
this.fail(error);
|
|
609
|
+
this.srtpAccess.revoke();
|
|
610
|
+
this.releasePreAuthData();
|
|
611
|
+
this.abortSpedSession();
|
|
612
|
+
this.dtls?.close();
|
|
294
613
|
}
|
|
295
614
|
/** Internal: whether a description gave this transport the peer's DTLS parameters. */
|
|
296
615
|
get hasRemoteParameters() {
|
|
297
616
|
return (this.remoteParameters?.fingerprints.length ?? 0) > 0;
|
|
298
617
|
}
|
|
299
618
|
async start() {
|
|
619
|
+
if (this.state === "connected") {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (this.state === "closed") {
|
|
623
|
+
throw new Error("RTCDtlsTransport is closed");
|
|
624
|
+
}
|
|
625
|
+
if (this.state === "failed") {
|
|
626
|
+
throw this.lastError ?? new Error("dtls failed");
|
|
627
|
+
}
|
|
628
|
+
if (this.startPromise) {
|
|
629
|
+
await this.startPromise;
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
300
632
|
if (this.state !== "new") {
|
|
301
633
|
throw new Error("state must be new");
|
|
302
634
|
}
|
|
@@ -314,198 +646,705 @@ class RTCDtlsTransport {
|
|
|
314
646
|
}
|
|
315
647
|
}
|
|
316
648
|
this.setState("connecting");
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
649
|
+
// A connecting listener may have stopped the transport synchronously.
|
|
650
|
+
if (this.isTerminated())
|
|
651
|
+
return;
|
|
652
|
+
this.srtpStarted = true;
|
|
653
|
+
this.startPromise = new Promise((resolve, reject) => {
|
|
654
|
+
let settled = false;
|
|
655
|
+
const settle = (error) => {
|
|
656
|
+
if (settled)
|
|
657
|
+
return;
|
|
658
|
+
settled = true;
|
|
659
|
+
this.settleStart = undefined;
|
|
660
|
+
if (error === undefined)
|
|
661
|
+
resolve();
|
|
662
|
+
else
|
|
663
|
+
reject(error);
|
|
664
|
+
};
|
|
665
|
+
this.settleStart = () => settle();
|
|
666
|
+
void this.completeHandshake().then(() => settle(), (error) => settle(error));
|
|
667
|
+
});
|
|
668
|
+
await this.startPromise;
|
|
669
|
+
}
|
|
670
|
+
/** @internal */
|
|
671
|
+
async waitForWriteReady() {
|
|
672
|
+
if (this.readiness.writeReady)
|
|
673
|
+
return;
|
|
674
|
+
if (!this.dtls)
|
|
675
|
+
await Promise.resolve();
|
|
676
|
+
if (!this.dtls)
|
|
677
|
+
throw new Error("DTLS handshake has not started");
|
|
678
|
+
const attempt = this.attempts.current;
|
|
679
|
+
await this.dtls.waitForWriteReady();
|
|
680
|
+
// The lower socket can finish an old carrier generation after ICE restart.
|
|
681
|
+
// That completion may never re-grant upper-layer permission: only the
|
|
682
|
+
// current attempt's handshake path may call markWriteReady().
|
|
683
|
+
if (attempt && this.isCurrentAttempt(attempt)) {
|
|
684
|
+
this.markWriteReady(attempt);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
await this.readiness.waitFor("writeReady");
|
|
688
|
+
}
|
|
689
|
+
/** @internal */
|
|
690
|
+
isEarlyServerWriteAllowed() {
|
|
691
|
+
return this.isEarlyServerOutboundReady();
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Single permission boundary for server 0.5-RTT application/media output.
|
|
695
|
+
* Public RTCDtlsTransport instances are deliberately not WARP transports;
|
|
696
|
+
* the marker is installed only by SecureTransportManager for PeerConfig.sped.
|
|
697
|
+
*/
|
|
698
|
+
isEarlyServerOutboundReady() {
|
|
699
|
+
const attempt = this.attempts.current;
|
|
700
|
+
return (this.sped &&
|
|
701
|
+
this.role === "server" &&
|
|
702
|
+
this.allowsEarlyServerData &&
|
|
703
|
+
!this.earlyModeDisabled &&
|
|
704
|
+
this.readiness.writeReady &&
|
|
705
|
+
this.dtls?.isDtls13 === true &&
|
|
706
|
+
attempt !== undefined &&
|
|
707
|
+
this.isCurrentAttempt(attempt));
|
|
708
|
+
}
|
|
709
|
+
/** @internal */
|
|
710
|
+
waitForPeerAuthenticated() {
|
|
711
|
+
return this.readiness.waitFor("peerAuthenticated");
|
|
712
|
+
}
|
|
713
|
+
/** @internal */
|
|
714
|
+
waitForHandshakeComplete() {
|
|
715
|
+
return this.readiness.waitFor("handshakeComplete");
|
|
716
|
+
}
|
|
717
|
+
/** @internal Rebind an in-flight direct handshake to the new ICE generation. */
|
|
718
|
+
handleIceRestart() {
|
|
719
|
+
this.syncAttemptToIceGeneration();
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* answerer 側の ICE restart は DTLS への明示通知なしに generation だけが
|
|
723
|
+
* 進む。offerer の明示 restart と datagram 受信時・handshake 待機中の
|
|
724
|
+
* drift 検出を同じ処理にまとめ、旧 attempt の継続を無効化する。
|
|
725
|
+
*/
|
|
726
|
+
syncAttemptToIceGeneration() {
|
|
727
|
+
const current = this.attempts.current;
|
|
728
|
+
// start() 前にも authenticated media は mediaQueue に到着し得る。
|
|
729
|
+
// attempt 未発行のまま ICE restart された場合も、旧世代の queue と
|
|
730
|
+
// retention timer を新世代へ持ち越さない。
|
|
731
|
+
if (!current) {
|
|
732
|
+
this.mediaQueue.renew(this.bufferEarlyMedia);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
if (this.sped)
|
|
736
|
+
return;
|
|
737
|
+
const generation = this.liveIceGeneration;
|
|
738
|
+
if (generation === current.iceGeneration)
|
|
739
|
+
return;
|
|
740
|
+
// ここに来るのは SPED でない transport だけで、early 送信は SPED 専用
|
|
741
|
+
// (isEarlyServerOutboundReady) なので early attempt は存在しない。
|
|
742
|
+
// onEarlyApplicationAttemptCancelled を発火すると、確立前の通常 SCTP
|
|
743
|
+
// association まで cancelStart で閉じてしまうため発火しない。
|
|
744
|
+
if (this.state === "connected") {
|
|
745
|
+
// 認証済み association は維持し、新 generation へ attempt を付け替える。
|
|
746
|
+
this.rebindConnectedAttempt(this.attempts.begin(generation));
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (this.state !== "connecting")
|
|
750
|
+
return;
|
|
751
|
+
this.restartConnectingAttempt(generation);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* An ICE restart replaced the generation of a handshake that is still
|
|
755
|
+
* connecting. The cryptographic association continues as a new attempt:
|
|
756
|
+
* continuations captured by the previous generation fail the identity
|
|
757
|
+
* check, and the pre-authentication state starts over for the new one.
|
|
758
|
+
*/
|
|
759
|
+
restartConnectingAttempt(generation) {
|
|
760
|
+
// A restart never mutates an in-flight attempt; the owning
|
|
761
|
+
// completeHandshake loop adopts this new immutable token.
|
|
762
|
+
this.attempts.begin(generation);
|
|
763
|
+
// 新 attempt 用に gate を開き直す (旧 drain 残余は呼び出し側が破棄する)。
|
|
764
|
+
this.applicationGate.restartForNewAttempt();
|
|
765
|
+
this.mediaQueue.renew(this.bufferEarlyMedia);
|
|
766
|
+
this.dtls?.clearEarlyDataBuffer();
|
|
767
|
+
this.earlyModeDisabled = false;
|
|
768
|
+
this.readiness.restartAttempt();
|
|
769
|
+
this.srtpAccess.revoke();
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* SPED: the session restarted for `generation` (ICE restart, or a reset in
|
|
773
|
+
* the same generation). The early attempt is cancelled; a connected
|
|
774
|
+
* association moves to a new attempt, a connecting one starts over.
|
|
775
|
+
*/
|
|
776
|
+
resetSpedGeneration(generation) {
|
|
777
|
+
this.onEarlyApplicationAttemptCancelled.execute();
|
|
778
|
+
this.mediaQueue.renew(this.bufferEarlyMedia);
|
|
779
|
+
this.spedTransport?.setEarlyApplicationSendEnabled(this.allowsEarlyServerData);
|
|
780
|
+
this.dtls?.clearEarlyDataBuffer();
|
|
781
|
+
const current = this.attempts.current;
|
|
782
|
+
if (this.state === "connected" &&
|
|
783
|
+
current &&
|
|
784
|
+
current.iceGeneration !== generation) {
|
|
785
|
+
// SPED owns the generation reset callback; connected associations
|
|
786
|
+
// still need to rebind upper readiness waiters to the new attempt.
|
|
787
|
+
this.rebindConnectedAttempt(this.attempts.begin(generation));
|
|
788
|
+
}
|
|
789
|
+
if (this.state === "connecting" && this.attempts.current) {
|
|
790
|
+
this.restartConnectingAttempt(generation);
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
this.applicationGate.discardPending();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* SPED: early application data of the current attempt is abandoned (SPED
|
|
798
|
+
* session abort, direct DTLS fallback). Early server output stays off until
|
|
799
|
+
* a new attempt; `revoke` names the SRTP permissions withdrawn now.
|
|
800
|
+
*/
|
|
801
|
+
abandonEarlyApplication(revoke) {
|
|
802
|
+
this.onEarlyApplicationAttemptCancelled.execute();
|
|
803
|
+
this.earlyModeDisabled = true;
|
|
804
|
+
this.spedTransport?.setEarlyApplicationSendEnabled(false);
|
|
805
|
+
if (revoke === "write")
|
|
806
|
+
this.srtpAccess.revokeWrite();
|
|
807
|
+
else
|
|
808
|
+
this.srtpAccess.revoke();
|
|
809
|
+
this.applicationGate.discardPending();
|
|
810
|
+
this.mediaQueue.discard();
|
|
811
|
+
this.dtls?.clearEarlyDataBuffer();
|
|
812
|
+
}
|
|
813
|
+
async completeHandshake() {
|
|
814
|
+
let attempt = this.attempts.begin(this.liveIceGeneration);
|
|
815
|
+
this.readiness.startHandshake();
|
|
816
|
+
const sped = this.sped;
|
|
817
|
+
const addressValidation = sped
|
|
818
|
+
? "ice-authenticated"
|
|
819
|
+
: this.config.helloRetryRequest
|
|
820
|
+
? "dtls-cookie"
|
|
821
|
+
: "ice-authenticated";
|
|
822
|
+
if (sped)
|
|
823
|
+
await this.startWithSped(addressValidation);
|
|
824
|
+
else
|
|
825
|
+
await this.startSerial(addressValidation);
|
|
826
|
+
// A fatal alert raced with the end of the handshake.
|
|
827
|
+
// (Narrowed by the checks above, the state may have changed meanwhile.)
|
|
828
|
+
const state = this.state;
|
|
829
|
+
if (state === "failed")
|
|
830
|
+
throw new Error("dtls transport failed");
|
|
831
|
+
// stop() raced with the end of the handshake: closed stays.
|
|
832
|
+
if (state === "closed")
|
|
833
|
+
return;
|
|
834
|
+
// An ICE restart can retain the cryptographic association while changing
|
|
835
|
+
// its carrier generation. Every authentication/drain phase is therefore
|
|
836
|
+
// owned by an immutable attempt. If a callback restarts the ICE
|
|
837
|
+
// generation, abandon only the old phase and run the phase again for the
|
|
838
|
+
// new attempt before allowing start() to resolve.
|
|
839
|
+
while (true) {
|
|
840
|
+
// answerer 側の restart では generation drift をここで吸収し、旧 attempt
|
|
841
|
+
// での無限待機を防ぐ (SPED は runtime 側が所有するため対象外)。
|
|
842
|
+
this.syncAttemptToIceGeneration();
|
|
843
|
+
if (!this.isCurrentAttempt(attempt)) {
|
|
844
|
+
if (this.isTerminated())
|
|
845
|
+
return;
|
|
846
|
+
const current = this.attempts.current;
|
|
847
|
+
if (!current)
|
|
848
|
+
return;
|
|
849
|
+
attempt = current;
|
|
850
|
+
continue;
|
|
328
851
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
852
|
+
await this.dtls?.waitForPeerHandshakeAuthenticated();
|
|
853
|
+
if (!this.isCurrentAttempt(attempt))
|
|
854
|
+
continue;
|
|
855
|
+
if (this.dtls?.readiness.writeReady)
|
|
856
|
+
this.markWriteReady(attempt);
|
|
857
|
+
try {
|
|
858
|
+
this.verifyRemoteCertificateFingerprint();
|
|
859
|
+
}
|
|
860
|
+
catch (error) {
|
|
861
|
+
this.failAuthenticatedTransport(toError(error));
|
|
862
|
+
throw error;
|
|
863
|
+
}
|
|
864
|
+
if (!this.isCurrentAttempt(attempt))
|
|
865
|
+
continue;
|
|
866
|
+
if (this.state !== "connecting")
|
|
867
|
+
return;
|
|
868
|
+
this.readiness.authenticatePeer();
|
|
869
|
+
if (this.srtpProfiles.length > 0) {
|
|
870
|
+
this.installSrtpKeys();
|
|
871
|
+
this.updateSrtpPermissions();
|
|
872
|
+
this.drainMediaBuffer(attempt);
|
|
873
|
+
// drain 中の close/restart では認証確定へ進まず、新 attempt で
|
|
874
|
+
// readiness と保留データの処理をやり直す。
|
|
875
|
+
if (!this.isCurrentAttempt(attempt))
|
|
876
|
+
continue;
|
|
877
|
+
if (this.state !== "connecting")
|
|
878
|
+
return;
|
|
338
879
|
}
|
|
339
|
-
this.
|
|
340
|
-
|
|
341
|
-
|
|
880
|
+
this.applicationGate.authenticate(() => this.isCurrentAttempt(attempt) && this.state === "connecting", () => this.isTerminated());
|
|
881
|
+
// deliver callback 内の restart は start() を成功扱いにせず、次の
|
|
882
|
+
// attempt が同じ association の認証完了処理を引き継ぐ。
|
|
883
|
+
if (!this.isCurrentAttempt(attempt))
|
|
884
|
+
continue;
|
|
885
|
+
if (this.state !== "connecting")
|
|
886
|
+
return;
|
|
887
|
+
this.setState("connected");
|
|
888
|
+
// state callback 内の restart/close で attempt が変わり得るため、通知直前に再検証する。
|
|
889
|
+
if (!this.isCurrentAttempt(attempt)) {
|
|
890
|
+
if (this.isTerminated())
|
|
891
|
+
return;
|
|
892
|
+
// connected association の restart は rebindConnectedAttempt() が
|
|
893
|
+
// readiness waiter と DTLS 完了待機を新 attempt へ引き継いだ。
|
|
894
|
+
if (this.attempts.current) {
|
|
895
|
+
this.bindHandshakeCompletion(this.attempts.current);
|
|
342
896
|
return;
|
|
343
897
|
}
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
this.
|
|
347
|
-
|
|
348
|
-
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
if (this.isTerminated())
|
|
901
|
+
return;
|
|
902
|
+
this.readiness.announcePeerAuthenticated();
|
|
903
|
+
this.bindHandshakeCompletion(attempt);
|
|
904
|
+
log("dtls connected");
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
isCurrentAttempt(attempt) {
|
|
909
|
+
if (this.isTerminated())
|
|
910
|
+
return false;
|
|
911
|
+
return this.attempts.isCurrent(attempt, this.liveIceGeneration);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Keep a connected association's readiness waiters attached after ICE
|
|
915
|
+
* restart. The cryptographic association remains valid, so the readiness
|
|
916
|
+
* latch is preserved; only callbacks that captured the old attempt need a
|
|
917
|
+
* new identity-bound continuation.
|
|
918
|
+
*/
|
|
919
|
+
rebindConnectedAttempt(attempt) {
|
|
920
|
+
if (!this.isCurrentAttempt(attempt) || this.isTerminated())
|
|
921
|
+
return;
|
|
922
|
+
// SPED abort invalidates both SRTP permissions. A connected association
|
|
923
|
+
// remains cryptographically authenticated across ICE restart, so the new
|
|
924
|
+
// attempt must explicitly re-evaluate those permissions after the path is
|
|
925
|
+
// rebound instead of leaving media permanently disabled.
|
|
926
|
+
this.updateSrtpPermissions();
|
|
927
|
+
this.bindHandshakeCompletion(attempt);
|
|
928
|
+
// Do not re-fire onPeerAuthenticated/onHandshakeComplete here: those are
|
|
929
|
+
// one-shot notifications. Re-evaluate only waiters registered before the
|
|
930
|
+
// restart, which otherwise have no event edge after their attempt drifted.
|
|
931
|
+
}
|
|
932
|
+
/** Attach the lower DTLS completion latch to the current transport attempt. */
|
|
933
|
+
bindHandshakeCompletion(attempt) {
|
|
934
|
+
if (this.readiness.handshakeComplete)
|
|
935
|
+
return;
|
|
936
|
+
const dtls = this.dtls;
|
|
937
|
+
if (!dtls || !this.attempts.claimHandshakeWait(attempt))
|
|
938
|
+
return;
|
|
939
|
+
if (dtls.readiness.handshakeComplete) {
|
|
940
|
+
this.markHandshakeComplete(attempt);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
void dtls.waitForHandshakeComplete().then(() => this.markHandshakeComplete(attempt), () => {
|
|
944
|
+
// Terminal state is surfaced by the DTLS socket state bridge.
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
markHandshakeComplete(attempt) {
|
|
948
|
+
if (!this.isCurrentAttempt(attempt) || this.isTerminated())
|
|
949
|
+
return;
|
|
950
|
+
this.readiness.reachHandshakeComplete();
|
|
951
|
+
}
|
|
952
|
+
markWriteReady(attempt) {
|
|
953
|
+
const current = attempt ?? this.attempts.current;
|
|
954
|
+
if (!current || !this.isCurrentAttempt(current))
|
|
955
|
+
return;
|
|
956
|
+
this.readiness.reachWriteReady(() => {
|
|
957
|
+
this.spedTransport?.markApplicationWriteReady();
|
|
958
|
+
this.ensureEarlySrtpKeys();
|
|
959
|
+
this.updateSrtpPermissions();
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
ensureEarlySrtpKeys() {
|
|
963
|
+
if (this.srtpProfiles.length > 0 && this.isEarlyServerOutboundReady()) {
|
|
964
|
+
this.installSrtpKeys();
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
/** Options every DTLS socket of this transport shares. */
|
|
968
|
+
dtlsSocketOptions(addressValidation) {
|
|
969
|
+
return {
|
|
970
|
+
cert: this.localCertificate?.certPem,
|
|
971
|
+
key: this.localCertificate?.privateKey,
|
|
972
|
+
signatureHash: this.localCertificate?.signatureHash,
|
|
973
|
+
srtpProfiles: this.srtpProfiles,
|
|
974
|
+
extendedMasterSecret: true,
|
|
975
|
+
// The association owns version selection. SPED carries the 1.3
|
|
976
|
+
// candidate while a negotiated 1.2 candidate commits to direct DTLS.
|
|
977
|
+
protocolVersions: this.config.protocolVersions,
|
|
978
|
+
peerIdentityMode: "authenticated-single-peer",
|
|
979
|
+
handshakeValidation: this.config.handshakeValidation,
|
|
980
|
+
addressValidation,
|
|
981
|
+
verifyRemoteCertificate: (certificate) => {
|
|
982
|
+
try {
|
|
983
|
+
(0, dtls_fingerprint_1.verifyRemoteCertificateFingerprint)(this.remoteParameters?.fingerprints, certificate);
|
|
984
|
+
return true;
|
|
985
|
+
}
|
|
986
|
+
catch (error) {
|
|
987
|
+
const reason = error instanceof Error &&
|
|
988
|
+
error.message === "remote certificate fingerprint mismatch"
|
|
989
|
+
? new FingerprintMismatchError()
|
|
990
|
+
: error;
|
|
991
|
+
this.lastError = toError(reason);
|
|
992
|
+
throw reason;
|
|
349
993
|
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
994
|
+
},
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
async startSerial(addressValidation) {
|
|
998
|
+
await new Promise(async (resolve, reject) => {
|
|
999
|
+
const options = {
|
|
1000
|
+
...this.dtlsSocketOptions(addressValidation),
|
|
1001
|
+
transport: (0, dtls_ice_transport_1.createIceTransport)(this.iceTransport.connection),
|
|
1002
|
+
};
|
|
1003
|
+
this.dtls =
|
|
1004
|
+
this.role === "server"
|
|
1005
|
+
? new dtls_1.DtlsServer({ ...options, certificateRequest: true })
|
|
1006
|
+
: new dtls_1.DtlsClient(options);
|
|
1007
|
+
this.bindDtlsSocketEvents(resolve, reject);
|
|
357
1008
|
if (this.dtls instanceof dtls_1.DtlsClient) {
|
|
358
1009
|
await (0, promises_1.setTimeout)(100);
|
|
359
|
-
this.dtls.connect().catch((error) =>
|
|
360
|
-
this.setState("failed");
|
|
361
|
-
log("dtls connect failed", error);
|
|
362
|
-
f(error);
|
|
363
|
-
});
|
|
1010
|
+
this.dtls.connect().catch((error) => this.failStart(error, reject));
|
|
364
1011
|
}
|
|
365
1012
|
});
|
|
366
|
-
try {
|
|
367
|
-
this.verifyRemoteCertificateFingerprint();
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
this.setState("failed");
|
|
371
|
-
this.dtls?.close();
|
|
372
|
-
throw error;
|
|
373
|
-
}
|
|
374
|
-
if (this.srtpProfiles.length > 0) {
|
|
375
|
-
this.startSrtp();
|
|
376
|
-
}
|
|
377
|
-
this.setState("connected");
|
|
378
|
-
log("dtls connected");
|
|
379
1013
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
this.
|
|
383
|
-
|
|
1014
|
+
startWithSped(addressValidation) {
|
|
1015
|
+
return (0, dtls_sped_handshake_1.runSpedHandshake)({
|
|
1016
|
+
connection: this.iceTransport.connection,
|
|
1017
|
+
allowsEarlyServerData: () => this.allowsEarlyServerData,
|
|
1018
|
+
sendsBeforeNomination: () => this.config.warp?.sendBeforeNomination === true,
|
|
1019
|
+
state: () => this.state,
|
|
1020
|
+
adoptSpedTransport: (transport) => {
|
|
1021
|
+
this.spedTransport = transport;
|
|
1022
|
+
},
|
|
1023
|
+
createSocket: (transport, carrier, resolve, reject) => {
|
|
1024
|
+
const options = {
|
|
1025
|
+
...this.dtlsSocketOptions(addressValidation),
|
|
1026
|
+
transport,
|
|
1027
|
+
handshakeCarrier: carrier,
|
|
1028
|
+
};
|
|
1029
|
+
const socket = this.role === "server"
|
|
1030
|
+
? (0, internal_1.createDtlsServerInternal)({ ...options, certificateRequest: true })
|
|
1031
|
+
: (0, internal_1.createDtlsClientInternal)(options);
|
|
1032
|
+
this.dtls = socket;
|
|
1033
|
+
this.bindDtlsSocketEvents(resolve, reject);
|
|
1034
|
+
return socket;
|
|
1035
|
+
},
|
|
1036
|
+
failStart: (error, reject) => this.failStart(error, reject),
|
|
1037
|
+
resetForGeneration: (generation) => this.resetSpedGeneration(generation),
|
|
1038
|
+
abandonEarlyApplication: (revoke) => this.abandonEarlyApplication(revoke),
|
|
1039
|
+
endEarlyServerMode: () => {
|
|
1040
|
+
this.earlyModeDisabled = true;
|
|
1041
|
+
},
|
|
1042
|
+
markWriteReady: () => this.markWriteReady(),
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
/** connect() of the DTLS client failed: the start fails with `error`. */
|
|
1046
|
+
failStart(error, reject) {
|
|
1047
|
+
// stop()/close() 後の遅延失敗で closed を failed へ上書きしない。
|
|
1048
|
+
if (this.isTerminated())
|
|
1049
|
+
return;
|
|
1050
|
+
// ICE restart で attempt を付け替えても DTLS socket は同じで、
|
|
1051
|
+
// connect() をやり直す経路はない。失敗を捨てると start() が
|
|
1052
|
+
// 終わらないため、attempt に関係なく現在の失敗として扱う。
|
|
1053
|
+
this.lastError = error;
|
|
1054
|
+
this.fail(error);
|
|
1055
|
+
this.abortSpedSession();
|
|
1056
|
+
log("dtls connect failed", error);
|
|
1057
|
+
reject(error);
|
|
1058
|
+
}
|
|
1059
|
+
bindDtlsSocketEvents(resolve, reject) {
|
|
1060
|
+
if (!this.dtls) {
|
|
1061
|
+
return;
|
|
384
1062
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
1063
|
+
// engine RX queue の stale 実行を世代で遮断する (ICE restart race)。
|
|
1064
|
+
// 対象は世代ごとに注入される SPED carrier だけ。非 SPED では restart を
|
|
1065
|
+
// またいでも同じ DTLS association の datagram なので遮断しない (warp と同じ)。
|
|
1066
|
+
if (this.sped) {
|
|
1067
|
+
this.dtls.setExpectedRxGeneration(() => this.liveIceGeneration);
|
|
388
1068
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
1069
|
+
this.dtls.onData.subscribe((buf) => {
|
|
1070
|
+
if (this.dropForDebug("inbound"))
|
|
1071
|
+
return;
|
|
1072
|
+
// restart 後に engine queue から遅延配送された旧世代 data は gate に入れない。
|
|
1073
|
+
if (!this.isFreshApplicationReceive())
|
|
1074
|
+
return;
|
|
1075
|
+
this.applicationGate.receive(buf);
|
|
1076
|
+
});
|
|
1077
|
+
// close_notify from the peer, also during the handshake: closed (with
|
|
1078
|
+
// statechange, the peer caused it; W3C RTCDtlsTransportState "closed").
|
|
1079
|
+
// close_notify is not a fatal alert, so neither failed nor an error
|
|
1080
|
+
// event. closed / failed are final.
|
|
1081
|
+
this.dtls.onClose.subscribe(() => {
|
|
1082
|
+
// 全 close 経路で送信許可を解除し、close 後の SRTP/SRTCP 送信を防ぐ。
|
|
1083
|
+
this.srtpAccess.revoke();
|
|
1084
|
+
if (this.isTerminated())
|
|
1085
|
+
return;
|
|
1086
|
+
if (this.state === "connecting") {
|
|
1087
|
+
this.abortSpedSession();
|
|
1088
|
+
this.discardUnauthenticatedData();
|
|
393
1089
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
1090
|
+
if (this.state !== "failed") {
|
|
1091
|
+
log("dtls closed by the peer");
|
|
1092
|
+
this.setState("closed");
|
|
397
1093
|
}
|
|
398
|
-
|
|
1094
|
+
// Settle start() on a close: it returns with the transport closed
|
|
1095
|
+
// (transport activation then ends a connection attempt that never
|
|
1096
|
+
// connected as failed). A failure rejects through onError instead.
|
|
1097
|
+
resolve();
|
|
399
1098
|
});
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
1099
|
+
this.dtls.onConnect.once(resolve);
|
|
1100
|
+
// Reflect the core's write readiness (DTLS 1.3 server: after its own
|
|
1101
|
+
// Finished) as soon as it exists, independent of SCTP. Media-only early
|
|
1102
|
+
// server sends depend on it; the permission itself is still decided by
|
|
1103
|
+
// updateSrtpPermissions() (peer authentication or the early-server policy).
|
|
1104
|
+
this.waitForWriteReady().catch((error) => {
|
|
1105
|
+
// close / failure is reported by the handshake path above.
|
|
1106
|
+
log("core write readiness not reached", error);
|
|
1107
|
+
});
|
|
1108
|
+
this.dtls.onError.once((error) => {
|
|
1109
|
+
if (!(this.lastError instanceof FingerprintMismatchError)) {
|
|
1110
|
+
this.lastError =
|
|
1111
|
+
error instanceof dtls_1.DtlsAlertError &&
|
|
1112
|
+
error.source === "local" &&
|
|
1113
|
+
error.reason instanceof Error
|
|
1114
|
+
? error.reason
|
|
1115
|
+
: error;
|
|
408
1116
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
1117
|
+
this.fail(error);
|
|
1118
|
+
this.abortSpedSession();
|
|
1119
|
+
this.discardUnauthenticatedData();
|
|
1120
|
+
log("dtls failed", error);
|
|
1121
|
+
// A local certificate rejection rejects with the verifier's error
|
|
1122
|
+
// (e.g. "remote certificate fingerprint mismatch").
|
|
1123
|
+
reject(error instanceof dtls_1.DtlsAlertError &&
|
|
1124
|
+
error.source === "local" &&
|
|
1125
|
+
error.reason instanceof Error
|
|
1126
|
+
? error.reason
|
|
1127
|
+
: error);
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
/** closed / failed are terminal and produce one isolated DTLS error event. */
|
|
1131
|
+
fail(error) {
|
|
1132
|
+
if (this.isTerminated())
|
|
1133
|
+
return;
|
|
1134
|
+
this.srtpAccess.revoke();
|
|
1135
|
+
this.setState("failed");
|
|
1136
|
+
const rtcError = error instanceof RTCError
|
|
1137
|
+
? error
|
|
1138
|
+
: error instanceof dtls_1.DtlsAlertError &&
|
|
1139
|
+
error.source === "local" &&
|
|
1140
|
+
error.reason instanceof FingerprintMismatchError
|
|
1141
|
+
? certificateVerificationError(error.reason)
|
|
1142
|
+
: error instanceof dtls_1.DtlsAlertError
|
|
1143
|
+
? new RTCError({
|
|
1144
|
+
errorDetail: "dtls-failure",
|
|
1145
|
+
...(error.source === "remote"
|
|
1146
|
+
? { receivedAlert: error.description }
|
|
1147
|
+
: { sentAlert: error.description }),
|
|
1148
|
+
}, error.message)
|
|
1149
|
+
: new RTCError({ errorDetail: "dtls-failure" }, String(error));
|
|
1150
|
+
const event = {
|
|
1151
|
+
type: "error",
|
|
1152
|
+
error: rtcError,
|
|
1153
|
+
};
|
|
1154
|
+
this.notifySafely("onerror", () => this.onerror?.(event));
|
|
1155
|
+
this.events.emitIsolated((listenerError) => log("error listener failed", listenerError), "error", event);
|
|
1156
|
+
}
|
|
1157
|
+
abortSpedSession() {
|
|
1158
|
+
const ice = this.iceTransport.connection;
|
|
1159
|
+
(0, sped_bind_1.getConnectionSpedRuntime)(ice)?.abort();
|
|
1160
|
+
}
|
|
1161
|
+
/** Drop every application / media record held for authentication, for good. */
|
|
1162
|
+
releasePreAuthData() {
|
|
1163
|
+
this.applicationGate.abort();
|
|
1164
|
+
this.mediaQueue.close();
|
|
1165
|
+
}
|
|
1166
|
+
/** {@link releasePreAuthData}, unless the peer was already authenticated. */
|
|
1167
|
+
discardUnauthenticatedData() {
|
|
1168
|
+
if (this.readiness.peerAuthenticated)
|
|
1169
|
+
return;
|
|
1170
|
+
this.releasePreAuthData();
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* engine から届いた application data を gate へ入れてよいか判定する。
|
|
1174
|
+
* connecting 中の旧 attempt 由来や close/failed 後の遅延配送を遮断する。
|
|
1175
|
+
* connected 中の answerer restart はここで attempt を付け替えて継続する。
|
|
1176
|
+
*/
|
|
1177
|
+
isFreshApplicationReceive() {
|
|
1178
|
+
if (this.isTerminated())
|
|
1179
|
+
return false;
|
|
1180
|
+
const generation = this.liveIceGeneration;
|
|
1181
|
+
if (this.state === "connected") {
|
|
1182
|
+
this.syncConnectedAttempt();
|
|
1183
|
+
const synced = this.attempts.current;
|
|
1184
|
+
if (!synced)
|
|
1185
|
+
return false;
|
|
1186
|
+
return generation === synced.iceGeneration;
|
|
414
1187
|
}
|
|
1188
|
+
const current = this.attempts.current;
|
|
1189
|
+
if (!current)
|
|
1190
|
+
return true;
|
|
1191
|
+
return generation === current.iceGeneration;
|
|
1192
|
+
}
|
|
1193
|
+
verifyRemoteCertificateFingerprint() {
|
|
1194
|
+
(0, dtls_fingerprint_1.verifyRemoteCertificateFingerprint)(this.remoteParameters?.fingerprints, this.dtls?.remoteCertificate);
|
|
415
1195
|
}
|
|
416
1196
|
updateSrtpSession() {
|
|
1197
|
+
this.installSrtpKeys();
|
|
1198
|
+
}
|
|
1199
|
+
installSrtpKeys() {
|
|
1200
|
+
if (this.srtpAccess.keysInstalled)
|
|
1201
|
+
return;
|
|
417
1202
|
if (!this.dtls)
|
|
418
1203
|
throw new Error();
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
log("selected SRTP Profile", profile);
|
|
424
|
-
const { localKey, localSalt, remoteKey, remoteSalt } = this.dtls.extractSessionKeys((0, rtp_1.keyLength)(profile), (0, rtp_1.saltLength)(profile));
|
|
425
|
-
const config = {
|
|
426
|
-
keys: {
|
|
427
|
-
localMasterKey: localKey,
|
|
428
|
-
localMasterSalt: localSalt,
|
|
429
|
-
remoteMasterKey: remoteKey,
|
|
430
|
-
remoteMasterSalt: remoteSalt,
|
|
431
|
-
},
|
|
432
|
-
profile,
|
|
433
|
-
};
|
|
434
|
-
this.srtp = new rtp_1.SrtpSession(config);
|
|
435
|
-
this.srtcp = new rtp_1.SrtcpSession(config);
|
|
1204
|
+
const { srtp, srtcp } = this.srtpAccess.installKeys(this.dtls);
|
|
1205
|
+
this.srtp = srtp;
|
|
1206
|
+
this.srtcp = srtcp;
|
|
436
1207
|
}
|
|
437
1208
|
startSrtp() {
|
|
438
|
-
if (this.srtpStarted)
|
|
439
|
-
return;
|
|
440
1209
|
this.srtpStarted = true;
|
|
441
|
-
this.
|
|
442
|
-
this.
|
|
443
|
-
|
|
444
|
-
|
|
1210
|
+
this.installSrtpKeys();
|
|
1211
|
+
this.updateSrtpPermissions();
|
|
1212
|
+
}
|
|
1213
|
+
/** Key availability never grants media access by itself. */
|
|
1214
|
+
updateSrtpPermissions() {
|
|
1215
|
+
this.srtpAccess.update({
|
|
1216
|
+
peerAuthenticated: this.readiness.peerAuthenticated,
|
|
1217
|
+
earlyServerWriteAllowed: this.isEarlyServerOutboundReady(),
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* ICE datagram 受信層の media 処理。購読は constructor 時に開始済みのため、
|
|
1222
|
+
* DTLS `start()` 前に届いた early RTP/RTCP もここで保持する。認証前の到着
|
|
1223
|
+
* は encrypted のまま buffer/drop し、復号・配送は fingerprint 認証後だけ。
|
|
1224
|
+
*/
|
|
1225
|
+
onIceDatagram(ctx) {
|
|
1226
|
+
if (this.dropForDebug("inbound"))
|
|
1227
|
+
return;
|
|
1228
|
+
// 旧 generation・close 後・未認証 pair の media は配送も buffer もしない。
|
|
1229
|
+
if (this.isTerminated())
|
|
1230
|
+
return;
|
|
1231
|
+
this.syncConnectedAttempt();
|
|
1232
|
+
const current = this.attempts.current;
|
|
1233
|
+
if (ctx.generation !== this.liveIceGeneration)
|
|
1234
|
+
return;
|
|
1235
|
+
// ICE restart 後も相手が新 pair へ移るまでは、旧世代の選択 pair の media を
|
|
1236
|
+
// 受け付ける (RFC 8445 §9)。DTLS の認証経路には使わない。
|
|
1237
|
+
if (!ctx.fromPreviousSelectedPair) {
|
|
1238
|
+
if (!ctx.authenticated || !ctx.pair)
|
|
445
1239
|
return;
|
|
446
|
-
|
|
447
|
-
if (!(0, rtp_1.isMedia)(data))
|
|
1240
|
+
if (ctx.protocol !== ctx.pair.protocol)
|
|
448
1241
|
return;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
catch (error) {
|
|
487
|
-
if (error instanceof rtp_1.SrtpAuthenticationError) {
|
|
488
|
-
log("dropping invalid SRTP packet", error);
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
throw error;
|
|
492
|
-
}
|
|
493
|
-
let rtp;
|
|
494
|
-
try {
|
|
495
|
-
rtp = rtp_1.RtpPacket.deSerialize(dec);
|
|
496
|
-
}
|
|
497
|
-
catch (error) {
|
|
498
|
-
log("dropping malformed SRTP packet", error);
|
|
1242
|
+
const remote = ctx.pair.remoteAddr;
|
|
1243
|
+
if (ctx.source[0] !== remote[0] || ctx.source[1] !== remote[1])
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const data = ctx.bytes;
|
|
1247
|
+
if (!(0, rtp_1.isMedia)(data))
|
|
1248
|
+
return;
|
|
1249
|
+
this.recordReceived(data.length);
|
|
1250
|
+
if (!this.srtpAccess.canRead) {
|
|
1251
|
+
// handshake 開始前 (attempt 未発行) の pre-auth media は現世代に
|
|
1252
|
+
// 限り buffer し、配送は認証後の drain に委ねる。
|
|
1253
|
+
if (current && !this.isCurrentAttempt(current))
|
|
1254
|
+
return;
|
|
1255
|
+
if (current && ctx.generation !== current.iceGeneration)
|
|
1256
|
+
return;
|
|
1257
|
+
this.mediaQueue.push(data);
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
// 配送は現 attempt のみに限定し、close/restart 後の旧 queue は扱わない。
|
|
1261
|
+
if (!current || !this.isCurrentAttempt(current))
|
|
1262
|
+
return;
|
|
1263
|
+
if (ctx.generation !== current.iceGeneration)
|
|
1264
|
+
return;
|
|
1265
|
+
this.handleMediaPacket(data, current);
|
|
1266
|
+
}
|
|
1267
|
+
handleMediaPacket(data, attempt) {
|
|
1268
|
+
if (!this.canDeliverMedia(attempt))
|
|
1269
|
+
return;
|
|
1270
|
+
if ((0, rtp_1.isRtcp)(data)) {
|
|
1271
|
+
const rtcpPackets = (0, dtls_srtp_1.decryptRtcp)(this.srtcp, data);
|
|
1272
|
+
if (!rtcpPackets)
|
|
1273
|
+
return;
|
|
1274
|
+
for (const rtcp of rtcpPackets) {
|
|
1275
|
+
// 1つの SRTCP datagram に複数 packet が含まれる場合も、先頭の
|
|
1276
|
+
// callback 内の close/restart/fingerprint failure を直ちに反映する。
|
|
1277
|
+
if (!this.canDeliverMedia(attempt))
|
|
499
1278
|
return;
|
|
500
|
-
}
|
|
501
1279
|
try {
|
|
502
|
-
this.
|
|
1280
|
+
this.onRtcp.execute(rtcp);
|
|
503
1281
|
}
|
|
504
1282
|
catch (error) {
|
|
505
|
-
log("
|
|
1283
|
+
log("RTCP error", error);
|
|
506
1284
|
}
|
|
507
1285
|
}
|
|
508
|
-
}
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
const rtp = (0, dtls_srtp_1.decryptRtp)(this.srtp, data);
|
|
1289
|
+
if (!rtp)
|
|
1290
|
+
return;
|
|
1291
|
+
if (!this.canDeliverMedia(attempt))
|
|
1292
|
+
return;
|
|
1293
|
+
try {
|
|
1294
|
+
this.onRtp.execute(rtp);
|
|
1295
|
+
}
|
|
1296
|
+
catch (error) {
|
|
1297
|
+
log("RTP error", error);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
/** Deliver media queued before authentication while `attempt` stays current. */
|
|
1302
|
+
drainMediaBuffer(attempt) {
|
|
1303
|
+
// 各要素配送前と配送後に attempt/state を再検証し、close/restart で中断する。
|
|
1304
|
+
this.mediaQueue.drain((data) => this.handleMediaPacket(data, attempt), () => this.canDeliverMedia(attempt));
|
|
1305
|
+
}
|
|
1306
|
+
canDeliverMedia(attempt) {
|
|
1307
|
+
return (this.srtpAccess.canRead &&
|
|
1308
|
+
!this.isTerminated() &&
|
|
1309
|
+
this.isCurrentAttempt(attempt));
|
|
1310
|
+
}
|
|
1311
|
+
isTerminated() {
|
|
1312
|
+
const state = this.state;
|
|
1313
|
+
return state === "closed" || state === "failed";
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* answerer 側の ICE restart は DTLS への明示通知なしに generation だけが
|
|
1317
|
+
* 進む。認証済み association は維持し、新 generation へ attempt を付け替える。
|
|
1318
|
+
* queue 破棄を伴わないため SPED でも共通に扱える。
|
|
1319
|
+
*/
|
|
1320
|
+
syncConnectedAttempt() {
|
|
1321
|
+
const current = this.attempts.current;
|
|
1322
|
+
if (this.state !== "connected" || !current)
|
|
1323
|
+
return;
|
|
1324
|
+
const generation = this.liveIceGeneration;
|
|
1325
|
+
if (generation !== current.iceGeneration) {
|
|
1326
|
+
this.rebindConnectedAttempt(this.attempts.begin(generation));
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
/** `config.debug` packet loss simulation for `direction`. */
|
|
1330
|
+
dropForDebug(direction) {
|
|
1331
|
+
const loss = direction === "inbound"
|
|
1332
|
+
? this.config.debug?.inboundPacketLoss
|
|
1333
|
+
: this.config.debug?.outboundPacketLoss;
|
|
1334
|
+
return !!loss && loss / 100 < Math.random();
|
|
1335
|
+
}
|
|
1336
|
+
/** Record that output left before the peer was authenticated (stats). */
|
|
1337
|
+
noteEarlyServerSend() {
|
|
1338
|
+
if (!this.readiness.peerAuthenticated)
|
|
1339
|
+
this.earlyServerSendUsed = true;
|
|
1340
|
+
}
|
|
1341
|
+
recordSent(size) {
|
|
1342
|
+
this.bytesSent += size;
|
|
1343
|
+
this.packetsSent++;
|
|
1344
|
+
}
|
|
1345
|
+
recordReceived(size) {
|
|
1346
|
+
this.bytesReceived += size;
|
|
1347
|
+
this.packetsReceived++;
|
|
509
1348
|
}
|
|
510
1349
|
/**
|
|
511
1350
|
* Allocate the next transport-wide sequence at send time.
|
|
@@ -537,19 +1376,30 @@ class RTCDtlsTransport {
|
|
|
537
1376
|
/**
|
|
538
1377
|
* Encrypt RTP and enqueue on ICE, capturing the clock immediately before
|
|
539
1378
|
* the ICE write (RFC 8888). Prefer {@link sendRtp} unless send time is needed.
|
|
1379
|
+
*
|
|
1380
|
+
* Nothing is sent once the transport is `closed` / `failed` (close_notify
|
|
1381
|
+
* or a fatal alert, `stop()`): ICE may still be up, but the DTLS
|
|
1382
|
+
* association that keyed SRTP has ended. The size is then 0.
|
|
540
1383
|
*/
|
|
541
1384
|
async sendRtpWithMeta(payload, header) {
|
|
1385
|
+
if (this.isFinalState) {
|
|
1386
|
+
log("drop RTP on a", this.state, "transport");
|
|
1387
|
+
return { size: 0, sendingAtMs: (0, utils_1.milliTime)() };
|
|
1388
|
+
}
|
|
542
1389
|
try {
|
|
1390
|
+
if (this.isTerminated() || !this.srtpAccess.canWrite) {
|
|
1391
|
+
return { size: 0, sendingAtMs: (0, utils_1.milliTime)() };
|
|
1392
|
+
}
|
|
1393
|
+
this.noteEarlyServerSend();
|
|
543
1394
|
const enc = this.srtp.encrypt(payload, header);
|
|
544
|
-
if (this.
|
|
545
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
1395
|
+
if (this.dropForDebug("outbound")) {
|
|
546
1396
|
return { size: enc.length, sendingAtMs: (0, utils_1.milliTime)() };
|
|
547
1397
|
}
|
|
548
|
-
// Track statistics
|
|
549
|
-
this.bytesSent += enc.length;
|
|
550
|
-
this.packetsSent++;
|
|
551
1398
|
const sendingAtMs = (0, utils_1.milliTime)();
|
|
552
|
-
await this.
|
|
1399
|
+
await this.sendProtectedMedia(enc);
|
|
1400
|
+
// 実際の wire 送信が成功した後だけ統計を更新する。SPED の early
|
|
1401
|
+
// path は authenticated pair 待ちで reject することがある。
|
|
1402
|
+
this.recordSent(enc.length);
|
|
553
1403
|
return { size: enc.length, sendingAtMs };
|
|
554
1404
|
}
|
|
555
1405
|
catch (error) {
|
|
@@ -558,27 +1408,87 @@ class RTCDtlsTransport {
|
|
|
558
1408
|
}
|
|
559
1409
|
}
|
|
560
1410
|
async sendRtcp(packets) {
|
|
1411
|
+
if (this.isTerminated() || !this.srtpAccess.canWrite)
|
|
1412
|
+
return 0;
|
|
1413
|
+
this.noteEarlyServerSend();
|
|
561
1414
|
const payload = Buffer.concat(packets.map((packet) => packet.serialize()));
|
|
562
1415
|
const enc = this.srtcp.encrypt(payload);
|
|
563
|
-
if (this.
|
|
564
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
1416
|
+
if (this.dropForDebug("outbound")) {
|
|
565
1417
|
return enc.length;
|
|
566
1418
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1419
|
+
try {
|
|
1420
|
+
await this.sendProtectedMedia(enc);
|
|
1421
|
+
// 実際の wire 送信が成功した後だけ統計を更新する。
|
|
1422
|
+
this.recordSent(enc.length);
|
|
1423
|
+
return enc.length;
|
|
1424
|
+
}
|
|
1425
|
+
catch (error) {
|
|
1426
|
+
log("failed to send RTCP", error);
|
|
1427
|
+
return 0;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
async sendProtectedMedia(data) {
|
|
1431
|
+
if (this.spedTransport) {
|
|
1432
|
+
// メディア統計は実 wire 送信後に更新するため、nomination/consent
|
|
1433
|
+
// 前はキューが実際に flush されるまで待機する。
|
|
1434
|
+
await this.spedTransport.sendMediaAndWait(data);
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
// Connection.send() intentionally keeps its compatibility no-op contract
|
|
1438
|
+
// when ICE consent is unavailable. Media must not turn that no-op into a
|
|
1439
|
+
// successful SRTP send or a misleading transport statistic.
|
|
1440
|
+
if (!this.iceTransport.connection.canSendApplicationData()) {
|
|
1441
|
+
throw new Error("ICE application path is not ready");
|
|
1442
|
+
}
|
|
1443
|
+
await this.iceTransport.connection.send(data);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Stats-only remote certificate. The DTLS socket throws if the association
|
|
1447
|
+
* is torn down, so skip the getter unless this transport is connected.
|
|
1448
|
+
* Unexpected throws while connected are left to propagate.
|
|
1449
|
+
*/
|
|
1450
|
+
remoteCertificateForStats() {
|
|
1451
|
+
if (!this.dtls || this.state !== "connected") {
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
return this.dtls.remoteCertificate;
|
|
571
1455
|
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Change the state and notify. Each notification is isolated: an
|
|
1458
|
+
* exception thrown by a listener is logged and never interrupts the
|
|
1459
|
+
* caller (stop() cleanup, settling start(), failing the transport).
|
|
1460
|
+
*/
|
|
572
1461
|
setState(state, emitEvent = true) {
|
|
1462
|
+
if (this.isFinalState)
|
|
1463
|
+
return;
|
|
573
1464
|
if (state != this.state) {
|
|
574
1465
|
this.state = state;
|
|
575
|
-
|
|
1466
|
+
// Per subscriber: an application subscriber registered before the
|
|
1467
|
+
// internal ones (SCTP closing its association, connectionState) must
|
|
1468
|
+
// not stop them by throwing.
|
|
1469
|
+
this.onStateChange.executeIsolated((error) => log("onStateChange listener failed", error), state);
|
|
576
1470
|
if (emitEvent) {
|
|
577
|
-
this.onstatechange?.();
|
|
578
|
-
this.events.
|
|
1471
|
+
this.notifySafely("onstatechange", () => this.onstatechange?.());
|
|
1472
|
+
this.events.emitIsolated((error) => log("statechange listener failed", error), "statechange");
|
|
579
1473
|
}
|
|
580
1474
|
}
|
|
581
1475
|
}
|
|
1476
|
+
notifySafely(name, notify) {
|
|
1477
|
+
(0, helper_1.notifySafely)(log, name, notify);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* @internal
|
|
1481
|
+
* The synchronous part of {@link RTCDtlsTransport.stop}: `closed` without
|
|
1482
|
+
* statechange (W3C webrtc-pc `close()`), and a start() still waiting for
|
|
1483
|
+
* the handshake settles. `RTCPeerConnection.close()` calls it before its
|
|
1484
|
+
* first await; the alert and the ICE / socket teardown follow in stop().
|
|
1485
|
+
*/
|
|
1486
|
+
markClosed() {
|
|
1487
|
+
this.setState("closed", false);
|
|
1488
|
+
// A start() still waiting for the handshake returns here; the caller
|
|
1489
|
+
// sees the transport closed (it never connected).
|
|
1490
|
+
this.settleStart?.();
|
|
1491
|
+
}
|
|
582
1492
|
/** Resolves once ICE has stopped; concurrent callers share one stop. */
|
|
583
1493
|
stop() {
|
|
584
1494
|
if (this.stopPromise)
|
|
@@ -592,81 +1502,91 @@ class RTCDtlsTransport {
|
|
|
592
1502
|
settle(this.runStop());
|
|
593
1503
|
return this.stopPromise;
|
|
594
1504
|
}
|
|
1505
|
+
/**
|
|
1506
|
+
* 1. closed, synchronously and without statechange (W3C webrtc-pc
|
|
1507
|
+
* `close()`).
|
|
1508
|
+
* 2. close_notify to the peer (RFC 5246 §7.2.1), encrypted once the
|
|
1509
|
+
* handshake reached epoch 1, plaintext while it is still at epoch 0. It
|
|
1510
|
+
* is awaited for at most {@link DTLS_ALERT_SEND_TIMEOUT_MS}, so a dead
|
|
1511
|
+
* ICE path cannot hold the close. Nothing is sent after a fatal alert,
|
|
1512
|
+
* a received close_notify, or when ICE is already closed / failed.
|
|
1513
|
+
* 3. ICE stops (the alert must reach ICE before it closes).
|
|
1514
|
+
* 4. The DTLS socket closes, so a handshake still in flight stops
|
|
1515
|
+
* retransmitting.
|
|
1516
|
+
*
|
|
1517
|
+
* Steps 3 and 4 and `onStopped` always run, even if an earlier step or a
|
|
1518
|
+
* listener threw, so the underlying transports never outlive stop().
|
|
1519
|
+
*/
|
|
595
1520
|
async runStop() {
|
|
1521
|
+
const dtls = this.dtls;
|
|
596
1522
|
try {
|
|
597
|
-
this.
|
|
598
|
-
|
|
1523
|
+
this.markClosed();
|
|
1524
|
+
if (dtls &&
|
|
1525
|
+
!dtls.terminated &&
|
|
1526
|
+
!["closed", "failed"].includes(this.iceTransport.state)) {
|
|
1527
|
+
await dtls.sendAlert(dtls_1.AlertLevel.warning, dtls_1.AlertDesc.CloseNotify, {
|
|
1528
|
+
timeoutMs: exports.DTLS_ALERT_SEND_TIMEOUT_MS,
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
else if (dtls?.terminated) {
|
|
1532
|
+
await dtls.alertFlushed();
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
catch (error) {
|
|
1536
|
+
log("stop: close_notify step failed", error);
|
|
1537
|
+
}
|
|
1538
|
+
try {
|
|
1539
|
+
// 旧 attempt の callback・drain が再開しないよう ICE 停止前に無効化。
|
|
1540
|
+
this.attempts.invalidate();
|
|
1541
|
+
this.iceDatagramSubscription?.unSubscribe();
|
|
1542
|
+
this.iceDatagramSubscription = undefined;
|
|
1543
|
+
this.srtpAccess.revoke();
|
|
1544
|
+
this.releasePreAuthData();
|
|
599
1545
|
await this.iceTransport.stop();
|
|
600
|
-
// A handshake still in flight stops retransmitting its flight.
|
|
601
|
-
this.dtls?.close();
|
|
602
1546
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
this.onStopped.complete();
|
|
1547
|
+
catch (error) {
|
|
1548
|
+
log("stop: ice stop failed", error);
|
|
606
1549
|
}
|
|
1550
|
+
try {
|
|
1551
|
+
// SPED 購読は ICE 停止後に解除し、close_notify の送信を妨げない。
|
|
1552
|
+
const spedTransport = this.spedTransport;
|
|
1553
|
+
this.spedTransport = undefined;
|
|
1554
|
+
await spedTransport?.close();
|
|
1555
|
+
}
|
|
1556
|
+
catch (error) {
|
|
1557
|
+
log("stop: SPED close failed", error);
|
|
1558
|
+
}
|
|
1559
|
+
try {
|
|
1560
|
+
await dtls?.close();
|
|
1561
|
+
}
|
|
1562
|
+
catch (error) {
|
|
1563
|
+
log("stop: dtls close failed", error);
|
|
1564
|
+
}
|
|
1565
|
+
// Per subscriber: the owner releasing this transport must run.
|
|
1566
|
+
this.onStopped.executeIsolated((error) => log("onStopped listener failed", error));
|
|
1567
|
+
this.notifySafely("onStopped", () => this.onStopped.complete());
|
|
607
1568
|
}
|
|
608
1569
|
async getStats(timestamp = (0, stats_1.getStatsTimestamp)()) {
|
|
609
|
-
const stats =
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
1570
|
+
const { transportId, stats } = (0, dtls_stats_1.buildDtlsTransportStats)({
|
|
1571
|
+
id: this.id,
|
|
1572
|
+
state: this.state,
|
|
1573
|
+
role: this.role,
|
|
1574
|
+
iceTransport: this.iceTransport,
|
|
1575
|
+
dtls: this.dtls,
|
|
1576
|
+
localCertificate: this.localCertificate,
|
|
1577
|
+
remoteCertificate: this.remoteCertificateForStats(),
|
|
1578
|
+
remoteFingerprints: this.remoteParameters?.fingerprints,
|
|
616
1579
|
bytesSent: this.bytesSent,
|
|
617
1580
|
bytesReceived: this.bytesReceived,
|
|
618
1581
|
packetsSent: this.packetsSent,
|
|
619
1582
|
packetsReceived: this.packetsReceived,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
? (0, stats_1.generateStatsId)("candidate-pair", this.iceTransport.connection.nominated.id)
|
|
628
|
-
: undefined,
|
|
629
|
-
localCertificateId: this.localCertificate
|
|
630
|
-
? (0, stats_1.generateStatsId)("certificate", this.id, "local")
|
|
631
|
-
: undefined,
|
|
632
|
-
remoteCertificateId: this.dtls?.remoteCertificate
|
|
633
|
-
? (0, stats_1.generateStatsId)("certificate", this.id, "remote")
|
|
634
|
-
: undefined,
|
|
635
|
-
dtlsRole: this.role === "auto" ? undefined : this.role,
|
|
636
|
-
tlsVersion: formatDtlsVersion(this.dtls?.dtls.version),
|
|
637
|
-
dtlsCipher: this.dtls?.cipher.cipher?.name,
|
|
638
|
-
srtpCipher: formatSrtpCipher(this.dtls?.srtp.srtpProfile),
|
|
639
|
-
iceRestarts: this.iceTransport.iceRestarts,
|
|
640
|
-
};
|
|
641
|
-
stats.push(transportStats);
|
|
642
|
-
// Certificate stats
|
|
643
|
-
if (this.localCertificate) {
|
|
644
|
-
const fingerprints = this.localCertificate.getFingerprints();
|
|
645
|
-
if (fingerprints.length > 0) {
|
|
646
|
-
const certStats = {
|
|
647
|
-
type: "certificate",
|
|
648
|
-
id: (0, stats_1.generateStatsId)("certificate", this.id, "local"),
|
|
649
|
-
timestamp,
|
|
650
|
-
fingerprint: fingerprints[0].value,
|
|
651
|
-
fingerprintAlgorithm: fingerprints[0].algorithm,
|
|
652
|
-
base64Certificate: Buffer.from(this.localCertificate.certPem).toString("base64"),
|
|
653
|
-
};
|
|
654
|
-
stats.push(certStats);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
if (this.remoteParameters &&
|
|
658
|
-
this.remoteParameters.fingerprints.length > 0 &&
|
|
659
|
-
this.dtls?.remoteCertificate) {
|
|
660
|
-
const certStats = {
|
|
661
|
-
type: "certificate",
|
|
662
|
-
id: (0, stats_1.generateStatsId)("certificate", this.id, "remote"),
|
|
663
|
-
timestamp,
|
|
664
|
-
fingerprint: this.remoteParameters.fingerprints[0].value,
|
|
665
|
-
fingerprintAlgorithm: this.remoteParameters.fingerprints[0].algorithm,
|
|
666
|
-
base64Certificate: Buffer.from(this.dtls.remoteCertificate).toString("base64"),
|
|
667
|
-
};
|
|
668
|
-
stats.push(certStats);
|
|
669
|
-
}
|
|
1583
|
+
applicationQueue: this.applicationGate.snapshot(),
|
|
1584
|
+
mediaQueue: this.mediaQueue.snapshot(),
|
|
1585
|
+
handshakeStartedAt: this.readiness.handshakeStartedAt,
|
|
1586
|
+
peerAuthenticatedAt: this.readiness.peerAuthenticatedAt,
|
|
1587
|
+
earlyServerSendUsed: this.earlyServerSendUsed,
|
|
1588
|
+
preNominationSendUsed: this.spedTransport?.preNominationSendUsed ?? false,
|
|
1589
|
+
}, timestamp);
|
|
670
1590
|
// Get ICE stats
|
|
671
1591
|
const iceStats = await this.iceTransport.getStats(timestamp, transportId);
|
|
672
1592
|
stats.push(...iceStats);
|
|
@@ -674,170 +1594,7 @@ class RTCDtlsTransport {
|
|
|
674
1594
|
}
|
|
675
1595
|
}
|
|
676
1596
|
exports.RTCDtlsTransport = RTCDtlsTransport;
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
"connecting",
|
|
680
|
-
"connected",
|
|
681
|
-
"closed",
|
|
682
|
-
"failed",
|
|
683
|
-
];
|
|
684
|
-
class RTCCertificate {
|
|
685
|
-
constructor(privateKeyPem, certPem, signatureHash) {
|
|
686
|
-
Object.defineProperty(this, "certPem", {
|
|
687
|
-
enumerable: true,
|
|
688
|
-
configurable: true,
|
|
689
|
-
writable: true,
|
|
690
|
-
value: void 0
|
|
691
|
-
});
|
|
692
|
-
Object.defineProperty(this, "signatureHash", {
|
|
693
|
-
enumerable: true,
|
|
694
|
-
configurable: true,
|
|
695
|
-
writable: true,
|
|
696
|
-
value: void 0
|
|
697
|
-
});
|
|
698
|
-
Object.defineProperty(this, "publicKey", {
|
|
699
|
-
enumerable: true,
|
|
700
|
-
configurable: true,
|
|
701
|
-
writable: true,
|
|
702
|
-
value: void 0
|
|
703
|
-
});
|
|
704
|
-
Object.defineProperty(this, "privateKey", {
|
|
705
|
-
enumerable: true,
|
|
706
|
-
configurable: true,
|
|
707
|
-
writable: true,
|
|
708
|
-
value: void 0
|
|
709
|
-
});
|
|
710
|
-
this.certPem = certPem;
|
|
711
|
-
this.signatureHash = signatureHash;
|
|
712
|
-
this.certPem = (0, dtls_1.normalizePem)(certPem);
|
|
713
|
-
const cert = new node_crypto_1.X509Certificate(this.certPem);
|
|
714
|
-
this.publicKey = cert.publicKey
|
|
715
|
-
.export({ type: "spki", format: "pem" })
|
|
716
|
-
.toString();
|
|
717
|
-
this.privateKey = (0, node_crypto_1.createPrivateKey)((0, dtls_1.normalizePem)(privateKeyPem))
|
|
718
|
-
.export({ type: "pkcs8", format: "pem" })
|
|
719
|
-
.toString();
|
|
720
|
-
}
|
|
721
|
-
getFingerprints() {
|
|
722
|
-
return [
|
|
723
|
-
new RTCDtlsFingerprint("sha-256", (0, utils_1.fingerprint)(new node_crypto_1.X509Certificate(this.certPem).raw, "sha256")),
|
|
724
|
-
];
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
exports.RTCCertificate = RTCCertificate;
|
|
728
|
-
class RTCDtlsFingerprint {
|
|
729
|
-
constructor(algorithm, value) {
|
|
730
|
-
Object.defineProperty(this, "algorithm", {
|
|
731
|
-
enumerable: true,
|
|
732
|
-
configurable: true,
|
|
733
|
-
writable: true,
|
|
734
|
-
value: void 0
|
|
735
|
-
});
|
|
736
|
-
Object.defineProperty(this, "value", {
|
|
737
|
-
enumerable: true,
|
|
738
|
-
configurable: true,
|
|
739
|
-
writable: true,
|
|
740
|
-
value: void 0
|
|
741
|
-
});
|
|
742
|
-
this.algorithm = algorithm;
|
|
743
|
-
this.value = value;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
exports.RTCDtlsFingerprint = RTCDtlsFingerprint;
|
|
747
|
-
class RTCDtlsParameters {
|
|
748
|
-
constructor(fingerprints = [], role) {
|
|
749
|
-
Object.defineProperty(this, "fingerprints", {
|
|
750
|
-
enumerable: true,
|
|
751
|
-
configurable: true,
|
|
752
|
-
writable: true,
|
|
753
|
-
value: void 0
|
|
754
|
-
});
|
|
755
|
-
Object.defineProperty(this, "role", {
|
|
756
|
-
enumerable: true,
|
|
757
|
-
configurable: true,
|
|
758
|
-
writable: true,
|
|
759
|
-
value: void 0
|
|
760
|
-
});
|
|
761
|
-
this.fingerprints = fingerprints;
|
|
762
|
-
this.role = role;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
exports.RTCDtlsParameters = RTCDtlsParameters;
|
|
766
|
-
const deduplicateFingerprints = (fingerprints) => {
|
|
767
|
-
const seen = new Set();
|
|
768
|
-
return fingerprints.filter(({ algorithm, value }) => {
|
|
769
|
-
const key = `${(0, utils_1.normalizeFingerprintAlgorithm)(algorithm) ?? algorithm.trim().toLowerCase()}:${(0, utils_1.normalizeFingerprintValue)(value)}`;
|
|
770
|
-
if (seen.has(key)) {
|
|
771
|
-
return false;
|
|
772
|
-
}
|
|
773
|
-
seen.add(key);
|
|
774
|
-
return true;
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
|
-
const preferredFingerprintAlgorithms = [
|
|
778
|
-
"sha512",
|
|
779
|
-
"sha384",
|
|
780
|
-
"sha256",
|
|
781
|
-
"sha224",
|
|
782
|
-
"sha1",
|
|
783
|
-
];
|
|
784
|
-
const selectPreferredFingerprintAlgorithm = (fingerprints) => {
|
|
785
|
-
return (preferredFingerprintAlgorithms.find((algorithm) => fingerprints.some(({ normalizedAlgorithm }) => normalizedAlgorithm === algorithm)) ?? fingerprints[0].normalizedAlgorithm);
|
|
786
|
-
};
|
|
787
|
-
class IceTransport {
|
|
788
|
-
constructor(ice) {
|
|
789
|
-
Object.defineProperty(this, "ice", {
|
|
790
|
-
enumerable: true,
|
|
791
|
-
configurable: true,
|
|
792
|
-
writable: true,
|
|
793
|
-
value: void 0
|
|
794
|
-
});
|
|
795
|
-
Object.defineProperty(this, "closed", {
|
|
796
|
-
enumerable: true,
|
|
797
|
-
configurable: true,
|
|
798
|
-
writable: true,
|
|
799
|
-
value: false
|
|
800
|
-
});
|
|
801
|
-
Object.defineProperty(this, "onData", {
|
|
802
|
-
enumerable: true,
|
|
803
|
-
configurable: true,
|
|
804
|
-
writable: true,
|
|
805
|
-
value: () => { }
|
|
806
|
-
});
|
|
807
|
-
Object.defineProperty(this, "type", {
|
|
808
|
-
enumerable: true,
|
|
809
|
-
configurable: true,
|
|
810
|
-
writable: true,
|
|
811
|
-
value: "ice"
|
|
812
|
-
});
|
|
813
|
-
Object.defineProperty(this, "send", {
|
|
814
|
-
enumerable: true,
|
|
815
|
-
configurable: true,
|
|
816
|
-
writable: true,
|
|
817
|
-
value: (data) => {
|
|
818
|
-
return this.ice.send(data);
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
this.ice = ice;
|
|
822
|
-
ice.onData.subscribe((buf) => {
|
|
823
|
-
if ((0, utils_1.isDtls)(buf)) {
|
|
824
|
-
if (this.onData) {
|
|
825
|
-
this.onData(buf);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
get address() {
|
|
831
|
-
return {};
|
|
832
|
-
}
|
|
833
|
-
async close() {
|
|
834
|
-
if (this.closed)
|
|
835
|
-
return;
|
|
836
|
-
this.closed = true;
|
|
837
|
-
// RTCIceTransport.stop() may have closed the agent already.
|
|
838
|
-
if (this.ice.state !== "closed")
|
|
839
|
-
this.ice.close();
|
|
840
|
-
}
|
|
1597
|
+
function toError(error) {
|
|
1598
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
841
1599
|
}
|
|
842
|
-
const createIceTransport = (ice) => new IceTransport(ice);
|
|
843
1600
|
//# sourceMappingURL=dtls.js.map
|