werift 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -2
- package/lib/common/src/transport.d.ts +39 -5
- package/lib/common/src/transport.js +32 -7
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/carrier/direct.d.ts +67 -0
- package/lib/dtls/src/carrier/direct.js +226 -0
- package/lib/dtls/src/carrier/direct.js.map +1 -0
- package/lib/dtls/src/carrier/types.d.ts +81 -0
- package/lib/dtls/src/carrier/types.js +7 -0
- package/lib/dtls/src/carrier/types.js.map +1 -0
- package/lib/dtls/src/cipher/const.d.ts +6 -0
- package/lib/dtls/src/cipher/const.js +13 -2
- package/lib/dtls/src/cipher/const.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +11 -2
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
- package/lib/dtls/src/cipher/tls13/aead.js +128 -0
- package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/signature.js +149 -0
- package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
- package/lib/dtls/src/client.d.ts +253 -0
- package/lib/dtls/src/client.js +1257 -16
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +45 -0
- package/lib/dtls/src/context/dtls.js +114 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +13 -0
- package/lib/dtls/src/context/transport.js +29 -1
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
- package/lib/dtls/src/engine/v1_3/connection.js +680 -0
- package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
- package/lib/dtls/src/engine/v1_3/host.js +11 -0
- package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
- package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
- package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
- package/lib/dtls/src/engine/v1_3/types.js +113 -0
- package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
- package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
- package/lib/dtls/src/flight/client/flight1.js +9 -3
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
- package/lib/dtls/src/flight/client/flight3.js +24 -4
- package/lib/dtls/src/flight/client/flight3.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +13 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +16 -0
- package/lib/dtls/src/flight/flight.js +109 -8
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
- package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
- package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
- package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
- package/lib/dtls/src/flight/server/flight2.js +29 -105
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +14 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +8 -0
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +10 -0
- package/lib/dtls/src/handshake/const.js +10 -0
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
- package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
- package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/ids.js +11 -0
- package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/unique.js +19 -0
- package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
- package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
- package/lib/dtls/src/handshake/random.d.ts +14 -0
- package/lib/dtls/src/handshake/random.js +24 -0
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/handshake/validation.d.ts +26 -0
- package/lib/dtls/src/handshake/validation.js +32 -0
- package/lib/dtls/src/handshake/validation.js.map +1 -0
- package/lib/dtls/src/index.d.ts +6 -1
- package/lib/dtls/src/index.js +116 -44
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/internal.d.ts +7 -0
- package/lib/dtls/src/internal.js +57 -0
- package/lib/dtls/src/internal.js.map +1 -0
- package/lib/dtls/src/peer.d.ts +49 -0
- package/lib/dtls/src/peer.js +54 -0
- package/lib/dtls/src/peer.js.map +1 -0
- package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
- package/lib/dtls/src/record/antiReplayWindow.js +119 -0
- package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
- package/lib/dtls/src/record/const.d.ts +6 -0
- package/lib/dtls/src/record/const.js +6 -0
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +0 -2
- package/lib/dtls/src/record/message/fragment.js +36 -17
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
- package/lib/dtls/src/record/message/reassembler.js +249 -0
- package/lib/dtls/src/record/message/reassembler.js.map +1 -0
- package/lib/dtls/src/record/receive.js +24 -16
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
- package/lib/dtls/src/record/v1_3/header.js +95 -0
- package/lib/dtls/src/record/v1_3/header.js.map +1 -0
- package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
- package/lib/dtls/src/record/v1_3/record.js +370 -0
- package/lib/dtls/src/record/v1_3/record.js.map +1 -0
- package/lib/dtls/src/retransmission.d.ts +26 -0
- package/lib/dtls/src/retransmission.js +39 -0
- package/lib/dtls/src/retransmission.js.map +1 -0
- package/lib/dtls/src/server.d.ts +38 -0
- package/lib/dtls/src/server.js +367 -20
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +379 -35
- package/lib/dtls/src/socket.js +1105 -132
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/version.d.ts +89 -0
- package/lib/dtls/src/version.js +204 -0
- package/lib/dtls/src/version.js.map +1 -0
- package/lib/ice/src/consent.d.ts +78 -1
- package/lib/ice/src/consent.js +236 -24
- package/lib/ice/src/consent.js.map +1 -1
- package/lib/ice/src/dns/lookup.d.ts +10 -0
- package/lib/ice/src/dns/lookup.js +130 -3
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +9 -0
- package/lib/ice/src/exceptions.js +14 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/failover.d.ts +270 -0
- package/lib/ice/src/failover.js +674 -0
- package/lib/ice/src/failover.js.map +1 -0
- package/lib/ice/src/gatheringError.d.ts +28 -0
- package/lib/ice/src/gatheringError.js +17 -0
- package/lib/ice/src/gatheringError.js.map +1 -0
- package/lib/ice/src/ice.d.ts +265 -9
- package/lib/ice/src/ice.js +1624 -236
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +197 -6
- package/lib/ice/src/iceBase.js +157 -7
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +2 -0
- package/lib/ice/src/index.js +4 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/datagram.d.ts +37 -0
- package/lib/ice/src/internal/datagram.js +45 -0
- package/lib/ice/src/internal/datagram.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +13 -2
- package/lib/ice/src/internal/hostInterfaces.js +16 -4
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -1
- package/lib/ice/src/internal/sped-bind.d.ts +44 -0
- package/lib/ice/src/internal/sped-bind.js +53 -0
- package/lib/ice/src/internal/sped-bind.js.map +1 -0
- package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
- package/lib/ice/src/internal/sped-binding-cache.js +102 -0
- package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
- package/lib/ice/src/internal/sped.d.ts +15 -0
- package/lib/ice/src/internal/sped.js +62 -0
- package/lib/ice/src/internal/sped.js.map +1 -0
- package/lib/ice/src/nomination/selectionController.d.ts +111 -0
- package/lib/ice/src/nomination/selectionController.js +172 -0
- package/lib/ice/src/nomination/selectionController.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +40 -0
- package/lib/ice/src/nomination/selectionReplacement.js +65 -7
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -1
- package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
- package/lib/ice/src/sped/draft00/codec.js +59 -0
- package/lib/ice/src/sped/draft00/codec.js.map +1 -0
- package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
- package/lib/ice/src/sped/draft00/constants.js +18 -0
- package/lib/ice/src/sped/draft00/constants.js.map +1 -0
- package/lib/ice/src/sped/draft00/index.d.ts +6 -0
- package/lib/ice/src/sped/draft00/index.js +26 -0
- package/lib/ice/src/sped/draft00/index.js.map +1 -0
- package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
- package/lib/ice/src/sped/draft00/mtu.js +96 -0
- package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
- package/lib/ice/src/sped/draft00/session.d.ts +86 -0
- package/lib/ice/src/sped/draft00/session.js +353 -0
- package/lib/ice/src/sped/draft00/session.js.map +1 -0
- package/lib/ice/src/sped/draft00/types.d.ts +16 -0
- package/lib/ice/src/sped/draft00/types.js +3 -0
- package/lib/ice/src/sped/draft00/types.js.map +1 -0
- package/lib/ice/src/sped/runtime.d.ts +188 -0
- package/lib/ice/src/sped/runtime.js +643 -0
- package/lib/ice/src/sped/runtime.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +29 -0
- package/lib/ice/src/stun/protocol.js +91 -4
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
- package/lib/ice/src/stun/rawAttributeValue.js +6 -0
- package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +1 -0
- package/lib/ice/src/stun/tcpProtocol.js +14 -2
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +4 -0
- package/lib/ice/src/stun/transaction.js +23 -0
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +21 -2
- package/lib/ice/src/turn/protocol.js +93 -8
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +9 -0
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +13 -0
- package/lib/ice/src/utils.js +13 -0
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +15 -2
- package/lib/ice-server/src/stun/message.js +156 -25
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/index.mjs +19568 -3106
- package/lib/nonstandard/index.mjs +2539 -1175
- package/lib/polyfill/dom.mjs +33210 -16872
- package/lib/polyfill/index.mjs +33345 -17013
- package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
- package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
- package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
- package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
- package/lib/rtp/src/extra/processor/webm.js +6 -2
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
- package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +10 -0
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js +4 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +81 -5
- package/lib/sctp/src/sctp.js +273 -28
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +11 -1
- package/lib/webrtc/src/api/compatibilityOptions.js +11 -1
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -1
- package/lib/webrtc/src/api/peerConfig.d.ts +210 -13
- package/lib/webrtc/src/api/peerConfig.js +100 -5
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +10 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +122 -10
- package/lib/webrtc/src/dataChannel.js +214 -20
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
- package/lib/webrtc/src/media/domEventTarget.js +216 -0
- package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
- package/lib/webrtc/src/media/index.d.ts +2 -0
- package/lib/webrtc/src/media/index.js +1 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +5 -0
- package/lib/webrtc/src/media/parameters.js +10 -0
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +6 -0
- package/lib/webrtc/src/media/router.js +39 -1
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +56 -6
- package/lib/webrtc/src/media/rtpReceiver.js +165 -15
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +1 -1
- package/lib/webrtc/src/media/rtpSender.js +4 -3
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +29 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +31 -9
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +13 -0
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +103 -11
- package/lib/webrtc/src/media/track.js +241 -19
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
- package/lib/webrtc/src/media/trackConstraints.js +141 -0
- package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
- package/lib/webrtc/src/negotiation/internalState.js +0 -11
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +4 -0
- package/lib/webrtc/src/negotiation/transportActivation.js +112 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +25 -4
- package/lib/webrtc/src/negotiationTransaction.js +27 -6
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +44 -8
- package/lib/webrtc/src/peerConnection.js +88 -9
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +2 -1
- package/lib/webrtc/src/polyfill/api.js +3 -3
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
- package/lib/webrtc/src/polyfill/dom.js +15 -0
- package/lib/webrtc/src/polyfill/dom.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +6 -2
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.d.ts +1 -1
- package/lib/webrtc/src/polyfill/index.js +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.d.ts +5 -1
- package/lib/webrtc/src/polyfill/install.js +2 -2
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
- package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
- package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +31 -18
- package/lib/webrtc/src/sctpManager.js +158 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +38 -2
- package/lib/webrtc/src/sdp.js +84 -3
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +19 -9
- package/lib/webrtc/src/sdpManager.js +26 -4
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +11 -2
- package/lib/webrtc/src/secureTransportManager.js +84 -5
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +5 -2
- package/lib/webrtc/src/transceiverManager.js +42 -14
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
- package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
- package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
- package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
- package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
- package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-stats.js +134 -0
- package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
- package/lib/webrtc/src/transport/dtls-types.js +11 -0
- package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
- package/lib/webrtc/src/transport/dtls.d.ts +150 -55
- package/lib/webrtc/src/transport/dtls.js +1017 -556
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +35 -2
- package/lib/webrtc/src/transport/ice.js +147 -14
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +126 -2
- package/lib/webrtc/src/transport/sctp.js +747 -134
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/transport/sped.d.ts +139 -0
- package/lib/webrtc/src/transport/sped.js +757 -0
- package/lib/webrtc/src/transport/sped.js.map +1 -0
- package/lib/webrtc/src/types/util.d.ts +6 -0
- package/lib/webrtc/src/types/util.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +1 -1
- package/lib/webrtc/src/webidl.d.ts +15 -0
- package/lib/webrtc/src/webidl.js +34 -0
- package/lib/webrtc/src/webidl.js.map +1 -0
- package/package.json +7 -3
- package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
|
@@ -1,14 +1,34 @@
|
|
|
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");
|
|
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; } });
|
|
12
32
|
/**
|
|
13
33
|
* Upper bound (ms) for waiting until close_notify / a fatal alert has been
|
|
14
34
|
* handed to ICE in {@link RTCDtlsTransport.stop}; it adds directly to the
|
|
@@ -64,42 +84,31 @@ class RTCError extends Error {
|
|
|
64
84
|
}
|
|
65
85
|
exports.RTCError = RTCError;
|
|
66
86
|
const log = (0, rtp_1.debug)("werift:packages/webrtc/src/transport/dtls.ts");
|
|
67
|
-
/**
|
|
68
|
-
* Internal: the remote certificate matched none of the remote fingerprints
|
|
69
|
-
* (reported as `errorDetail: "fingerprint-failure"`). Other verification
|
|
70
|
-
* errors (no certificate, no usable fingerprint) stay `"dtls-failure"`.
|
|
71
|
-
*/
|
|
72
87
|
class FingerprintMismatchError extends Error {
|
|
73
88
|
constructor() {
|
|
74
89
|
super("remote certificate fingerprint mismatch");
|
|
75
90
|
this.name = "FingerprintMismatchError";
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
|
-
/** The RTCError for a failed check of the remote certificate. */
|
|
79
93
|
const certificateVerificationError = (reason) => reason instanceof FingerprintMismatchError
|
|
80
94
|
? new RTCError({ errorDetail: "fingerprint-failure" }, reason.message)
|
|
81
95
|
: new RTCError({ errorDetail: "dtls-failure", sentAlert: dtls_1.AlertDesc.BadCertificate }, String(reason));
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return "AEAD_AES_128_GCM";
|
|
99
|
-
default:
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
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.
|
|
103
112
|
class RTCDtlsTransport {
|
|
104
113
|
constructor(config, iceTransport, localCertificate, srtpProfiles = []) {
|
|
105
114
|
Object.defineProperty(this, "config", {
|
|
@@ -126,11 +135,28 @@ class RTCDtlsTransport {
|
|
|
126
135
|
writable: true,
|
|
127
136
|
value: void 0
|
|
128
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
|
+
});
|
|
129
155
|
Object.defineProperty(this, "id", {
|
|
130
156
|
enumerable: true,
|
|
131
157
|
configurable: true,
|
|
132
158
|
writable: true,
|
|
133
|
-
value: (0,
|
|
159
|
+
value: (0, crypto_1.randomUUID)().toString()
|
|
134
160
|
});
|
|
135
161
|
Object.defineProperty(this, "state", {
|
|
136
162
|
enumerable: true,
|
|
@@ -138,17 +164,31 @@ class RTCDtlsTransport {
|
|
|
138
164
|
writable: true,
|
|
139
165
|
value: "new"
|
|
140
166
|
});
|
|
141
|
-
Object.defineProperty(this, "
|
|
167
|
+
Object.defineProperty(this, "_role", {
|
|
142
168
|
enumerable: true,
|
|
143
169
|
configurable: true,
|
|
144
170
|
writable: true,
|
|
145
171
|
value: "auto"
|
|
146
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
|
+
});
|
|
147
185
|
/**
|
|
148
186
|
* Internal: the ICE role when the handshake started. werift sets the ICE role at
|
|
149
187
|
* every offer / answer, so an SCTP association that starts later on this
|
|
150
|
-
* transport takes its client / server side from here, as both peers
|
|
151
|
-
* 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"
|
|
152
192
|
*/
|
|
153
193
|
Object.defineProperty(this, "iceRoleAtStart", {
|
|
154
194
|
enumerable: true,
|
|
@@ -229,6 +269,97 @@ class RTCDtlsTransport {
|
|
|
229
269
|
writable: true,
|
|
230
270
|
value: void 0
|
|
231
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
|
+
});
|
|
232
363
|
Object.defineProperty(this, "onStateChange", {
|
|
233
364
|
enumerable: true,
|
|
234
365
|
configurable: true,
|
|
@@ -317,25 +448,21 @@ class RTCDtlsTransport {
|
|
|
317
448
|
writable: true,
|
|
318
449
|
value: (event) => this.events.dispatchEvent(event)
|
|
319
450
|
});
|
|
320
|
-
/** Settles a pending start() (set while the handshake is awaited). */
|
|
321
|
-
Object.defineProperty(this, "settleStart", {
|
|
322
|
-
enumerable: true,
|
|
323
|
-
configurable: true,
|
|
324
|
-
writable: true,
|
|
325
|
-
value: void 0
|
|
326
|
-
});
|
|
327
451
|
Object.defineProperty(this, "sendData", {
|
|
328
452
|
enumerable: true,
|
|
329
453
|
configurable: true,
|
|
330
454
|
writable: true,
|
|
331
455
|
value: async (data) => {
|
|
332
|
-
if (this.
|
|
333
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
456
|
+
if (this.dropForDebug("outbound"))
|
|
334
457
|
return;
|
|
335
|
-
}
|
|
336
458
|
if (!this.dtls) {
|
|
337
459
|
throw new Error("dtls not established");
|
|
338
460
|
}
|
|
461
|
+
if (!this.readiness.peerAuthenticated &&
|
|
462
|
+
!this.isEarlyServerOutboundReady()) {
|
|
463
|
+
throw new src_1.SCTPSendPermissionRevokedError("DTLS peer is not authenticated");
|
|
464
|
+
}
|
|
465
|
+
this.noteEarlyServerSend();
|
|
339
466
|
await this.dtls.send(data);
|
|
340
467
|
}
|
|
341
468
|
});
|
|
@@ -345,14 +472,89 @@ class RTCDtlsTransport {
|
|
|
345
472
|
writable: true,
|
|
346
473
|
value: void 0
|
|
347
474
|
});
|
|
348
|
-
this.config = config;
|
|
349
475
|
this.iceTransport = iceTransport;
|
|
350
476
|
this.localCertificate = localCertificate;
|
|
351
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
|
+
};
|
|
352
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);
|
|
353
555
|
}
|
|
354
556
|
get localParameters() {
|
|
355
|
-
return new RTCDtlsParameters(this.localCertificate ? this.localCertificate.getFingerprints() : [], this.role);
|
|
557
|
+
return new dtls_certificate_1.RTCDtlsParameters(this.localCertificate ? this.localCertificate.getFingerprints() : [], this.role);
|
|
356
558
|
}
|
|
357
559
|
/**
|
|
358
560
|
* Generates a new self-signed certificate (ECDSA P-256 / SHA-256) on every call.
|
|
@@ -360,11 +562,7 @@ class RTCDtlsTransport {
|
|
|
360
562
|
* when `RTCConfiguration.certificates` is not given.
|
|
361
563
|
*/
|
|
362
564
|
static async generateCertificate() {
|
|
363
|
-
|
|
364
|
-
signature: dtls_1.SignatureAlgorithm.ecdsa_3,
|
|
365
|
-
hash: dtls_1.HashAlgorithm.sha256_4,
|
|
366
|
-
}, dtls_1.NamedCurveAlgorithm.secp256r1_23);
|
|
367
|
-
return new RTCCertificate(keyPem, certPem, signatureHash);
|
|
565
|
+
return (0, dtls_certificate_1.createSelfSignedCertificate)();
|
|
368
566
|
}
|
|
369
567
|
/**
|
|
370
568
|
* Returns the default certificate cached for the whole process
|
|
@@ -381,17 +579,56 @@ class RTCDtlsTransport {
|
|
|
381
579
|
return this.localCertificatePromise;
|
|
382
580
|
}
|
|
383
581
|
setRemoteParams(remoteParameters) {
|
|
384
|
-
|
|
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);
|
|
385
586
|
const role = remoteParameters.role === "auto" && this.remoteParameters?.role
|
|
386
587
|
? this.remoteParameters.role
|
|
387
588
|
: remoteParameters.role;
|
|
388
|
-
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();
|
|
389
613
|
}
|
|
390
614
|
/** Internal: whether a description gave this transport the peer's DTLS parameters. */
|
|
391
615
|
get hasRemoteParameters() {
|
|
392
616
|
return (this.remoteParameters?.fingerprints.length ?? 0) > 0;
|
|
393
617
|
}
|
|
394
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
|
+
}
|
|
395
632
|
if (this.state !== "new") {
|
|
396
633
|
throw new Error("state must be new");
|
|
397
634
|
}
|
|
@@ -409,152 +646,499 @@ class RTCDtlsTransport {
|
|
|
409
646
|
}
|
|
410
647
|
}
|
|
411
648
|
this.setState("connecting");
|
|
412
|
-
// A connecting listener may have stopped the transport synchronously
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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);
|
|
418
685
|
return;
|
|
419
686
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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;
|
|
440
851
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
extendedMasterSecret: true,
|
|
449
|
-
verifyRemoteCertificate,
|
|
450
|
-
});
|
|
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();
|
|
451
859
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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")
|
|
455
878
|
return;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
//
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
879
|
+
}
|
|
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);
|
|
465
896
|
return;
|
|
466
|
-
log("dtls closed by the peer");
|
|
467
|
-
try {
|
|
468
|
-
this.setState("closed");
|
|
469
|
-
}
|
|
470
|
-
finally {
|
|
471
|
-
// Settle start() even if a statechange listener threw: it returns
|
|
472
|
-
// with closed (transport activation then ends a connection attempt
|
|
473
|
-
// that never connected as failed).
|
|
474
|
-
r();
|
|
475
897
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
this.
|
|
481
|
-
|
|
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) => {
|
|
482
982
|
try {
|
|
483
|
-
this.
|
|
983
|
+
(0, dtls_fingerprint_1.verifyRemoteCertificateFingerprint)(this.remoteParameters?.fingerprints, certificate);
|
|
984
|
+
return true;
|
|
484
985
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
? error.reason
|
|
493
|
-
: error);
|
|
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;
|
|
494
993
|
}
|
|
495
|
-
}
|
|
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);
|
|
496
1008
|
if (this.dtls instanceof dtls_1.DtlsClient) {
|
|
497
1009
|
await (0, promises_1.setTimeout)(100);
|
|
498
|
-
|
|
499
|
-
// stop() / a failure during the wait: settle start().
|
|
500
|
-
r();
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
this.dtls.connect().catch((error) => {
|
|
504
|
-
this.fail(error);
|
|
505
|
-
log("dtls connect failed", error);
|
|
506
|
-
f(error);
|
|
507
|
-
});
|
|
1010
|
+
this.dtls.connect().catch((error) => this.failStart(error, reject));
|
|
508
1011
|
}
|
|
509
1012
|
});
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
1013
|
+
}
|
|
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) {
|
|
517
1061
|
return;
|
|
518
|
-
try {
|
|
519
|
-
// Fallback: a certificate the in-handshake check did not see.
|
|
520
|
-
this.verifyRemoteCertificateFingerprint(this.dtls?.remoteCertificate);
|
|
521
|
-
}
|
|
522
|
-
catch (error) {
|
|
523
|
-
const dtls = this.dtls;
|
|
524
|
-
this.fail(certificateVerificationError(error));
|
|
525
|
-
// Tell the peer (whose handshake already completed); a fatal alert
|
|
526
|
-
// closes the DTLS transport once it has been sent.
|
|
527
|
-
void dtls?.sendAlert(dtls_1.AlertLevel.fatal, dtls_1.AlertDesc.BadCertificate, {
|
|
528
|
-
timeoutMs: exports.DTLS_ALERT_SEND_TIMEOUT_MS,
|
|
529
|
-
});
|
|
530
|
-
throw error;
|
|
531
1062
|
}
|
|
532
|
-
|
|
533
|
-
|
|
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);
|
|
534
1068
|
}
|
|
535
|
-
this.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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();
|
|
1089
|
+
}
|
|
1090
|
+
if (this.state !== "failed") {
|
|
1091
|
+
log("dtls closed by the peer");
|
|
1092
|
+
this.setState("closed");
|
|
1093
|
+
}
|
|
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();
|
|
1098
|
+
});
|
|
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;
|
|
1116
|
+
}
|
|
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
|
+
});
|
|
541
1129
|
}
|
|
542
|
-
/**
|
|
543
|
-
* Move to failed (once; closed / failed are final) and fire the `error`
|
|
544
|
-
* event with the DTLS alert that caused it.
|
|
545
|
-
*/
|
|
1130
|
+
/** closed / failed are terminal and produce one isolated DTLS error event. */
|
|
546
1131
|
fail(error) {
|
|
547
|
-
if (this.
|
|
1132
|
+
if (this.isTerminated())
|
|
548
1133
|
return;
|
|
1134
|
+
this.srtpAccess.revoke();
|
|
549
1135
|
this.setState("failed");
|
|
550
1136
|
const rtcError = error instanceof RTCError
|
|
551
1137
|
? error
|
|
552
1138
|
: error instanceof dtls_1.DtlsAlertError &&
|
|
553
1139
|
error.source === "local" &&
|
|
554
1140
|
error.reason instanceof FingerprintMismatchError
|
|
555
|
-
?
|
|
556
|
-
// (bad_certificate was sent).
|
|
557
|
-
certificateVerificationError(error.reason)
|
|
1141
|
+
? certificateVerificationError(error.reason)
|
|
558
1142
|
: error instanceof dtls_1.DtlsAlertError
|
|
559
1143
|
? new RTCError({
|
|
560
1144
|
errorDetail: "dtls-failure",
|
|
@@ -568,140 +1152,199 @@ class RTCDtlsTransport {
|
|
|
568
1152
|
error: rtcError,
|
|
569
1153
|
};
|
|
570
1154
|
this.notifySafely("onerror", () => this.onerror?.(event));
|
|
571
|
-
|
|
572
|
-
this.events.emitIsolated((error) => log("error listener failed", error), "error", event);
|
|
1155
|
+
this.events.emitIsolated((listenerError) => log("error listener failed", listenerError), "error", event);
|
|
573
1156
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const matched = expectedFingerprints.some(({ normalizedAlgorithm, normalizedValue }) => actualFingerprints.get(normalizedAlgorithm) === normalizedValue);
|
|
605
|
-
if (!matched) {
|
|
606
|
-
throw new FingerprintMismatchError();
|
|
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;
|
|
607
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);
|
|
608
1195
|
}
|
|
609
1196
|
updateSrtpSession() {
|
|
1197
|
+
this.installSrtpKeys();
|
|
1198
|
+
}
|
|
1199
|
+
installSrtpKeys() {
|
|
1200
|
+
if (this.srtpAccess.keysInstalled)
|
|
1201
|
+
return;
|
|
610
1202
|
if (!this.dtls)
|
|
611
1203
|
throw new Error();
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
log("selected SRTP Profile", profile);
|
|
617
|
-
const { localKey, localSalt, remoteKey, remoteSalt } = this.dtls.extractSessionKeys((0, rtp_1.keyLength)(profile), (0, rtp_1.saltLength)(profile));
|
|
618
|
-
const config = {
|
|
619
|
-
keys: {
|
|
620
|
-
localMasterKey: localKey,
|
|
621
|
-
localMasterSalt: localSalt,
|
|
622
|
-
remoteMasterKey: remoteKey,
|
|
623
|
-
remoteMasterSalt: remoteSalt,
|
|
624
|
-
},
|
|
625
|
-
profile,
|
|
626
|
-
};
|
|
627
|
-
this.srtp = new rtp_1.SrtpSession(config);
|
|
628
|
-
this.srtcp = new rtp_1.SrtcpSession(config);
|
|
1204
|
+
const { srtp, srtcp } = this.srtpAccess.installKeys(this.dtls);
|
|
1205
|
+
this.srtp = srtp;
|
|
1206
|
+
this.srtcp = srtcp;
|
|
629
1207
|
}
|
|
630
1208
|
startSrtp() {
|
|
631
|
-
if (this.srtpStarted)
|
|
632
|
-
return;
|
|
633
1209
|
this.srtpStarted = true;
|
|
634
|
-
this.
|
|
635
|
-
this.
|
|
636
|
-
|
|
637
|
-
|
|
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)
|
|
638
1239
|
return;
|
|
639
|
-
|
|
640
|
-
if (!(0, rtp_1.isMedia)(data))
|
|
1240
|
+
if (ctx.protocol !== ctx.pair.protocol)
|
|
641
1241
|
return;
|
|
642
|
-
|
|
643
|
-
if (
|
|
1242
|
+
const remote = ctx.pair.remoteAddr;
|
|
1243
|
+
if (ctx.source[0] !== remote[0] || ctx.source[1] !== remote[1])
|
|
644
1244
|
return;
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
let dec;
|
|
679
|
-
try {
|
|
680
|
-
dec = this.srtp.decrypt(data);
|
|
681
|
-
}
|
|
682
|
-
catch (error) {
|
|
683
|
-
if (error instanceof rtp_1.SrtpAuthenticationError) {
|
|
684
|
-
log("dropping invalid SRTP packet", error);
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
throw error;
|
|
688
|
-
}
|
|
689
|
-
let rtp;
|
|
690
|
-
try {
|
|
691
|
-
rtp = rtp_1.RtpPacket.deSerialize(dec);
|
|
692
|
-
}
|
|
693
|
-
catch (error) {
|
|
694
|
-
log("dropping malformed SRTP packet", error);
|
|
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))
|
|
695
1278
|
return;
|
|
696
|
-
}
|
|
697
1279
|
try {
|
|
698
|
-
this.
|
|
1280
|
+
this.onRtcp.execute(rtcp);
|
|
699
1281
|
}
|
|
700
1282
|
catch (error) {
|
|
701
|
-
log("
|
|
1283
|
+
log("RTCP error", error);
|
|
702
1284
|
}
|
|
703
1285
|
}
|
|
704
|
-
}
|
|
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++;
|
|
705
1348
|
}
|
|
706
1349
|
/**
|
|
707
1350
|
* Allocate the next transport-wide sequence at send time.
|
|
@@ -744,16 +1387,19 @@ class RTCDtlsTransport {
|
|
|
744
1387
|
return { size: 0, sendingAtMs: (0, utils_1.milliTime)() };
|
|
745
1388
|
}
|
|
746
1389
|
try {
|
|
1390
|
+
if (this.isTerminated() || !this.srtpAccess.canWrite) {
|
|
1391
|
+
return { size: 0, sendingAtMs: (0, utils_1.milliTime)() };
|
|
1392
|
+
}
|
|
1393
|
+
this.noteEarlyServerSend();
|
|
747
1394
|
const enc = this.srtp.encrypt(payload, header);
|
|
748
|
-
if (this.
|
|
749
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
1395
|
+
if (this.dropForDebug("outbound")) {
|
|
750
1396
|
return { size: enc.length, sendingAtMs: (0, utils_1.milliTime)() };
|
|
751
1397
|
}
|
|
752
|
-
// Track statistics
|
|
753
|
-
this.bytesSent += enc.length;
|
|
754
|
-
this.packetsSent++;
|
|
755
1398
|
const sendingAtMs = (0, utils_1.milliTime)();
|
|
756
|
-
await this.
|
|
1399
|
+
await this.sendProtectedMedia(enc);
|
|
1400
|
+
// 実際の wire 送信が成功した後だけ統計を更新する。SPED の early
|
|
1401
|
+
// path は authenticated pair 待ちで reject することがある。
|
|
1402
|
+
this.recordSent(enc.length);
|
|
757
1403
|
return { size: enc.length, sendingAtMs };
|
|
758
1404
|
}
|
|
759
1405
|
catch (error) {
|
|
@@ -761,26 +1407,51 @@ class RTCDtlsTransport {
|
|
|
761
1407
|
return { size: 0, sendingAtMs: (0, utils_1.milliTime)() };
|
|
762
1408
|
}
|
|
763
1409
|
}
|
|
764
|
-
/**
|
|
765
|
-
* Encrypt RTCP and enqueue on ICE. Like RTP, nothing is sent once the
|
|
766
|
-
* transport is `closed` / `failed` (periodic sender / receiver reports,
|
|
767
|
-
* NACK, PLI, TWCC feedback included).
|
|
768
|
-
*/
|
|
769
1410
|
async sendRtcp(packets) {
|
|
770
|
-
if (this.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
1411
|
+
if (this.isTerminated() || !this.srtpAccess.canWrite)
|
|
1412
|
+
return 0;
|
|
1413
|
+
this.noteEarlyServerSend();
|
|
774
1414
|
const payload = Buffer.concat(packets.map((packet) => packet.serialize()));
|
|
775
1415
|
const enc = this.srtcp.encrypt(payload);
|
|
776
|
-
if (this.
|
|
777
|
-
this.config.debug?.outboundPacketLoss / 100 < Math.random()) {
|
|
1416
|
+
if (this.dropForDebug("outbound")) {
|
|
778
1417
|
return enc.length;
|
|
779
1418
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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;
|
|
784
1455
|
}
|
|
785
1456
|
/**
|
|
786
1457
|
* Change the state and notify. Each notification is isolated: an
|
|
@@ -788,6 +1459,8 @@ class RTCDtlsTransport {
|
|
|
788
1459
|
* caller (stop() cleanup, settling start(), failing the transport).
|
|
789
1460
|
*/
|
|
790
1461
|
setState(state, emitEvent = true) {
|
|
1462
|
+
if (this.isFinalState)
|
|
1463
|
+
return;
|
|
791
1464
|
if (state != this.state) {
|
|
792
1465
|
this.state = state;
|
|
793
1466
|
// Per subscriber: an application subscriber registered before the
|
|
@@ -812,7 +1485,8 @@ class RTCDtlsTransport {
|
|
|
812
1485
|
*/
|
|
813
1486
|
markClosed() {
|
|
814
1487
|
this.setState("closed", false);
|
|
815
|
-
// A start() still waiting for the handshake
|
|
1488
|
+
// A start() still waiting for the handshake returns here; the caller
|
|
1489
|
+
// sees the transport closed (it never connected).
|
|
816
1490
|
this.settleStart?.();
|
|
817
1491
|
}
|
|
818
1492
|
/** Resolves once ICE has stopped; concurrent callers share one stop. */
|
|
@@ -850,33 +1524,38 @@ class RTCDtlsTransport {
|
|
|
850
1524
|
if (dtls &&
|
|
851
1525
|
!dtls.terminated &&
|
|
852
1526
|
!["closed", "failed"].includes(this.iceTransport.state)) {
|
|
853
|
-
log("send close_notify", this.iceTransport.state);
|
|
854
1527
|
await dtls.sendAlert(dtls_1.AlertLevel.warning, dtls_1.AlertDesc.CloseNotify, {
|
|
855
1528
|
timeoutMs: exports.DTLS_ALERT_SEND_TIMEOUT_MS,
|
|
856
1529
|
});
|
|
857
1530
|
}
|
|
858
1531
|
else if (dtls?.terminated) {
|
|
859
|
-
// The peer's close_notify is being answered: let that reply reach ICE
|
|
860
|
-
// before ICE stops.
|
|
861
1532
|
await dtls.alertFlushed();
|
|
862
1533
|
}
|
|
863
|
-
else {
|
|
864
|
-
log("skip close_notify", {
|
|
865
|
-
dtls: !!dtls,
|
|
866
|
-
terminated: dtls?.terminated,
|
|
867
|
-
ice: this.iceTransport.state,
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
1534
|
}
|
|
871
1535
|
catch (error) {
|
|
872
1536
|
log("stop: close_notify step failed", error);
|
|
873
1537
|
}
|
|
874
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();
|
|
875
1545
|
await this.iceTransport.stop();
|
|
876
1546
|
}
|
|
877
1547
|
catch (error) {
|
|
878
1548
|
log("stop: ice stop failed", error);
|
|
879
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
|
+
}
|
|
880
1559
|
try {
|
|
881
1560
|
await dtls?.close();
|
|
882
1561
|
}
|
|
@@ -888,67 +1567,26 @@ class RTCDtlsTransport {
|
|
|
888
1567
|
this.notifySafely("onStopped", () => this.onStopped.complete());
|
|
889
1568
|
}
|
|
890
1569
|
async getStats(timestamp = (0, stats_1.getStatsTimestamp)()) {
|
|
891
|
-
const stats =
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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,
|
|
898
1579
|
bytesSent: this.bytesSent,
|
|
899
1580
|
bytesReceived: this.bytesReceived,
|
|
900
1581
|
packetsSent: this.packetsSent,
|
|
901
1582
|
packetsReceived: this.packetsReceived,
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
? (0, stats_1.generateStatsId)("candidate-pair", this.iceTransport.connection.nominated.id)
|
|
910
|
-
: undefined,
|
|
911
|
-
localCertificateId: this.localCertificate
|
|
912
|
-
? (0, stats_1.generateStatsId)("certificate", this.id, "local")
|
|
913
|
-
: undefined,
|
|
914
|
-
remoteCertificateId: this.dtls?.remoteCertificate
|
|
915
|
-
? (0, stats_1.generateStatsId)("certificate", this.id, "remote")
|
|
916
|
-
: undefined,
|
|
917
|
-
dtlsRole: this.role === "auto" ? undefined : this.role,
|
|
918
|
-
tlsVersion: formatDtlsVersion(this.dtls?.dtls.version),
|
|
919
|
-
dtlsCipher: this.dtls?.cipher.cipher?.name,
|
|
920
|
-
srtpCipher: formatSrtpCipher(this.dtls?.srtp.srtpProfile),
|
|
921
|
-
iceRestarts: this.iceTransport.iceRestarts,
|
|
922
|
-
};
|
|
923
|
-
stats.push(transportStats);
|
|
924
|
-
// Certificate stats
|
|
925
|
-
if (this.localCertificate) {
|
|
926
|
-
const fingerprints = this.localCertificate.getFingerprints();
|
|
927
|
-
if (fingerprints.length > 0) {
|
|
928
|
-
const certStats = {
|
|
929
|
-
type: "certificate",
|
|
930
|
-
id: (0, stats_1.generateStatsId)("certificate", this.id, "local"),
|
|
931
|
-
timestamp,
|
|
932
|
-
fingerprint: fingerprints[0].value,
|
|
933
|
-
fingerprintAlgorithm: fingerprints[0].algorithm,
|
|
934
|
-
base64Certificate: Buffer.from(this.localCertificate.certPem).toString("base64"),
|
|
935
|
-
};
|
|
936
|
-
stats.push(certStats);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
if (this.remoteParameters &&
|
|
940
|
-
this.remoteParameters.fingerprints.length > 0 &&
|
|
941
|
-
this.dtls?.remoteCertificate) {
|
|
942
|
-
const certStats = {
|
|
943
|
-
type: "certificate",
|
|
944
|
-
id: (0, stats_1.generateStatsId)("certificate", this.id, "remote"),
|
|
945
|
-
timestamp,
|
|
946
|
-
fingerprint: this.remoteParameters.fingerprints[0].value,
|
|
947
|
-
fingerprintAlgorithm: this.remoteParameters.fingerprints[0].algorithm,
|
|
948
|
-
base64Certificate: Buffer.from(this.dtls.remoteCertificate).toString("base64"),
|
|
949
|
-
};
|
|
950
|
-
stats.push(certStats);
|
|
951
|
-
}
|
|
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);
|
|
952
1590
|
// Get ICE stats
|
|
953
1591
|
const iceStats = await this.iceTransport.getStats(timestamp, transportId);
|
|
954
1592
|
stats.push(...iceStats);
|
|
@@ -956,184 +1594,7 @@ class RTCDtlsTransport {
|
|
|
956
1594
|
}
|
|
957
1595
|
}
|
|
958
1596
|
exports.RTCDtlsTransport = RTCDtlsTransport;
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
"connecting",
|
|
962
|
-
"connected",
|
|
963
|
-
"closed",
|
|
964
|
-
"failed",
|
|
965
|
-
];
|
|
966
|
-
class RTCCertificate {
|
|
967
|
-
constructor(privateKeyPem, certPem, signatureHash) {
|
|
968
|
-
Object.defineProperty(this, "certPem", {
|
|
969
|
-
enumerable: true,
|
|
970
|
-
configurable: true,
|
|
971
|
-
writable: true,
|
|
972
|
-
value: void 0
|
|
973
|
-
});
|
|
974
|
-
Object.defineProperty(this, "signatureHash", {
|
|
975
|
-
enumerable: true,
|
|
976
|
-
configurable: true,
|
|
977
|
-
writable: true,
|
|
978
|
-
value: void 0
|
|
979
|
-
});
|
|
980
|
-
Object.defineProperty(this, "publicKey", {
|
|
981
|
-
enumerable: true,
|
|
982
|
-
configurable: true,
|
|
983
|
-
writable: true,
|
|
984
|
-
value: void 0
|
|
985
|
-
});
|
|
986
|
-
Object.defineProperty(this, "privateKey", {
|
|
987
|
-
enumerable: true,
|
|
988
|
-
configurable: true,
|
|
989
|
-
writable: true,
|
|
990
|
-
value: void 0
|
|
991
|
-
});
|
|
992
|
-
this.certPem = certPem;
|
|
993
|
-
this.signatureHash = signatureHash;
|
|
994
|
-
this.certPem = (0, dtls_1.normalizePem)(certPem);
|
|
995
|
-
const cert = new node_crypto_1.X509Certificate(this.certPem);
|
|
996
|
-
this.publicKey = cert.publicKey
|
|
997
|
-
.export({ type: "spki", format: "pem" })
|
|
998
|
-
.toString();
|
|
999
|
-
this.privateKey = (0, node_crypto_1.createPrivateKey)((0, dtls_1.normalizePem)(privateKeyPem))
|
|
1000
|
-
.export({ type: "pkcs8", format: "pem" })
|
|
1001
|
-
.toString();
|
|
1002
|
-
}
|
|
1003
|
-
getFingerprints() {
|
|
1004
|
-
return [
|
|
1005
|
-
new RTCDtlsFingerprint("sha-256", (0, utils_1.fingerprint)(new node_crypto_1.X509Certificate(this.certPem).raw, "sha256")),
|
|
1006
|
-
];
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
exports.RTCCertificate = RTCCertificate;
|
|
1010
|
-
class RTCDtlsFingerprint {
|
|
1011
|
-
constructor(algorithm, value) {
|
|
1012
|
-
Object.defineProperty(this, "algorithm", {
|
|
1013
|
-
enumerable: true,
|
|
1014
|
-
configurable: true,
|
|
1015
|
-
writable: true,
|
|
1016
|
-
value: void 0
|
|
1017
|
-
});
|
|
1018
|
-
Object.defineProperty(this, "value", {
|
|
1019
|
-
enumerable: true,
|
|
1020
|
-
configurable: true,
|
|
1021
|
-
writable: true,
|
|
1022
|
-
value: void 0
|
|
1023
|
-
});
|
|
1024
|
-
this.algorithm = algorithm;
|
|
1025
|
-
this.value = value;
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
exports.RTCDtlsFingerprint = RTCDtlsFingerprint;
|
|
1029
|
-
class RTCDtlsParameters {
|
|
1030
|
-
constructor(fingerprints = [], role) {
|
|
1031
|
-
Object.defineProperty(this, "fingerprints", {
|
|
1032
|
-
enumerable: true,
|
|
1033
|
-
configurable: true,
|
|
1034
|
-
writable: true,
|
|
1035
|
-
value: void 0
|
|
1036
|
-
});
|
|
1037
|
-
Object.defineProperty(this, "role", {
|
|
1038
|
-
enumerable: true,
|
|
1039
|
-
configurable: true,
|
|
1040
|
-
writable: true,
|
|
1041
|
-
value: void 0
|
|
1042
|
-
});
|
|
1043
|
-
this.fingerprints = fingerprints;
|
|
1044
|
-
this.role = role;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
exports.RTCDtlsParameters = RTCDtlsParameters;
|
|
1048
|
-
const deduplicateFingerprints = (fingerprints) => {
|
|
1049
|
-
const seen = new Set();
|
|
1050
|
-
return fingerprints.filter(({ algorithm, value }) => {
|
|
1051
|
-
const key = `${(0, utils_1.normalizeFingerprintAlgorithm)(algorithm) ?? algorithm.trim().toLowerCase()}:${(0, utils_1.normalizeFingerprintValue)(value)}`;
|
|
1052
|
-
if (seen.has(key)) {
|
|
1053
|
-
return false;
|
|
1054
|
-
}
|
|
1055
|
-
seen.add(key);
|
|
1056
|
-
return true;
|
|
1057
|
-
});
|
|
1058
|
-
};
|
|
1059
|
-
const preferredFingerprintAlgorithms = [
|
|
1060
|
-
"sha512",
|
|
1061
|
-
"sha384",
|
|
1062
|
-
"sha256",
|
|
1063
|
-
"sha224",
|
|
1064
|
-
"sha1",
|
|
1065
|
-
];
|
|
1066
|
-
const selectPreferredFingerprintAlgorithm = (fingerprints) => {
|
|
1067
|
-
return (preferredFingerprintAlgorithms.find((algorithm) => fingerprints.some(({ normalizedAlgorithm }) => normalizedAlgorithm === algorithm)) ?? fingerprints[0].normalizedAlgorithm);
|
|
1068
|
-
};
|
|
1069
|
-
/**
|
|
1070
|
-
* The DTLS socket's view of the ICE connection. The ICE connection belongs to
|
|
1071
|
-
* {@link RTCIceTransport} (shared with SRTP, stopped by
|
|
1072
|
-
* {@link RTCDtlsTransport.stop}): when the DTLS socket closes its transport
|
|
1073
|
-
* (after a received close_notify or fatal alert, or close()), this only
|
|
1074
|
-
* detaches DTLS from ICE; it never closes the ICE agent.
|
|
1075
|
-
*/
|
|
1076
|
-
class IceTransport {
|
|
1077
|
-
constructor(ice) {
|
|
1078
|
-
Object.defineProperty(this, "ice", {
|
|
1079
|
-
enumerable: true,
|
|
1080
|
-
configurable: true,
|
|
1081
|
-
writable: true,
|
|
1082
|
-
value: void 0
|
|
1083
|
-
});
|
|
1084
|
-
Object.defineProperty(this, "unSubscribe", {
|
|
1085
|
-
enumerable: true,
|
|
1086
|
-
configurable: true,
|
|
1087
|
-
writable: true,
|
|
1088
|
-
value: void 0
|
|
1089
|
-
});
|
|
1090
|
-
Object.defineProperty(this, "closed", {
|
|
1091
|
-
enumerable: true,
|
|
1092
|
-
configurable: true,
|
|
1093
|
-
writable: true,
|
|
1094
|
-
value: false
|
|
1095
|
-
});
|
|
1096
|
-
Object.defineProperty(this, "onData", {
|
|
1097
|
-
enumerable: true,
|
|
1098
|
-
configurable: true,
|
|
1099
|
-
writable: true,
|
|
1100
|
-
value: () => { }
|
|
1101
|
-
});
|
|
1102
|
-
Object.defineProperty(this, "type", {
|
|
1103
|
-
enumerable: true,
|
|
1104
|
-
configurable: true,
|
|
1105
|
-
writable: true,
|
|
1106
|
-
value: "ice"
|
|
1107
|
-
});
|
|
1108
|
-
Object.defineProperty(this, "send", {
|
|
1109
|
-
enumerable: true,
|
|
1110
|
-
configurable: true,
|
|
1111
|
-
writable: true,
|
|
1112
|
-
value: (data) => {
|
|
1113
|
-
if (this.closed)
|
|
1114
|
-
return Promise.resolve();
|
|
1115
|
-
return this.ice.send(data);
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
this.ice = ice;
|
|
1119
|
-
this.unSubscribe = ice.onData.subscribe((buf) => {
|
|
1120
|
-
if ((0, utils_1.isDtls)(buf)) {
|
|
1121
|
-
if (this.onData) {
|
|
1122
|
-
this.onData(buf);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}).unSubscribe;
|
|
1126
|
-
}
|
|
1127
|
-
get address() {
|
|
1128
|
-
return {};
|
|
1129
|
-
}
|
|
1130
|
-
/** Detach DTLS from ICE: no more DTLS records in either direction. */
|
|
1131
|
-
async close() {
|
|
1132
|
-
if (this.closed)
|
|
1133
|
-
return;
|
|
1134
|
-
this.closed = true;
|
|
1135
|
-
this.unSubscribe();
|
|
1136
|
-
}
|
|
1597
|
+
function toError(error) {
|
|
1598
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
1137
1599
|
}
|
|
1138
|
-
const createIceTransport = (ice) => new IceTransport(ice);
|
|
1139
1600
|
//# sourceMappingURL=dtls.js.map
|