werift 0.27.0 → 0.28.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 +119 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +12 -5
- package/lib/common/src/transport.js +3 -2
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/client.js +15 -1
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +2 -0
- package/lib/dtls/src/context/dtls.js +7 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +17 -1
- package/lib/dtls/src/context/transport.js +38 -2
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +4 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +5 -0
- package/lib/dtls/src/flight/flight.js +10 -1
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +4 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/index.d.ts +3 -1
- package/lib/dtls/src/index.js +10 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +9 -0
- package/lib/dtls/src/record/const.js +9 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +50 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/server.js +19 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +134 -2
- package/lib/dtls/src/socket.js +322 -6
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +49 -0
- package/lib/ice/src/consent.js +258 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/ice.d.ts +223 -71
- package/lib/ice/src/ice.js +873 -975
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +207 -8
- package/lib/ice/src/iceBase.js +94 -31
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +1 -0
- package/lib/ice/src/index.js +1 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
- package/lib/ice/src/internal/hostInterfaces.js +77 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
- package/lib/ice/src/nomination/selectionReplacement.js +371 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +9 -2
- package/lib/ice/src/stun/protocol.js +16 -17
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
- package/lib/ice/src/stun/tcpProtocol.js +7 -7
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.js +4 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +2 -2
- package/lib/ice/src/turn/protocol.js +6 -3
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +16 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +28 -1
- package/lib/ice-server/src/stun/message.js +102 -15
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +13394 -7732
- package/lib/nonstandard/index.mjs +680 -286
- package/lib/polyfill/dom.mjs +19605 -14243
- package/lib/polyfill/index.mjs +19605 -14243
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/sctp.d.ts +5 -0
- package/lib/sctp/src/sctp.js +81 -47
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +348 -34
- package/lib/webrtc/src/api/peerConfig.js +90 -24
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +239 -51
- package/lib/webrtc/src/media/router.js +664 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +222 -0
- package/lib/webrtc/src/media/rtpReceiver.js +668 -28
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +7 -0
- package/lib/webrtc/src/media/rtpSender.js +9 -3
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +18 -0
- package/lib/webrtc/src/media/rtpTransceiver.js +64 -2
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +9 -0
- package/lib/webrtc/src/media/track.js +9 -0
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +21 -0
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +35 -4
- package/lib/webrtc/src/negotiationTransaction.js +111 -8
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +65 -6
- package/lib/webrtc/src/peerConnection.js +283 -28
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +2 -0
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/sctpManager.js +4 -0
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +69 -0
- package/lib/webrtc/src/sdp.js +139 -14
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +85 -4
- package/lib/webrtc/src/sdpManager.js +214 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +38 -1
- package/lib/webrtc/src/secureTransportManager.js +82 -7
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +82 -4
- package/lib/webrtc/src/transceiverManager.js +231 -38
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +95 -1
- package/lib/webrtc/src/transport/dtls.js +324 -28
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +61 -4
- package/lib/webrtc/src/transport/ice.js +180 -11
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +23 -0
- package/lib/webrtc/src/transport/sctp.js +87 -2
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +33 -0
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flight6.js","sourceRoot":"","sources":["../../../../../../dtls/src/flight/server/flight6.ts"],"names":[],"mappings":";;;AAAA,gDAAmD;AACnD,0CAI0B;AAI1B,iDAAsD;AACtD,qEAAkE;AAClE,+EAA4E;AAC5E,wFAAqF;AACrF,4EAA+E;AAC/E,+DAA4D;AAC5D,iDAA6C;AAC7C,kDAAuD;AACvD,8CAAiD;AAEjD,sCAAmC;AAEnC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,sDAAsD,CAAC,CAAC;AAE1E,MAAa,OAAQ,SAAQ,eAAM;IAGjC,YAAY,GAAqB,EAAE,IAAiB,EAAE,MAAqB;QACzE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAHd;;;;;WAAsB;QAI5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,eAAe,CAAC,SAA8B;QAC5C,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAEtD,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;YACpB,QAAQ,SAAS,CAAC,QAAQ,EAAE,CAAC;gBAC3B,KAAK,qBAAa,CAAC,cAAc;oBAC/B,OAAO,yBAAW,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACrD,KAAK,qBAAa,CAAC,qBAAqB;oBACtC,OAAO,qCAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC3D,KAAK,qBAAa,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AAG,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,cAAc,CAAC;IACpC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CACrB,CAAC,OAAoB,EAAE,EAAE;QACvB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,qBAAqB,CAAC;IAC3C,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CACrB,CAAC,OAA0B,EAAE,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,WAAW,CAAC;IACjC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACb,CAAC,OAAiB,EAAE,EAAE;QACpB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC,CAAC","sourcesContent":["import { createCipher } from \"../../cipher/create\";\nimport {\n prfExtendedMasterSecret,\n prfMasterSecret,\n prfPreMasterSecret,\n} from \"../../cipher/prf\";\nimport type { CipherContext } from \"../../context/cipher\";\nimport type { DtlsContext } from \"../../context/dtls\";\nimport type { TransportContext } from \"../../context/transport\";\nimport { HandshakeType } from \"../../handshake/const\";\nimport { Certificate } from \"../../handshake/message/certificate\";\nimport { ChangeCipherSpec } from \"../../handshake/message/changeCipherSpec\";\nimport { CertificateVerify } from \"../../handshake/message/client/certificateVerify\";\nimport { ClientKeyExchange } from \"../../handshake/message/client/keyExchange\";\nimport { Finished } from \"../../handshake/message/finished\";\nimport { debug } from \"../../imports/common\";\nimport { createPlaintext } from \"../../record/builder\";\nimport { ContentType } from \"../../record/const\";\nimport type { FragmentedHandshake } from \"../../record/message/fragment\";\nimport { Flight } from \"../flight\";\n\nconst log = debug(\"werift-dtls : packages/dtls/flight/server/flight6.ts\");\n\nexport class Flight6 extends Flight {\n private cipher: CipherContext;\n\n constructor(udp: TransportContext, dtls: DtlsContext, cipher: CipherContext) {\n super(udp, dtls, 6);\n this.cipher = cipher;\n }\n\n handleHandshake(handshake: FragmentedHandshake) {\n this.dtls.bufferHandshakeCache([handshake], false, 5);\n\n const message = (() => {\n switch (handshake.msg_type) {\n case HandshakeType.certificate_11:\n return Certificate.deSerialize(handshake.fragment);\n case HandshakeType.certificate_verify_15:\n return CertificateVerify.deSerialize(handshake.fragment);\n case HandshakeType.client_key_exchange_16:\n return ClientKeyExchange.deSerialize(handshake.fragment);\n case HandshakeType.finished_20:\n return Finished.deSerialize(handshake.fragment);\n }\n })();\n\n if (message) {\n const handler = handlers[message.msgType];\n if (!handler) {\n return;\n }\n handler({ dtls: this.dtls, cipher: this.cipher })(message);\n }\n }\n\n async exec() {\n if (this.dtls.flight === 6) {\n log(this.dtls.sessionId, \"flight6 twice\");\n this.send(this.dtls.lastMessage);\n return;\n }\n this.dtls.flight = 6;\n\n const messages = [this.sendChangeCipherSpec(), this.sendFinished()];\n this.dtls.lastMessage = messages;\n await this.transmit(messages);\n }\n\n private sendChangeCipherSpec() {\n const changeCipherSpec = ChangeCipherSpec.createEmpty().serialize();\n const packets = createPlaintext(this.dtls)(\n [{ type: ContentType.changeCipherSpec, fragment: changeCipherSpec }],\n ++this.dtls.recordSequenceNumber,\n );\n const buf = Buffer.concat(packets.map((v) => v.serialize()));\n return buf;\n }\n\n private sendFinished() {\n const cache = Buffer.concat(\n this.dtls.sortedHandshakeCache.map((v) => v.serialize()),\n );\n\n const localVerifyData = this.cipher.verifyData(cache);\n const finish = new Finished(localVerifyData);\n\n this.dtls.epoch = 1;\n const [packet] = this.createPacket([finish]);\n this.dtls.recordSequenceNumber = 0;\n\n const buf = this.cipher.encryptPacket(packet).serialize();\n return buf;\n }\n}\n\nconst handlers: {\n [key: number]: (contexts: {\n dtls: DtlsContext;\n cipher: CipherContext;\n }) => (message: any) => void;\n} = {};\n\nhandlers[HandshakeType.client_key_exchange_16] =\n ({ cipher, dtls }) =>\n (message: ClientKeyExchange) => {\n cipher.remoteKeyPair = {\n curve: cipher.namedCurve,\n publicKey: message.publicKey,\n };\n if (\n !cipher.remoteKeyPair.publicKey ||\n !cipher.localKeyPair ||\n !cipher.remoteRandom ||\n !cipher.localRandom\n )\n throw new Error(\"not exist\");\n\n const preMasterSecret = prfPreMasterSecret(\n cipher.remoteKeyPair.publicKey,\n cipher.localKeyPair.privateKey,\n cipher.localKeyPair.curve,\n );\n\n log(\n dtls.sessionId,\n \"extendedMasterSecret\",\n dtls.options.extendedMasterSecret,\n dtls.remoteExtendedMasterSecret,\n );\n\n const handshakes = Buffer.concat(\n dtls.sortedHandshakeCache.map((v) => v.serialize()),\n );\n cipher.masterSecret =\n dtls.options.extendedMasterSecret && dtls.remoteExtendedMasterSecret\n ? prfExtendedMasterSecret(preMasterSecret, handshakes)\n : prfMasterSecret(\n preMasterSecret,\n cipher.remoteRandom.serialize(),\n cipher.localRandom.serialize(),\n );\n\n cipher.cipher = createCipher(cipher.cipherSuite!);\n cipher.cipher.init(\n cipher.masterSecret,\n cipher.localRandom.serialize(),\n cipher.remoteRandom.serialize(),\n );\n log(dtls.sessionId, \"setup cipher\", cipher.cipher.summary);\n };\n\nhandlers[HandshakeType.certificate_11] =\n ({ cipher, dtls }) =>\n (message: Certificate) => {\n log(dtls.sessionId, \"handshake certificate\", message);\n cipher.remoteCertificate = message.certificateList[0];\n };\n\nhandlers[HandshakeType.certificate_verify_15] =\n ({ cipher, dtls }) =>\n (message: CertificateVerify) => {\n if (!cipher.remoteCertificate) {\n throw new Error(\"client certificate missing before certificate verify\");\n }\n log(dtls.sessionId, \"certificate_verify\", message.algorithm);\n };\n\nhandlers[HandshakeType.finished_20] =\n ({ dtls }) =>\n (message: Finished) => {\n log(dtls.sessionId, \"finished\", message);\n };\n"]}
|
|
1
|
+
{"version":3,"file":"flight6.js","sourceRoot":"","sources":["../../../../../../dtls/src/flight/server/flight6.ts"],"names":[],"mappings":";;;AAAA,gDAAmD;AACnD,0CAI0B;AAI1B,iDAAsD;AACtD,qEAAkE;AAClE,+EAA4E;AAC5E,wFAAqF;AACrF,4EAA+E;AAC/E,+DAA4D;AAC5D,iDAA6C;AAC7C,kDAAuD;AACvD,8CAAiD;AAEjD,sCAAmC;AAEnC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,sDAAsD,CAAC,CAAC;AAE1E,MAAa,OAAQ,SAAQ,eAAM;IAGjC,YAAY,GAAqB,EAAE,IAAiB,EAAE,MAAqB;QACzE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAHd;;;;;WAAsB;QAI5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,eAAe,CAAC,SAA8B;QAC5C,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAEtD,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;YACpB,QAAQ,SAAS,CAAC,QAAQ,EAAE,CAAC;gBAC3B,KAAK,qBAAa,CAAC,cAAc;oBAC/B,OAAO,yBAAW,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACrD,KAAK,qBAAa,CAAC,qBAAqB;oBACtC,OAAO,qCAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;g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S,EAAE,EAC9B,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,CAChC,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,cAAc,CAAC;IACpC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CACrB,CAAC,OAAoB,EAAE,EAAE;QACvB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,qBAAqB,CAAC;IAC3C,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CACrB,CAAC,OAA0B,EAAE,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAa,CAAC,WAAW,CAAC;IACjC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACb,CAAC,OAAiB,EAAE,EAAE;QACpB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC,CAAC","sourcesContent":["import { createCipher } from \"../../cipher/create\";\nimport {\n prfExtendedMasterSecret,\n prfMasterSecret,\n prfPreMasterSecret,\n} from \"../../cipher/prf\";\nimport type { CipherContext } from \"../../context/cipher\";\nimport type { DtlsContext } from \"../../context/dtls\";\nimport type { TransportContext } from \"../../context/transport\";\nimport { HandshakeType } from \"../../handshake/const\";\nimport { Certificate } from \"../../handshake/message/certificate\";\nimport { ChangeCipherSpec } from \"../../handshake/message/changeCipherSpec\";\nimport { CertificateVerify } from \"../../handshake/message/client/certificateVerify\";\nimport { ClientKeyExchange } from \"../../handshake/message/client/keyExchange\";\nimport { Finished } from \"../../handshake/message/finished\";\nimport { debug } from \"../../imports/common\";\nimport { createPlaintext } from \"../../record/builder\";\nimport { ContentType } from \"../../record/const\";\nimport type { FragmentedHandshake } from \"../../record/message/fragment\";\nimport { Flight } from \"../flight\";\n\nconst log = debug(\"werift-dtls : packages/dtls/flight/server/flight6.ts\");\n\nexport class Flight6 extends Flight {\n private cipher: CipherContext;\n\n constructor(udp: TransportContext, dtls: DtlsContext, cipher: CipherContext) {\n super(udp, dtls, 6);\n this.cipher = cipher;\n }\n\n handleHandshake(handshake: FragmentedHandshake) {\n this.dtls.bufferHandshakeCache([handshake], false, 5);\n\n const message = (() => {\n switch (handshake.msg_type) {\n case HandshakeType.certificate_11:\n return Certificate.deSerialize(handshake.fragment);\n case HandshakeType.certificate_verify_15:\n return CertificateVerify.deSerialize(handshake.fragment);\n case HandshakeType.client_key_exchange_16:\n return ClientKeyExchange.deSerialize(handshake.fragment);\n case HandshakeType.finished_20:\n return Finished.deSerialize(handshake.fragment);\n }\n })();\n\n if (message) {\n const handler = handlers[message.msgType];\n if (!handler) {\n return;\n }\n handler({ dtls: this.dtls, cipher: this.cipher })(message);\n }\n }\n\n async exec() {\n if (this.dtls.flight === 6) {\n log(this.dtls.sessionId, \"flight6 twice\");\n this.send(this.dtls.lastMessage);\n return;\n }\n this.dtls.flight = 6;\n\n const messages = [this.sendChangeCipherSpec(), this.sendFinished()];\n this.dtls.lastMessage = messages;\n await this.transmit(messages);\n }\n\n private sendChangeCipherSpec() {\n const changeCipherSpec = ChangeCipherSpec.createEmpty().serialize();\n const packets = createPlaintext(this.dtls)(\n [{ type: ContentType.changeCipherSpec, fragment: changeCipherSpec }],\n ++this.dtls.recordSequenceNumber,\n );\n const buf = Buffer.concat(packets.map((v) => v.serialize()));\n return buf;\n }\n\n private sendFinished() {\n const cache = Buffer.concat(\n this.dtls.sortedHandshakeCache.map((v) => v.serialize()),\n );\n\n const localVerifyData = this.cipher.verifyData(cache);\n const finish = new Finished(localVerifyData);\n\n this.dtls.epoch = 1;\n // RFC 6347 §4.1: the record sequence number restarts at 0 with each\n // epoch; Finished is the first record of epoch 1 (later records continue\n // from 1, so no epoch-1 sequence number is used twice).\n this.dtls.recordSequenceNumber = -1;\n const [packet] = this.createPacket([finish]);\n\n const buf = this.cipher.encryptPacket(packet).serialize();\n return buf;\n }\n}\n\nconst handlers: {\n [key: number]: (contexts: {\n dtls: DtlsContext;\n cipher: CipherContext;\n }) => (message: any) => void;\n} = {};\n\nhandlers[HandshakeType.client_key_exchange_16] =\n ({ cipher, dtls }) =>\n (message: ClientKeyExchange) => {\n cipher.remoteKeyPair = {\n curve: cipher.namedCurve,\n publicKey: message.publicKey,\n };\n if (\n !cipher.remoteKeyPair.publicKey ||\n !cipher.localKeyPair ||\n !cipher.remoteRandom ||\n !cipher.localRandom\n )\n throw new Error(\"not exist\");\n\n const preMasterSecret = prfPreMasterSecret(\n cipher.remoteKeyPair.publicKey,\n cipher.localKeyPair.privateKey,\n cipher.localKeyPair.curve,\n );\n\n log(\n dtls.sessionId,\n \"extendedMasterSecret\",\n dtls.options.extendedMasterSecret,\n dtls.remoteExtendedMasterSecret,\n );\n\n const handshakes = Buffer.concat(\n dtls.sortedHandshakeCache.map((v) => v.serialize()),\n );\n cipher.masterSecret =\n dtls.options.extendedMasterSecret && dtls.remoteExtendedMasterSecret\n ? prfExtendedMasterSecret(preMasterSecret, handshakes)\n : prfMasterSecret(\n preMasterSecret,\n cipher.remoteRandom.serialize(),\n cipher.localRandom.serialize(),\n );\n\n cipher.cipher = createCipher(cipher.cipherSuite!);\n cipher.cipher.init(\n cipher.masterSecret,\n cipher.localRandom.serialize(),\n cipher.remoteRandom.serialize(),\n );\n log(dtls.sessionId, \"setup cipher\", cipher.cipher.summary);\n };\n\nhandlers[HandshakeType.certificate_11] =\n ({ cipher, dtls }) =>\n (message: Certificate) => {\n log(dtls.sessionId, \"handshake certificate\", message);\n cipher.remoteCertificate = message.certificateList[0];\n };\n\nhandlers[HandshakeType.certificate_verify_15] =\n ({ cipher, dtls }) =>\n (message: CertificateVerify) => {\n if (!cipher.remoteCertificate) {\n throw new Error(\"client certificate missing before certificate verify\");\n }\n log(dtls.sessionId, \"certificate_verify\", message.algorithm);\n };\n\nhandlers[HandshakeType.finished_20] =\n ({ dtls }) =>\n (message: Finished) => {\n log(dtls.sessionId, \"finished\", message);\n };\n"]}
|
package/lib/dtls/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export { classifyAlert, createAlertRecord, type DtlsAlert, DtlsAlertError, } from "./alert";
|
|
1
2
|
export * from "./cipher/const";
|
|
2
3
|
export { DtlsClient } from "./client";
|
|
3
4
|
export * from "./context/cipher";
|
|
4
5
|
export * from "./context/srtp";
|
|
6
|
+
export { AlertDesc, AlertLevel, alertDescName, ContentType, } from "./record/const";
|
|
5
7
|
export { DtlsServer } from "./server";
|
|
6
|
-
export { DtlsSocket } from "./socket";
|
|
8
|
+
export { DtlsSocket, type Options as DtlsSocketOptions } from "./socket";
|
package/lib/dtls/src/index.js
CHANGED
|
@@ -14,12 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.DtlsSocket = exports.DtlsServer = exports.DtlsClient = void 0;
|
|
17
|
+
exports.DtlsSocket = exports.DtlsServer = exports.ContentType = exports.alertDescName = exports.AlertLevel = exports.AlertDesc = exports.DtlsClient = exports.DtlsAlertError = exports.createAlertRecord = exports.classifyAlert = void 0;
|
|
18
|
+
var alert_1 = require("./alert");
|
|
19
|
+
Object.defineProperty(exports, "classifyAlert", { enumerable: true, get: function () { return alert_1.classifyAlert; } });
|
|
20
|
+
Object.defineProperty(exports, "createAlertRecord", { enumerable: true, get: function () { return alert_1.createAlertRecord; } });
|
|
21
|
+
Object.defineProperty(exports, "DtlsAlertError", { enumerable: true, get: function () { return alert_1.DtlsAlertError; } });
|
|
18
22
|
__exportStar(require("./cipher/const"), exports);
|
|
19
23
|
var client_1 = require("./client");
|
|
20
24
|
Object.defineProperty(exports, "DtlsClient", { enumerable: true, get: function () { return client_1.DtlsClient; } });
|
|
21
25
|
__exportStar(require("./context/cipher"), exports);
|
|
22
26
|
__exportStar(require("./context/srtp"), exports);
|
|
27
|
+
var const_1 = require("./record/const");
|
|
28
|
+
Object.defineProperty(exports, "AlertDesc", { enumerable: true, get: function () { return const_1.AlertDesc; } });
|
|
29
|
+
Object.defineProperty(exports, "AlertLevel", { enumerable: true, get: function () { return const_1.AlertLevel; } });
|
|
30
|
+
Object.defineProperty(exports, "alertDescName", { enumerable: true, get: function () { return const_1.alertDescName; } });
|
|
31
|
+
Object.defineProperty(exports, "ContentType", { enumerable: true, get: function () { return const_1.ContentType; } });
|
|
23
32
|
var server_1 = require("./server");
|
|
24
33
|
Object.defineProperty(exports, "DtlsServer", { enumerable: true, get: function () { return server_1.DtlsServer; } });
|
|
25
34
|
var socket_1 = require("./socket");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dtls/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,mDAAiC;AACjC,iDAA+B;AAC/B,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dtls/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAKiB;AAJf,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AAEjB,uGAAA,cAAc,OAAA;AAEhB,iDAA+B;AAC/B,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,mDAAiC;AACjC,iDAA+B;AAC/B,wCAKwB;AAJtB,kGAAA,SAAS,OAAA;AACT,mGAAA,UAAU,OAAA;AACV,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AAEb,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,mCAAyE;AAAhE,oGAAA,UAAU,OAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CE;AAEF,uBAAuB;AACvB,uBAAuB;AACvB,sBAAsB;AACtB,sBAAsB;AACtB,8BAA8B;AAC9B,sBAAsB;AACtB,8BAA8B;AAC9B,8BAA8B;AAC9B,4BAA4B;AAC5B,6BAA6B;AAC7B,8BAA8B;AAC9B,mBAAmB;AACnB,IAAI;AAEJ,qBAAqB;AACrB,2BAA2B;AAC3B,gBAAgB;AAChB,oBAAoB;AACpB,0BAA0B;AAC1B,IAAI;AAEJ,SAAS;AACT,qBAAqB;AACrB,4BAA4B;AAC5B,wBAAwB;AACxB,oCAAoC;AACpC,yBAAyB;AACzB,+BAA+B;AAC/B,2BAA2B;AAC3B,iCAAiC;AACjC,yBAAyB;AACzB,iCAAiC;AACjC,6BAA6B;AAC7B,6BAA6B;AAC7B,6BAA6B;AAC7B,2BAA2B;AAC3B,oBAAoB;AACpB,uBAAuB;AACvB,sBAAsB;AACtB,uBAAuB;AACvB,qCAAqC;AACrC,0BAA0B;AAC1B,+BAA+B;AAC/B,wBAAwB;AACxB,uBAAuB;AACvB,2BAA2B;AAC3B,gCAAgC;AAChC,UAAU;AACV,sBAAsB","sourcesContent":["export {\n classifyAlert,\n createAlertRecord,\n type DtlsAlert,\n DtlsAlertError,\n} from \"./alert\";\nexport * from \"./cipher/const\";\nexport { DtlsClient } from \"./client\";\nexport * from \"./context/cipher\";\nexport * from \"./context/srtp\";\nexport {\n AlertDesc,\n AlertLevel,\n alertDescName,\n ContentType,\n} from \"./record/const\";\nexport { DtlsServer } from \"./server\";\nexport { DtlsSocket, type Options as DtlsSocketOptions } from \"./socket\";\n\n/* Client Server\n ------ ------\n\n ClientHello --------> Flight 1\n\n\t\t\t\t\t\t <------- HelloVerifyRequest Flight 2\n\n ClientHello --------> Flight 3\n\n\t\t\t\t\t\t\t\t\t\t\t ServerHello \\\n\t\t\t\t\t\t\t\t\t\t\t Certificate* \\\n\t\t\t\t\t\t\t\t\t ServerKeyExchange* Flight 4\n\t\t\t\t\t\t\t\t\t CertificateRequest* /\n\t\t\t\t\t\t <-------- ServerHelloDone /\n\n Certificate* \\\n ClientKeyExchange \\\n CertificateVerify* Flight 5\n [ChangeCipherSpec] /\n Finished --------> /\n\n\t\t\t\t\t\t\t\t\t [ChangeCipherSpec] \\ Flight 6\n\t\t\t\t\t\t <-------- Finished /\n\n\t\t\t Figure 1. Message Flights for Full Handshake\n\n=======================================================================\n\n Client Server\n ------ ------\n\n ClientHello --------> Flight 1\n\n\t\t\t\t\t\t\t\t\t\t\t ServerHello \\\n\t\t\t\t\t\t\t\t\t [ChangeCipherSpec] Flight 2\n\t\t\t\t\t\t\t<-------- Finished /\n\n [ChangeCipherSpec] \\Flight 3\n Finished --------> /\n\n\t\t Figure 2. Message Flights for Session-Resuming Handshake\n\t\t\t\t\t\t (No Cookie Exchange)\n*/\n\n// enum HandshakeType {\n// hello_request = 0,\n// client_hello = 1,\n// server_hello = 2,\n// hello_verify_request = 3,\n// certificate = 11,\n// server_key_exchange = 12,\n// certificate_request = 13,\n// server_hello_done = 14,\n// certificate_verify = 15,\n// client_key_exchange = 16,\n// finished = 20,\n// }\n\n// enum ContentType {\n// changeCipherSpec = 20,\n// alert = 21,\n// handshake = 22,\n// applicationData = 23,\n// }\n\n// enum {\n// close_notify(0),\n// unexpected_message(10),\n// bad_record_mac(20),\n// decryption_failed_RESERVED(21),\n// record_overflow(22),\n// decompression_failure(30),\n// handshake_failure(40),\n// no_certificate_RESERVED(41),\n// bad_certificate(42),\n// unsupported_certificate(43),\n// certificate_revoked(44),\n// certificate_expired(45),\n// certificate_unknown(46),\n// illegal_parameter(47),\n// unknown_ca(48),\n// access_denied(49),\n// decode_error(50),\n// decrypt_error(51),\n// export_restriction_RESERVED(60),\n// protocol_version(70),\n// insufficient_security(71),\n// internal_error(80),\n// user_canceled(90),\n// no_renegotiation(100),\n// unsupported_extension(110),\n// (255)\n// } AlertDescription;\n"]}
|
|
@@ -41,3 +41,12 @@ export declare const AlertDesc: {
|
|
|
41
41
|
export type AlertDesc = (typeof AlertDesc)[keyof typeof AlertDesc];
|
|
42
42
|
/** Returns the AlertDesc member name for a wire value, or undefined if unknown. */
|
|
43
43
|
export declare const alertDescName: (value: number) => string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Alert level (RFC 5246 §7.2).
|
|
46
|
+
* @enum
|
|
47
|
+
*/
|
|
48
|
+
export declare const AlertLevel: {
|
|
49
|
+
readonly warning: 1;
|
|
50
|
+
readonly fatal: 2;
|
|
51
|
+
};
|
|
52
|
+
export type AlertLevel = (typeof AlertLevel)[keyof typeof AlertLevel];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.alertDescName = exports.AlertDesc = exports.ContentType = void 0;
|
|
3
|
+
exports.AlertLevel = exports.alertDescName = exports.AlertDesc = exports.ContentType = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @enum
|
|
6
6
|
*/
|
|
@@ -43,4 +43,12 @@ exports.AlertDesc = {
|
|
|
43
43
|
/** Returns the AlertDesc member name for a wire value, or undefined if unknown. */
|
|
44
44
|
const alertDescName = (value) => Object.entries(exports.AlertDesc).find(([, v]) => v === value)?.[0];
|
|
45
45
|
exports.alertDescName = alertDescName;
|
|
46
|
+
/**
|
|
47
|
+
* Alert level (RFC 5246 §7.2).
|
|
48
|
+
* @enum
|
|
49
|
+
*/
|
|
50
|
+
exports.AlertLevel = {
|
|
51
|
+
warning: 1,
|
|
52
|
+
fatal: 2,
|
|
53
|
+
};
|
|
46
54
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../../dtls/src/record/const.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,gBAAgB,EAAE,EAAE;IACpB,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE;IACb,eAAe,EAAE,EAAE;CACX,CAAC;AAGX;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,WAAW,EAAE,CAAC;IACd,iBAAiB,EAAE,EAAE;IACrB,YAAY,EAAE,EAAE;IAChB,gBAAgB,EAAE,EAAE;IACpB,cAAc,EAAE,EAAE;IAClB,oBAAoB,EAAE,EAAE;IACxB,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE,EAAE;IACjB,cAAc,EAAE,EAAE;IAClB,sBAAsB,EAAE,EAAE;IAC1B,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,EAAE;IACtB,gBAAgB,EAAE,EAAE;IACpB,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,EAAE;IACf,YAAY,EAAE,EAAE;IAChB,iBAAiB,EAAE,EAAE;IACrB,eAAe,EAAE,EAAE;IACnB,oBAAoB,EAAE,EAAE;IACxB,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,eAAe,EAAE,GAAG;IACpB,oBAAoB,EAAE,GAAG;CACjB,CAAC;AAGX,mFAAmF;AAC5E,MAAM,aAAa,GAAG,CAAC,KAAa,EAAsB,EAAE,CACjE,MAAM,CAAC,OAAO,CAAC,iBAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AADjD,QAAA,aAAa,iBACoC","sourcesContent":["/**\n * @enum\n */\nexport const ContentType = {\n changeCipherSpec: 20,\n alert: 21,\n handshake: 22,\n applicationData: 23,\n} as const;\nexport type ContentType = (typeof ContentType)[keyof typeof ContentType];\n\n/**\n * @enum\n */\nexport const AlertDesc = {\n CloseNotify: 0,\n UnexpectedMessage: 10,\n BadRecordMac: 20,\n DecryptionFailed: 21,\n RecordOverflow: 22,\n DecompressionFailure: 30,\n HandshakeFailure: 40,\n NoCertificate: 41,\n BadCertificate: 42,\n UnsupportedCertificate: 43,\n CertificateRevoked: 44,\n CertificateExpired: 45,\n CertificateUnknown: 46,\n IllegalParameter: 47,\n UnknownCa: 48,\n AccessDenied: 49,\n DecodeError: 50,\n DecryptError: 51,\n ExportRestriction: 60,\n ProtocolVersion: 70,\n InsufficientSecurity: 71,\n InternalError: 80,\n UserCanceled: 90,\n NoRenegotiation: 100,\n UnsupportedExtension: 110,\n} as const;\nexport type AlertDesc = (typeof AlertDesc)[keyof typeof AlertDesc];\n\n/** Returns the AlertDesc member name for a wire value, or undefined if unknown. */\nexport const alertDescName = (value: number): string | undefined =>\n Object.entries(AlertDesc).find(([, v]) => v === value)?.[0];\n"]}
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../../dtls/src/record/const.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,gBAAgB,EAAE,EAAE;IACpB,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE;IACb,eAAe,EAAE,EAAE;CACX,CAAC;AAGX;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,WAAW,EAAE,CAAC;IACd,iBAAiB,EAAE,EAAE;IACrB,YAAY,EAAE,EAAE;IAChB,gBAAgB,EAAE,EAAE;IACpB,cAAc,EAAE,EAAE;IAClB,oBAAoB,EAAE,EAAE;IACxB,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE,EAAE;IACjB,cAAc,EAAE,EAAE;IAClB,sBAAsB,EAAE,EAAE;IAC1B,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,EAAE;IACtB,gBAAgB,EAAE,EAAE;IACpB,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,EAAE;IACf,YAAY,EAAE,EAAE;IAChB,iBAAiB,EAAE,EAAE;IACrB,eAAe,EAAE,EAAE;IACnB,oBAAoB,EAAE,EAAE;IACxB,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,EAAE;IAChB,eAAe,EAAE,GAAG;IACpB,oBAAoB,EAAE,GAAG;CACjB,CAAC;AAGX,mFAAmF;AAC5E,MAAM,aAAa,GAAG,CAAC,KAAa,EAAsB,EAAE,CACjE,MAAM,CAAC,OAAO,CAAC,iBAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AADjD,QAAA,aAAa,iBACoC;AAE9D;;;GAGG;AACU,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;CACA,CAAC","sourcesContent":["/**\n * @enum\n */\nexport const ContentType = {\n changeCipherSpec: 20,\n alert: 21,\n handshake: 22,\n applicationData: 23,\n} as const;\nexport type ContentType = (typeof ContentType)[keyof typeof ContentType];\n\n/**\n * @enum\n */\nexport const AlertDesc = {\n CloseNotify: 0,\n UnexpectedMessage: 10,\n BadRecordMac: 20,\n DecryptionFailed: 21,\n RecordOverflow: 22,\n DecompressionFailure: 30,\n HandshakeFailure: 40,\n NoCertificate: 41,\n BadCertificate: 42,\n UnsupportedCertificate: 43,\n CertificateRevoked: 44,\n CertificateExpired: 45,\n CertificateUnknown: 46,\n IllegalParameter: 47,\n UnknownCa: 48,\n AccessDenied: 49,\n DecodeError: 50,\n DecryptError: 51,\n ExportRestriction: 60,\n ProtocolVersion: 70,\n InsufficientSecurity: 71,\n InternalError: 80,\n UserCanceled: 90,\n NoRenegotiation: 100,\n UnsupportedExtension: 110,\n} as const;\nexport type AlertDesc = (typeof AlertDesc)[keyof typeof AlertDesc];\n\n/** Returns the AlertDesc member name for a wire value, or undefined if unknown. */\nexport const alertDescName = (value: number): string | undefined =>\n Object.entries(AlertDesc).find(([, v]) => v === value)?.[0];\n\n/**\n * Alert level (RFC 5246 §7.2).\n * @enum\n */\nexport const AlertLevel = {\n warning: 1,\n fatal: 2,\n} as const;\nexport type AlertLevel = (typeof AlertLevel)[keyof typeof AlertLevel];\n"]}
|
|
@@ -2,6 +2,12 @@ import type { CipherContext } from "../context/cipher";
|
|
|
2
2
|
import type { DtlsContext } from "../context/dtls";
|
|
3
3
|
import { ContentType } from "./const";
|
|
4
4
|
import { DtlsPlaintext } from "./message/plaintext";
|
|
5
|
+
/**
|
|
6
|
+
* Split a datagram into its records. A truncated record (shorter than its
|
|
7
|
+
* header or its length field) ends the datagram: the records before it are
|
|
8
|
+
* kept, the rest is discarded (RFC 6347 §4.1.2.1: invalid records are
|
|
9
|
+
* silently discarded).
|
|
10
|
+
*/
|
|
5
11
|
export declare const parsePacket: (data: Buffer) => DtlsPlaintext[];
|
|
6
12
|
export declare const parsePlainText: (dtls: DtlsContext, cipher: CipherContext) => (plain: DtlsPlaintext) => {
|
|
7
13
|
type: ContentType;
|
|
@@ -8,17 +8,25 @@ const fragment_1 = require("./message/fragment");
|
|
|
8
8
|
const plaintext_1 = require("./message/plaintext");
|
|
9
9
|
const log = (0, common_1.debug)("werift-dtls : packages/dtls/record/receive.ts : log");
|
|
10
10
|
const err = (0, common_1.debug)("werift-dtls : packages/dtls/record/receive.ts : err");
|
|
11
|
+
/** DTLS record header: type(1) version(2) epoch(2) sequence(6) length(2). */
|
|
12
|
+
const recordHeaderLength = 13;
|
|
13
|
+
/**
|
|
14
|
+
* Split a datagram into its records. A truncated record (shorter than its
|
|
15
|
+
* header or its length field) ends the datagram: the records before it are
|
|
16
|
+
* kept, the rest is discarded (RFC 6347 §4.1.2.1: invalid records are
|
|
17
|
+
* silently discarded).
|
|
18
|
+
*/
|
|
11
19
|
const parsePacket = (data) => {
|
|
12
20
|
let start = 0;
|
|
13
21
|
const packets = [];
|
|
14
|
-
while (data.length
|
|
22
|
+
while (data.length - start >= recordHeaderLength) {
|
|
15
23
|
const fragmentLength = data.readUInt16BE(start + 11);
|
|
16
|
-
if (data.length < start +
|
|
24
|
+
if (data.length < start + recordHeaderLength + fragmentLength) {
|
|
17
25
|
break;
|
|
18
26
|
}
|
|
19
27
|
const packet = plaintext_1.DtlsPlaintext.deSerialize(data.subarray(start));
|
|
20
28
|
packets.push(packet);
|
|
21
|
-
start +=
|
|
29
|
+
start += recordHeaderLength + fragmentLength;
|
|
22
30
|
}
|
|
23
31
|
return packets;
|
|
24
32
|
};
|
|
@@ -41,6 +49,7 @@ const parsePlainText = (dtls, cipher) => (plain) => {
|
|
|
41
49
|
if (plain.recordLayerHeader.epoch > 0) {
|
|
42
50
|
log(dtls.sessionId, "decrypt handshake");
|
|
43
51
|
raw = cipher.decryptPacket(plain);
|
|
52
|
+
dtls.remoteEpoch = Math.max(dtls.remoteEpoch, plain.recordLayerHeader.epoch);
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
catch (error) {
|
|
@@ -63,28 +72,50 @@ const parsePlainText = (dtls, cipher) => (plain) => {
|
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
case const_1.ContentType.applicationData: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
data: cipher.decryptPacket(plain),
|
|
70
|
-
},
|
|
71
|
-
];
|
|
75
|
+
const data = cipher.decryptPacket(plain);
|
|
76
|
+
dtls.remoteEpoch = Math.max(dtls.remoteEpoch, plain.recordLayerHeader.epoch);
|
|
77
|
+
return [{ type: const_1.ContentType.applicationData, data }];
|
|
72
78
|
}
|
|
73
79
|
case const_1.ContentType.alert: {
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
// The record epoch tells whether the alert is protected: epoch 0 is
|
|
81
|
+
// plaintext (before ChangeCipherSpec), epoch > 0 is encrypted. A
|
|
82
|
+
// record that fails to decrypt throws and is dropped by the caller
|
|
83
|
+
// (RFC 6347 §4.1.2.1: invalid records are silently discarded).
|
|
84
|
+
const epoch = plain.recordLayerHeader.epoch;
|
|
85
|
+
// Once the peer's protected records were accepted, a plaintext (or
|
|
86
|
+
// older-epoch) alert is unauthenticated and must not end the
|
|
87
|
+
// connection: drop it.
|
|
88
|
+
if (epoch < dtls.remoteEpoch) {
|
|
89
|
+
throw new Error("alert from a stale epoch");
|
|
90
|
+
}
|
|
91
|
+
const raw = epoch > 0 ? cipher.decryptPacket(plain) : plain.fragment;
|
|
92
|
+
if (epoch > 0) {
|
|
93
|
+
dtls.remoteEpoch = Math.max(dtls.remoteEpoch, epoch);
|
|
94
|
+
}
|
|
95
|
+
if (raw.length < 2) {
|
|
96
|
+
throw new Error("malformed alert record");
|
|
97
|
+
}
|
|
98
|
+
// A record may carry several alerts (RFC 5246 §6.2.1, unchanged by
|
|
99
|
+
// RFC 6347 §4.1): return all of them in order. The receiver stops at
|
|
100
|
+
// the first one that ends the connection. A trailing partial alert
|
|
101
|
+
// cannot be reassembled across DTLS records and is dropped.
|
|
102
|
+
const alerts = [];
|
|
103
|
+
for (let start = 0; start + 2 <= raw.length; start += 2) {
|
|
104
|
+
const alert = alert_1.Alert.deSerialize(raw.subarray(start, start + 2));
|
|
105
|
+
log(dtls.sessionId, "ContentType.alert", alert, (0, const_1.alertDescName)(alert.description), "flight", dtls.flight, "lastFlight", dtls.lastFlight);
|
|
106
|
+
alerts.push({
|
|
107
|
+
type: const_1.ContentType.alert,
|
|
108
|
+
data: { level: alert.level, description: alert.description },
|
|
109
|
+
});
|
|
79
110
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
throw new Error("alert fatal error");
|
|
111
|
+
if (raw.length % 2 !== 0) {
|
|
112
|
+
err(dtls.sessionId, "drop a partial alert at the end of the record");
|
|
83
113
|
}
|
|
84
|
-
return
|
|
114
|
+
return alerts;
|
|
85
115
|
}
|
|
86
116
|
default: {
|
|
87
|
-
|
|
117
|
+
// Unknown content type: nothing to deliver (RFC 6347 §4.1.2.1).
|
|
118
|
+
return [];
|
|
88
119
|
}
|
|
89
120
|
}
|
|
90
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"receive.js","sourceRoot":"","sources":["../../../../../dtls/src/record/receive.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"receive.js","sourceRoot":"","sources":["../../../../../dtls/src/record/receive.ts"],"names":[],"mappings":";;;AAGA,sDAAmD;AACnD,8CAA0C;AAC1C,mCAAqD;AACrD,iDAAyD;AACzD,mDAAoD;AAEpD,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,qDAAqD,CAAC,CAAC;AACzE,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,qDAAqD,CAAC,CAAC;AAEzE,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,OAAO,GAAoB,EAAE,CAAC;IACpC,OAAO,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,kBAAkB,EAAE,CAAC;QACjD,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;QACrD,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,kBAAkB,GAAG,cAAc,EAAE,CAAC;YAC9D,MAAM;QACR,CAAC;QACD,MAA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,CAAC;YACL,CAAC;YACD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,+CAA+C,CAAC,CAAC;YACvE,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,gEAAgE;YAChE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AA/GS,QAAA,cAAc,kBA+GvB","sourcesContent":["import type { DtlsAlert } from \"../alert\";\nimport type { CipherContext } from \"../context/cipher\";\nimport type { DtlsContext } from \"../context/dtls\";\nimport { Alert } from \"../handshake/message/alert\";\nimport { debug } from \"../imports/common\";\nimport { alertDescName, ContentType } from \"./const\";\nimport { FragmentedHandshake } from \"./message/fragment\";\nimport { DtlsPlaintext } from \"./message/plaintext\";\n\nconst log = debug(\"werift-dtls : packages/dtls/record/receive.ts : log\");\nconst err = debug(\"werift-dtls : packages/dtls/record/receive.ts : err\");\n\n/** DTLS record header: type(1) version(2) epoch(2) sequence(6) length(2). */\nconst recordHeaderLength = 13;\n\n/**\n * Split a datagram into its records. A truncated record (shorter than its\n * header or its length field) ends the datagram: the records before it are\n * kept, the rest is discarded (RFC 6347 §4.1.2.1: invalid records are\n * silently discarded).\n */\nexport const parsePacket = (data: Buffer) => {\n let start = 0;\n const packets: DtlsPlaintext[] = [];\n while (data.length - start >= recordHeaderLength) {\n const fragmentLength = data.readUInt16BE(start + 11);\n if (data.length < start + recordHeaderLength + fragmentLength) {\n break;\n }\n const packet = DtlsPlaintext.deSerialize(data.subarray(start));\n packets.push(packet);\n\n start += recordHeaderLength + fragmentLength;\n }\n\n return packets;\n};\n\nexport const parsePlainText =\n (dtls: DtlsContext, cipher: CipherContext) =>\n (\n plain: DtlsPlaintext,\n ): {\n type: ContentType;\n data: any;\n }[] => {\n const contentType = plain.recordLayerHeader.contentType;\n\n switch (contentType) {\n case ContentType.changeCipherSpec: {\n log(dtls.sessionId, \"change cipher spec\");\n return [\n {\n type: ContentType.changeCipherSpec,\n data: undefined,\n },\n ];\n }\n case ContentType.handshake: {\n let raw = plain.fragment;\n try {\n if (plain.recordLayerHeader.epoch > 0) {\n log(dtls.sessionId, \"decrypt handshake\");\n raw = cipher.decryptPacket(plain);\n dtls.remoteEpoch = Math.max(\n dtls.remoteEpoch,\n plain.recordLayerHeader.epoch,\n );\n }\n } catch (error) {\n err(dtls.sessionId, \"decrypt failed\", error);\n throw error;\n }\n try {\n let start = 0;\n const handshakes: { type: ContentType; data: any }[] = [];\n while (raw.length > start) {\n const handshake = FragmentedHandshake.deSerialize(\n raw.subarray(start),\n );\n handshakes.push({ type: ContentType.handshake, data: handshake });\n start += handshake.fragment_length + 12;\n }\n\n return handshakes;\n } catch (error) {\n err(dtls.sessionId, \"decSerialize failed\", error, raw);\n throw error;\n }\n }\n case ContentType.applicationData: {\n const data = cipher.decryptPacket(plain);\n dtls.remoteEpoch = Math.max(\n dtls.remoteEpoch,\n plain.recordLayerHeader.epoch,\n );\n return [{ type: ContentType.applicationData, data }];\n }\n case ContentType.alert: {\n // The record epoch tells whether the alert is protected: epoch 0 is\n // plaintext (before ChangeCipherSpec), epoch > 0 is encrypted. A\n // record that fails to decrypt throws and is dropped by the caller\n // (RFC 6347 §4.1.2.1: invalid records are silently discarded).\n const epoch = plain.recordLayerHeader.epoch;\n // Once the peer's protected records were accepted, a plaintext (or\n // older-epoch) alert is unauthenticated and must not end the\n // connection: drop it.\n if (epoch < dtls.remoteEpoch) {\n throw new Error(\"alert from a stale epoch\");\n }\n const raw = epoch > 0 ? cipher.decryptPacket(plain) : plain.fragment;\n if (epoch > 0) {\n dtls.remoteEpoch = Math.max(dtls.remoteEpoch, epoch);\n }\n if (raw.length < 2) {\n throw new Error(\"malformed alert record\");\n }\n // A record may carry several alerts (RFC 5246 §6.2.1, unchanged by\n // RFC 6347 §4.1): return all of them in order. The receiver stops at\n // the first one that ends the connection. A trailing partial alert\n // cannot be reassembled across DTLS records and is dropped.\n const alerts: { type: ContentType; data: DtlsAlert }[] = [];\n for (let start = 0; start + 2 <= raw.length; start += 2) {\n const alert = Alert.deSerialize(raw.subarray(start, start + 2));\n log(\n dtls.sessionId,\n \"ContentType.alert\",\n alert,\n alertDescName(alert.description),\n \"flight\",\n dtls.flight,\n \"lastFlight\",\n dtls.lastFlight,\n );\n alerts.push({\n type: ContentType.alert,\n data: { level: alert.level, description: alert.description },\n });\n }\n if (raw.length % 2 !== 0) {\n err(dtls.sessionId, \"drop a partial alert at the end of the record\");\n }\n return alerts;\n }\n default: {\n // Unknown content type: nothing to deliver (RFC 6347 §4.1.2.1).\n return [];\n }\n }\n };\n"]}
|
package/lib/dtls/src/server.js
CHANGED
|
@@ -26,6 +26,8 @@ class DtlsServer extends socket_1.DtlsSocket {
|
|
|
26
26
|
value: async (assembled) => {
|
|
27
27
|
log(this.dtls.sessionId, "handleHandshakes", assembled.map((a) => a.msg_type));
|
|
28
28
|
for (const handshake of assembled) {
|
|
29
|
+
if (this.handshakeStopped)
|
|
30
|
+
return;
|
|
29
31
|
switch (handshake.msg_type) {
|
|
30
32
|
// flight1,3
|
|
31
33
|
case const_1.HandshakeType.client_hello_1:
|
|
@@ -60,6 +62,11 @@ class DtlsServer extends socket_1.DtlsSocket {
|
|
|
60
62
|
return;
|
|
61
63
|
this.flight6 = new flight6_1.Flight6(this.transport, this.dtls, this.cipher);
|
|
62
64
|
this.flight6.handleHandshake(handshake);
|
|
65
|
+
// Reject the client certificate before our Finished is sent.
|
|
66
|
+
if (handshake.msg_type === const_1.HandshakeType.certificate_11 &&
|
|
67
|
+
!this.verifyRemoteCertificate()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
63
70
|
}
|
|
64
71
|
break;
|
|
65
72
|
case const_1.HandshakeType.finished_20:
|
|
@@ -72,9 +79,20 @@ class DtlsServer extends socket_1.DtlsSocket {
|
|
|
72
79
|
this.options.certificateRequest && 15,
|
|
73
80
|
].filter((type) => typeof type === "number");
|
|
74
81
|
await this.waitForReady(() => this.dtls.checkHandshakesExist(requiredHandshakes));
|
|
82
|
+
// The certificate may have been rejected while waiting.
|
|
83
|
+
if (this.handshakeStopped)
|
|
84
|
+
return;
|
|
85
|
+
if (this.options.verifyRemoteCertificate &&
|
|
86
|
+
!this.cipher.remoteCertificate) {
|
|
87
|
+
// A verifier needs the client certificate (certificateRequest).
|
|
88
|
+
this.verifyRemoteCertificate();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
75
91
|
await this.flight6?.exec();
|
|
92
|
+
if (this.handshakeStopped)
|
|
93
|
+
return;
|
|
76
94
|
this.connected = true;
|
|
77
|
-
this.onConnect
|
|
95
|
+
this.notify(this.onConnect);
|
|
78
96
|
log(this.dtls.sessionId, "dtls connected");
|
|
79
97
|
}
|
|
80
98
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../dtls/src/server.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,qDAAkD;AAClD,qDAAkD;AAClD,qDAAkD;AAClD,6CAAkD;AAClD,4DAA+D;AAC/D,6CAAyC;AAEzC,qCAAoD;AAEpD,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,iDAAiD,CAAC,CAAC;AAErE,MAAa,UAAW,SAAQ,mBAAU;IACxC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,EAAE,sBAAW,CAAC,MAAM,CAAC,CAAC;QAK7B;;;;;WAAkB;QAClB;;;;mBAAmB,KAAK,EAAE,SAAgC,EAAE,EAAE;gBACpE,GAAG,CACD,IAAI,CAAC,IAAI,CAAC,SAAS,EACnB,kBAAkB,EAClB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CACjC,CAAC;gBAEF,KAAK,MAAM,SAAS,IAAI,SAAS,EAAE,CAAC;oBAClC,QAAQ,SAAS,CAAC,QAA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C,iBAAiB,EAC9B,CAAC;oCACD,gEAAgE;oCAChE,IAAI,CAAC,uBAAuB,EAAE,CAAC;oCAC/B,OAAO;gCACT,CAAC;gCACD,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;gCAC3B,IAAI,IAAI,CAAC,gBAAgB;oCAAE,OAAO;gCAElC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gCACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gCAC5B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;4BAC7C,CAAC;4BACD,MAAM;oBACV,CAAC;gBACH,CAAC;YACH,CAAC;WAAC;QApGA,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAC3C,CAAC;CAmGF;AAxGD,gCAwGC","sourcesContent":["import { SessionType } from \"./cipher/suites/abstract\";\nimport { flight2 } from \"./flight/server/flight2\";\nimport { Flight4 } from \"./flight/server/flight4\";\nimport { Flight6 } from \"./flight/server/flight6\";\nimport { HandshakeType } from \"./handshake/const\";\nimport { ClientHello } from \"./handshake/message/client/hello\";\nimport { debug } from \"./imports/common\";\nimport type { FragmentedHandshake } from \"./record/message/fragment\";\nimport { DtlsSocket, type Options } from \"./socket\";\n\nconst log = debug(\"werift-dtls : packages/dtls/src/server.ts : log\");\n\nexport class DtlsServer extends DtlsSocket {\n constructor(options: Options) {\n super(options, SessionType.SERVER);\n this.onHandleHandshakes = this.handleHandshakes;\n log(this.dtls.sessionId, \"start server\");\n }\n\n private flight6?: Flight6;\n private handleHandshakes = async (assembled: FragmentedHandshake[]) => {\n log(\n this.dtls.sessionId,\n \"handleHandshakes\",\n assembled.map((a) => a.msg_type),\n );\n\n for (const handshake of assembled) {\n if (this.handshakeStopped) return;\n switch (handshake.msg_type) {\n // flight1,3\n case HandshakeType.client_hello_1:\n {\n if (this.connected) {\n this.renegotiation();\n }\n const clientHello = ClientHello.deSerialize(handshake.fragment);\n\n if (clientHello.cookie.length === 0) {\n log(this.dtls.sessionId, \"send flight2\");\n flight2(\n this.transport,\n this.dtls,\n this.cipher,\n this.srtp,\n )(clientHello);\n } else if (\n this.dtls.cookie &&\n clientHello.cookie.equals(this.dtls.cookie)\n ) {\n log(this.dtls.sessionId, \"send flight4\");\n await new Flight4(\n this.transport,\n this.dtls,\n this.cipher,\n this.srtp,\n ).exec(handshake, clientHello, this.options.certificateRequest);\n } else {\n log(\"wrong state\", {\n dtlsCookie: this.dtls.cookie?.toString(\"hex\").slice(10),\n helloCookie: clientHello.cookie.toString(\"hex\").slice(10),\n });\n }\n }\n break;\n // flight 5\n case HandshakeType.certificate_11:\n case HandshakeType.certificate_verify_15:\n case HandshakeType.client_key_exchange_16:\n {\n if (this.connected) return;\n this.flight6 = new Flight6(this.transport, this.dtls, this.cipher);\n this.flight6.handleHandshake(handshake);\n // Reject the client certificate before our Finished is sent.\n if (\n handshake.msg_type === HandshakeType.certificate_11 &&\n !this.verifyRemoteCertificate()\n ) {\n return;\n }\n }\n break;\n case HandshakeType.finished_20:\n {\n await this.waitForReady(() => !!this.flight6);\n this.flight6?.handleHandshake(handshake);\n\n const requiredHandshakes = [\n 16,\n this.options.certificateRequest && 11,\n this.options.certificateRequest && 15,\n ].filter((type): type is number => typeof type === \"number\");\n await this.waitForReady(() =>\n this.dtls.checkHandshakesExist(requiredHandshakes),\n );\n // The certificate may have been rejected while waiting.\n if (this.handshakeStopped) return;\n if (\n this.options.verifyRemoteCertificate &&\n !this.cipher.remoteCertificate\n ) {\n // A verifier needs the client certificate (certificateRequest).\n this.verifyRemoteCertificate();\n return;\n }\n await this.flight6?.exec();\n if (this.handshakeStopped) return;\n\n this.connected = true;\n this.notify(this.onConnect);\n log(this.dtls.sessionId, \"dtls connected\");\n }\n break;\n }\n }\n };\n}\n"]}
|
package/lib/dtls/src/socket.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DtlsAlert } from "./alert";
|
|
1
2
|
import { type SignatureHash } from "./cipher/const";
|
|
2
3
|
import { type SessionTypes } from "./cipher/suites/abstract";
|
|
3
4
|
import { CipherContext } from "./context/cipher";
|
|
@@ -7,15 +8,26 @@ import { TransportContext } from "./context/transport";
|
|
|
7
8
|
import type { Address, Transport } from "./imports/common";
|
|
8
9
|
import { Event } from "./imports/common";
|
|
9
10
|
import type { SrtpProfile } from "./imports/rtp";
|
|
11
|
+
import { AlertDesc, AlertLevel } from "./record/const";
|
|
10
12
|
import { FragmentedHandshake } from "./record/message/fragment";
|
|
11
13
|
import type { Extension } from "./typings/domain";
|
|
12
14
|
export declare class DtlsSocket {
|
|
15
|
+
/** Default upper bound (ms) for waiting until an alert has been sent. */
|
|
16
|
+
static AlertSendTimeoutMs: number;
|
|
13
17
|
options: Options;
|
|
14
18
|
sessionType: SessionTypes;
|
|
15
19
|
readonly onConnect: Event<any[]>;
|
|
16
20
|
readonly onData: Event<[Buffer<ArrayBufferLike>]>;
|
|
21
|
+
/**
|
|
22
|
+
* Fires with a {@link DtlsAlertError} when the connection ends with a fatal
|
|
23
|
+
* alert (received from the peer, or sent by this side when it rejected the
|
|
24
|
+
* peer certificate), and with other errors raised by the handshake.
|
|
25
|
+
*/
|
|
17
26
|
readonly onError: Event<[Error]>;
|
|
27
|
+
/** Fires once when the peer closed the connection with close_notify. */
|
|
18
28
|
readonly onClose: Event<any[]>;
|
|
29
|
+
/** Fires for every alert received from the peer (before onClose / onError). */
|
|
30
|
+
readonly onAlert: Event<[DtlsAlert]>;
|
|
19
31
|
readonly transport: TransportContext;
|
|
20
32
|
cipher: CipherContext;
|
|
21
33
|
dtls: DtlsContext;
|
|
@@ -24,15 +36,125 @@ export declare class DtlsSocket {
|
|
|
24
36
|
extensions: Extension[];
|
|
25
37
|
onHandleHandshakes: (assembled: FragmentedHandshake[]) => Promise<void>;
|
|
26
38
|
private bufferFragmentedHandshakes;
|
|
39
|
+
/** close_notify or a fatal alert was sent: no record is sent any more. */
|
|
40
|
+
private alertSent;
|
|
41
|
+
/** The alert that is being sent (shared with concurrent close calls). */
|
|
42
|
+
private alertSending?;
|
|
43
|
+
/**
|
|
44
|
+
* The connection ended (close_notify / fatal alert sent or received, or
|
|
45
|
+
* close()): received records are no longer processed.
|
|
46
|
+
*/
|
|
47
|
+
private ended;
|
|
27
48
|
constructor(options: Options, sessionType: SessionTypes);
|
|
28
49
|
renegotiation(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves once the alert being sent (e.g. the close_notify answering the
|
|
52
|
+
* peer's) has been handed to the transport or timed out. Resolves
|
|
53
|
+
* immediately when none is in flight. Never rejects.
|
|
54
|
+
*/
|
|
55
|
+
alertFlushed(): Promise<void>;
|
|
56
|
+
/** Whether the connection ended (alert, or close()). */
|
|
57
|
+
get terminated(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the handshake must not go on: the connection ended, or this side
|
|
60
|
+
* sent close_notify (RFC 5246 §7.2.1: nothing is sent after it, so a
|
|
61
|
+
* handshake that would answer or complete stops; records received after it
|
|
62
|
+
* are still processed, to receive the peer's close_notify).
|
|
63
|
+
*/
|
|
64
|
+
protected get handshakeStopped(): boolean;
|
|
29
65
|
private udpOnMessage;
|
|
66
|
+
/**
|
|
67
|
+
* Run the listeners of an event this socket reports, each isolated
|
|
68
|
+
* (`Event.executeIsolated`): a listener's exception is logged, so an
|
|
69
|
+
* application listener can never interrupt the socket's own processing
|
|
70
|
+
* (ending the connection, closing the transport, the receive loop) nor
|
|
71
|
+
* skip a listener registered after it.
|
|
72
|
+
*/
|
|
73
|
+
protected notify<T extends any[]>(event: Event<T>, ...args: T): void;
|
|
74
|
+
/**
|
|
75
|
+
* RFC 5246 §7.2: react to an alert received from the peer. The connection
|
|
76
|
+
* is ended (flights stopped, close_notify answered or the transport
|
|
77
|
+
* closed) before any listener runs, and each notification is isolated, so
|
|
78
|
+
* a throwing listener does not leave the socket ended but unreported.
|
|
79
|
+
*/
|
|
80
|
+
private handleAlert;
|
|
81
|
+
/**
|
|
82
|
+
* Send an alert to the peer, protected with the current epoch (plaintext
|
|
83
|
+
* before ChangeCipherSpec, encrypted after it).
|
|
84
|
+
*
|
|
85
|
+
* Resolves once the transport has sent the record, or after `timeoutMs`
|
|
86
|
+
* (default {@link DtlsSocket.AlertSendTimeoutMs}). It never rejects: a
|
|
87
|
+
* failed send is only logged. Nothing is sent once close_notify or a fatal
|
|
88
|
+
* alert has been sent or the transport is closed. Sending close_notify or a
|
|
89
|
+
* fatal alert also stops the handshake flights (no retransmission). The
|
|
90
|
+
* record is handed to the transport synchronously, so closing the socket
|
|
91
|
+
* right after calling this does not drop it.
|
|
92
|
+
*
|
|
93
|
+
* A fatal alert ends the connection like a fatal error this side detected
|
|
94
|
+
* itself: `onError` fires synchronously with a local {@link DtlsAlertError},
|
|
95
|
+
* and the transport is closed once the alert has been sent (the returned
|
|
96
|
+
* promise resolves after that).
|
|
97
|
+
*/
|
|
98
|
+
sendAlert(level: AlertLevel, description: AlertDesc, options?: {
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
}): Promise<void>;
|
|
101
|
+
/** Encode, protect and send one alert record (see {@link sendAlert}). */
|
|
102
|
+
private transmitAlert;
|
|
103
|
+
/**
|
|
104
|
+
* Abort the handshake (or the connection) because this side detected a
|
|
105
|
+
* fatal error: see {@link endWithFatalAlert}.
|
|
106
|
+
*/
|
|
107
|
+
protected abortWithFatalAlert(description: AlertDesc, reason?: unknown): void;
|
|
108
|
+
/**
|
|
109
|
+
* The single ending path for a fatal alert sent by this side (the public
|
|
110
|
+
* {@link sendAlert} and an internal abort): send the alert, stop the
|
|
111
|
+
* flights, report a local {@link DtlsAlertError} on onError (once), and
|
|
112
|
+
* close the transport once the alert has been sent or timed out. Does
|
|
113
|
+
* nothing more once the connection already ended.
|
|
114
|
+
*/
|
|
115
|
+
private endWithFatalAlert;
|
|
116
|
+
/**
|
|
117
|
+
* Call `options.verifyRemoteCertificate` with the received peer
|
|
118
|
+
* certificate. When it returns false or throws, the handshake is aborted
|
|
119
|
+
* with a fatal bad_certificate alert and false is returned.
|
|
120
|
+
*/
|
|
121
|
+
protected verifyRemoteCertificate(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Close the transport (once; concurrent callers share the same close) and
|
|
124
|
+
* resolve when it has closed. A failure (a rejection or a synchronous
|
|
125
|
+
* throw of the transport's close()) is only logged: it never interrupts
|
|
126
|
+
* the caller, e.g. the onError notification of a received fatal alert.
|
|
127
|
+
*/
|
|
128
|
+
private closeTransport;
|
|
30
129
|
private setupExtensions;
|
|
31
130
|
protected waitForReady: (condition: () => boolean) => Promise<void>;
|
|
32
131
|
handleFragmentHandshake(messages: FragmentedHandshake[]): FragmentedHandshake[];
|
|
33
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* send application data. Nothing is sent once close_notify or a fatal
|
|
134
|
+
* alert has been sent or received.
|
|
135
|
+
*/
|
|
34
136
|
send: (buf: Buffer, addr?: Address) => Promise<void>;
|
|
35
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Close the socket: received records are no longer processed and a
|
|
139
|
+
* handshake flight stops retransmitting.
|
|
140
|
+
*
|
|
141
|
+
* - `close()`: sends no alert of its own and closes the transport right
|
|
142
|
+
* away, except that an alert already being sent (`sendAlert()`, the
|
|
143
|
+
* close_notify answering the peer's) is let through first: the transport
|
|
144
|
+
* closes once it has been sent or timed out.
|
|
145
|
+
* - `close({ notify: true })`: sends close_notify first and closes the
|
|
146
|
+
* transport once it has been sent, or after `timeoutMs`
|
|
147
|
+
* (default {@link DtlsSocket.AlertSendTimeoutMs}).
|
|
148
|
+
*
|
|
149
|
+
* The returned promise resolves once the transport is closed (also when
|
|
150
|
+
* the close was already started, e.g. after a fatal alert: it waits for
|
|
151
|
+
* that close) and never rejects; a failing transport close() (a rejection
|
|
152
|
+
* or a synchronous throw) is only logged.
|
|
153
|
+
*/
|
|
154
|
+
close(options?: {
|
|
155
|
+
notify?: boolean;
|
|
156
|
+
timeoutMs?: number;
|
|
157
|
+
}): Promise<void>;
|
|
36
158
|
extractSessionKeys(keyLength: number, saltLength: number): {
|
|
37
159
|
localKey: Buffer<ArrayBufferLike>;
|
|
38
160
|
localSalt: Buffer<ArrayBufferLike>;
|
|
@@ -50,4 +172,14 @@ export interface Options {
|
|
|
50
172
|
signatureHash?: SignatureHash;
|
|
51
173
|
certificateRequest?: boolean;
|
|
52
174
|
extendedMasterSecret?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Verify the peer certificate (DER) during the handshake. Returning false
|
|
177
|
+
* or throwing aborts the handshake with a fatal bad_certificate alert, so
|
|
178
|
+
* the peer learns the failure before it considers the connection
|
|
179
|
+
* established: the client checks the server certificate before sending
|
|
180
|
+
* flight 5, the server checks the client certificate before sending its
|
|
181
|
+
* Finished. onError receives a {@link DtlsAlertError} with
|
|
182
|
+
* `source: "local"`.
|
|
183
|
+
*/
|
|
184
|
+
verifyRemoteCertificate?: (certificate: Buffer) => boolean;
|
|
53
185
|
}
|