werift 0.15.2 → 0.15.5
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/lib/common/src/index.js +5 -1
- package/lib/common/src/index.js.map +1 -1
- package/lib/common/src/promise.d.ts +4 -3
- package/lib/common/src/promise.js +11 -5
- package/lib/common/src/promise.js.map +1 -1
- package/lib/dtls/src/cipher/namedCurve.js +5 -1
- package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +5 -1
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/suites/aead.js +5 -1
- package/lib/dtls/src/cipher/suites/aead.js.map +1 -1
- package/lib/dtls/src/context/cipher.js +5 -1
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/ice/src/dns/lookup.d.ts +9 -0
- package/lib/ice/src/dns/lookup.js +66 -0
- package/lib/ice/src/dns/lookup.js.map +1 -0
- package/lib/ice/src/ice.d.ts +2 -0
- package/lib/ice/src/ice.js +28 -24
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/index.js +5 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/stun/attributes.js +5 -1
- package/lib/ice/src/stun/attributes.js.map +1 -1
- package/lib/rtp/src/container/webm.js +5 -1
- package/lib/rtp/src/container/webm.js.map +1 -1
- package/lib/rtp/src/index.js +5 -1
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/webrtc/src/index.js +5 -1
- package/lib/webrtc/src/index.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.js +1 -1
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.js +5 -1
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +3 -1
- package/lib/webrtc/src/media/rtpTransceiver.js +12 -2
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +6 -2
- package/lib/webrtc/src/peerConnection.js +126 -52
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +0 -2
- package/lib/webrtc/src/sdp.js +0 -7
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +7 -1
- package/lib/webrtc/src/transport/ice.js +12 -3
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +2 -1
- package/lib/webrtc/src/transport/sctp.js +6 -2
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/package.json +9 -19
- package/src/media/rtpReceiver.ts +1 -1
- package/src/media/rtpTransceiver.ts +7 -1
- package/src/peerConnection.ts +197 -124
- package/src/sdp.ts +0 -8
- package/src/transport/ice.ts +13 -3
- package/src/transport/sctp.ts +2 -1
package/lib/common/src/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../common/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../common/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,4CAA0B","sourcesContent":["export * from \"./binary\";\nexport * from \"./number\";\nexport * from \"./promise\";\nexport * from \"./network\";\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare class PromiseQueue {
|
|
2
2
|
queue: {
|
|
3
|
-
promise: () => Promise<
|
|
4
|
-
done: () => void;
|
|
3
|
+
promise: () => Promise<unknown>;
|
|
4
|
+
done: (...args: any[]) => void;
|
|
5
|
+
failed: (...args: any[]) => void;
|
|
5
6
|
}[];
|
|
6
7
|
running: boolean;
|
|
7
|
-
push: (promise: () => Promise<
|
|
8
|
+
push: <T>(promise: () => Promise<T>) => Promise<T>;
|
|
8
9
|
private run;
|
|
9
10
|
}
|
|
@@ -5,18 +5,24 @@ class PromiseQueue {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
this.queue = [];
|
|
7
7
|
this.running = false;
|
|
8
|
-
this.push = (promise) => new Promise((r) => {
|
|
9
|
-
this.queue.push({ promise, done: r });
|
|
10
|
-
if (!this.running)
|
|
8
|
+
this.push = (promise) => new Promise((r, f) => {
|
|
9
|
+
this.queue.push({ promise, done: r, failed: f });
|
|
10
|
+
if (!this.running) {
|
|
11
11
|
this.run();
|
|
12
|
+
}
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
async run() {
|
|
15
16
|
const task = this.queue.shift();
|
|
16
17
|
if (task) {
|
|
17
18
|
this.running = true;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
try {
|
|
20
|
+
const res = await task.promise();
|
|
21
|
+
task.done(res);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
task.failed(error);
|
|
25
|
+
}
|
|
20
26
|
this.run();
|
|
21
27
|
}
|
|
22
28
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../../../common/src/promise.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAAzB;QACE,UAAK,
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../../../common/src/promise.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAAzB;QACE,UAAK,GAIC,EAAE,CAAC;QACT,YAAO,GAAG,KAAK,CAAC;QAEhB,SAAI,GAAG,CAAI,OAAyB,EAAE,EAAE,CACtC,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,IAAI,CAAC,GAAG,EAAE,CAAC;aACZ;QACH,CAAC,CAAC,CAAC;IAmBP,CAAC;IAjBS,KAAK,CAAC,GAAG;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAChB;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACpB;YAED,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACtB;IACH,CAAC;CACF;AAjCD,oCAiCC","sourcesContent":["export class PromiseQueue {\n queue: {\n promise: () => Promise<unknown>;\n done: (...args: any[]) => void;\n failed: (...args: any[]) => void;\n }[] = [];\n running = false;\n\n push = <T>(promise: () => Promise<T>) =>\n new Promise<T>((r, f) => {\n this.queue.push({ promise, done: r, failed: f });\n if (!this.running) {\n this.run();\n }\n });\n\n private async run() {\n const task = this.queue.shift();\n if (task) {\n this.running = true;\n\n try {\n const res = await task.promise();\n task.done(res);\n } catch (error) {\n task.failed(error);\n }\n\n this.run();\n } else {\n this.running = false;\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namedCurve.js","sourceRoot":"","sources":["../../../../../dtls/src/cipher/namedCurve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"namedCurve.js","sourceRoot":"","sources":["../../../../../dtls/src/cipher/namedCurve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA8B;AAC9B,gDAAkC;AAElC,mCAAoE;AAQpE,SAAgB,eAAe,CAC7B,UAAgC;IAEhC,QAAQ,UAAU,EAAE;QAClB,KAAK,2BAAmB,CAAC,YAAY,CAAC,CAAC;YACrC,MAAM,QAAQ,GAAG,IAAI,aAAE,CAAC,MAAM,CAAC,CAAC;YAChC,MAAM,GAAG,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC;YAClC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAEtE,OAAO;gBACL,KAAK,EAAE,UAAU;gBACjB,UAAU;gBACV,SAAS;aACV,CAAC;SACH;QACD,KAAK,2BAAmB,CAAC,SAAS,CAAC,CAAC;YAClC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YAEhC,OAAO;gBACL,KAAK,EAAE,UAAU;gBACjB,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC9C,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;aAC9C,CAAC;SACH;QACD;YACE,MAAM,IAAI,KAAK,EAAE,CAAC;KACrB;AACH,CAAC;AA5BD,0CA4BC","sourcesContent":["import { ec } from \"elliptic\";\nimport * as nacl from \"tweetnacl\";\n\nimport { NamedCurveAlgorithm, NamedCurveAlgorithms } from \"./const\";\n\nexport interface NamedCurveKeyPair {\n curve: NamedCurveAlgorithms;\n publicKey: Buffer;\n privateKey: Buffer;\n}\n\nexport function generateKeyPair(\n namedCurve: NamedCurveAlgorithms\n): NamedCurveKeyPair {\n switch (namedCurve) {\n case NamedCurveAlgorithm.secp256r1_23: {\n const elliptic = new ec(\"p256\");\n const key = elliptic.genKeyPair();\n const privateKey = key.getPrivate().toBuffer(\"be\");\n const publicKey = Buffer.from(key.getPublic().encode(\"array\", false));\n\n return {\n curve: namedCurve,\n privateKey,\n publicKey,\n };\n }\n case NamedCurveAlgorithm.x25519_29: {\n const keys = nacl.box.keyPair();\n\n return {\n curve: namedCurve,\n privateKey: Buffer.from(keys.secretKey.buffer),\n publicKey: Buffer.from(keys.publicKey.buffer),\n };\n }\n default:\n throw new Error();\n }\n}\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prf.js","sourceRoot":"","sources":["../../../../../dtls/src/cipher/prf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prf.js","sourceRoot":"","sources":["../../../../../dtls/src/cipher/prf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2C;AAC3C,mCAAgD;AAChD,uCAA8B;AAC9B,gDAAkC;AAElC,mCAAoE;AAEpE,SAAgB,kBAAkB,CAChC,SAAiB,EACjB,UAAkB,EAClB,KAA2B;IAE3B,QAAQ,KAAK,EAAE;QACb,KAAK,2BAAmB,CAAC,YAAY;YACnC,MAAM,QAAQ,GAAG,IAAI,aAAE,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB;YACjD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC;YAC1D,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,CAAC;YAC9D,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,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,CAAC,CAAC;IACpD,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAEpD,MAAM,mBAAmB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,mBAAmB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACjD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAEjD,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACzC,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAEzC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACtE,CAAC;AAjCD,8CAiCC","sourcesContent":["import { createDecode } from \"binary-data\";\nimport { createHash, createHmac } from \"crypto\";\nimport { ec } from \"elliptic\";\nimport * as nacl from \"tweetnacl\";\n\nimport { NamedCurveAlgorithm, NamedCurveAlgorithms } from \"./const\";\n\nexport function prfPreMasterSecret(\n publicKey: Buffer,\n privateKey: Buffer,\n curve: NamedCurveAlgorithms\n) {\n switch (curve) {\n case NamedCurveAlgorithm.secp256r1_23:\n const elliptic = new ec(\"p256\"); // aka secp256r1\n const pub = elliptic.keyFromPublic(publicKey).getPublic();\n const priv = elliptic.keyFromPrivate(privateKey).getPrivate();\n const res = pub.mul(priv);\n const secret = Buffer.from(res.encode(\"array\", false)).slice(1, 33);\n return secret;\n case NamedCurveAlgorithm.x25519_29:\n return Buffer.from(nacl.scalarMult(privateKey, publicKey));\n default:\n throw new Error();\n }\n}\n\nexport function hmac(algorithm: string, secret: Buffer, data: Buffer) {\n const hash = createHmac(algorithm, secret);\n hash.update(data);\n return hash.digest();\n}\n\nexport function prfPHash(\n secret: Buffer,\n seed: Buffer,\n requestedLegth: number,\n algorithm = \"sha256\"\n) {\n const totalLength = requestedLegth;\n const bufs: Buffer[] = [];\n let Ai = seed; // A0\n\n do {\n Ai = hmac(algorithm, secret, Ai); // A(i) = HMAC(secret, A(i-1))\n const output = hmac(algorithm, secret, Buffer.concat([Ai, seed]));\n\n bufs.push(output);\n requestedLegth -= output.length; // eslint-disable-line no-param-reassign\n } while (requestedLegth > 0);\n\n return Buffer.concat(bufs, totalLength);\n}\n\nexport function prfMasterSecret(\n preMasterSecret: Buffer,\n clientRandom: Buffer,\n serverRandom: Buffer\n) {\n const seed = Buffer.concat([\n Buffer.from(\"master secret\"),\n clientRandom,\n serverRandom,\n ]);\n return prfPHash(preMasterSecret, seed, 48);\n}\n\nexport function prfExtendedMasterSecret(\n preMasterSecret: Buffer,\n handshakes: Buffer\n) {\n const sessionHash = hash(\"sha256\", handshakes);\n const label = \"extended master secret\";\n return prfPHash(\n preMasterSecret,\n Buffer.concat([Buffer.from(label), sessionHash]),\n 48\n );\n}\n\nexport function exportKeyingMaterial(\n label: string,\n length: number,\n masterSecret: Buffer,\n localRandom: Buffer,\n remoteRandom: Buffer,\n isClient: boolean\n) {\n const clientRandom = isClient ? localRandom : remoteRandom;\n const serverRandom = isClient ? remoteRandom : localRandom;\n const seed = Buffer.concat([Buffer.from(label), clientRandom, serverRandom]);\n return prfPHash(masterSecret, seed, length);\n}\n\nexport function hash(algorithm: string, data: Buffer) {\n return createHash(algorithm).update(data).digest();\n}\n\nexport function prfVerifyData(\n masterSecret: Buffer,\n handshakes: Buffer,\n label: string,\n size = 12\n) {\n const bytes = hash(\"sha256\", handshakes);\n return prfPHash(\n masterSecret,\n Buffer.concat([Buffer.from(label), bytes]),\n size\n );\n}\n\nexport function prfVerifyDataClient(masterSecret: Buffer, handshakes: Buffer) {\n return prfVerifyData(masterSecret, handshakes, \"client finished\");\n}\n\nexport function prfVerifyDataServer(masterSecret: Buffer, handshakes: Buffer) {\n return prfVerifyData(masterSecret, handshakes, \"server finished\");\n}\n\nexport function prfEncryptionKeys(\n masterSecret: Buffer,\n clientRandom: Buffer,\n serverRandom: Buffer,\n prfKeyLen: number,\n prfIvLen: number,\n prfNonceLen: number,\n algorithm = \"sha256\"\n) {\n const size = prfKeyLen * 2 + prfIvLen * 2;\n const secret = masterSecret;\n const seed = Buffer.concat([serverRandom, clientRandom]);\n const keyBlock = prfPHash(\n secret,\n Buffer.concat([Buffer.from(\"key expansion\"), seed]),\n size,\n algorithm\n );\n const stream = createDecode(keyBlock);\n\n const clientWriteKey = stream.readBuffer(prfKeyLen);\n const serverWriteKey = stream.readBuffer(prfKeyLen);\n\n const clientNonceImplicit = stream.readBuffer(prfIvLen);\n const serverNonceImplicit = stream.readBuffer(prfIvLen);\n\n const clientNonce = Buffer.alloc(prfNonceLen, 0);\n const serverNonce = Buffer.alloc(prfNonceLen, 0);\n\n clientNonceImplicit.copy(clientNonce, 0);\n serverNonceImplicit.copy(serverNonce, 0);\n\n return { clientWriteKey, serverWriteKey, clientNonce, serverNonce };\n}\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aead.js","sourceRoot":"","sources":["../../../../../../dtls/src/cipher/suites/aead.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":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6BA+IC","sourcesContent":["import * as crypto from \"crypto\";\nimport debug from \"debug\";\n\nimport { dumpBuffer, getObjectSummary } from \"../../helper\";\nimport { prfEncryptionKeys } from \"../prf\";\nimport Cipher, { CipherHeader, SessionType, SessionTypes } from \"./abstract\";\nconst {\n createDecode,\n encode,\n types: { uint8, uint16be, uint48be },\n} = require(\"binary-data\");\n\nconst ContentType = uint8;\nconst ProtocolVersion = uint16be;\n\nconst AEADAdditionalData = {\n epoch: uint16be,\n sequence: uint48be,\n type: ContentType,\n version: ProtocolVersion,\n length: uint16be,\n};\n\nconst err = debug(\n \"werift-dtls : packages/dtls/src/cipher/suites/aead.ts : err\"\n);\n\n/**\n * This class implements AEAD cipher family.\n */\nexport default class AEADCipher extends Cipher {\n keyLength = 0;\n nonceLength = 0;\n ivLength = 0;\n authTagLength = 0;\n\n nonceImplicitLength = 0;\n nonceExplicitLength = 0;\n\n clientWriteKey?: Buffer;\n serverWriteKey?: Buffer;\n\n clientNonce?: Buffer;\n serverNonce?: Buffer;\n\n constructor() {\n super();\n }\n\n get summary() {\n return getObjectSummary(this);\n }\n\n init(masterSecret: Buffer, serverRandom: Buffer, clientRandom: Buffer) {\n const keys = prfEncryptionKeys(\n masterSecret,\n clientRandom,\n serverRandom,\n this.keyLength,\n this.ivLength,\n this.nonceLength,\n this.hashAlgorithm\n );\n\n this.clientWriteKey = keys.clientWriteKey;\n this.serverWriteKey = keys.serverWriteKey;\n this.clientNonce = keys.clientNonce;\n this.serverNonce = keys.serverNonce;\n }\n\n /**\n * Encrypt message.\n */\n encrypt(type: SessionTypes, data: Buffer, header: CipherHeader) {\n const isClient = type === SessionType.CLIENT;\n const iv = isClient ? this.clientNonce : this.serverNonce;\n const writeKey = isClient ? this.clientWriteKey : this.serverWriteKey;\n if (!iv || !writeKey) throw new Error();\n\n iv.writeUInt16BE(header.epoch, this.nonceImplicitLength);\n iv.writeUIntBE(header.sequenceNumber, this.nonceImplicitLength + 2, 6);\n\n const explicitNonce = iv.slice(this.nonceImplicitLength);\n\n const additionalData = {\n epoch: header.epoch,\n sequence: header.sequenceNumber,\n type: header.type,\n version: header.version,\n length: data.length,\n };\n\n const additionalBuffer = encode(additionalData, AEADAdditionalData).slice();\n\n const cipher = crypto.createCipheriv(\n this.blockAlgorithm as crypto.CipherCCMTypes,\n writeKey,\n iv,\n {\n authTagLength: this.authTagLength,\n }\n );\n\n cipher.setAAD(additionalBuffer, {\n plaintextLength: data.length,\n });\n\n const headPart = cipher.update(data);\n const finalPart = cipher.final();\n const authTag = cipher.getAuthTag();\n\n return Buffer.concat([explicitNonce, headPart, finalPart, authTag]);\n }\n\n /**\n * Decrypt message.\n */\n decrypt(type: SessionTypes, data: Buffer, header: CipherHeader) {\n const isClient = type === SessionType.CLIENT;\n const iv = isClient ? this.serverNonce : this.clientNonce;\n const writeKey = isClient ? this.serverWriteKey : this.clientWriteKey;\n if (!iv || !writeKey) throw new Error();\n\n const final = createDecode(data);\n\n const explicitNonce = final.readBuffer(this.nonceExplicitLength);\n explicitNonce.copy(iv, this.nonceImplicitLength);\n\n const encrypted = final.readBuffer(final.length - this.authTagLength);\n const authTag = final.readBuffer(this.authTagLength);\n\n const additionalData = {\n epoch: header.epoch,\n sequence: header.sequenceNumber,\n type: header.type,\n version: header.version,\n length: encrypted.length,\n };\n\n const additionalBuffer = encode(additionalData, AEADAdditionalData).slice();\n\n const decipher = crypto.createDecipheriv(\n this.blockAlgorithm as crypto.CipherCCMTypes,\n writeKey,\n iv,\n {\n authTagLength: this.authTagLength,\n }\n );\n\n decipher.setAuthTag(authTag);\n decipher.setAAD(additionalBuffer, {\n plaintextLength: encrypted.length,\n });\n\n const headPart = decipher.update(encrypted);\n try {\n const finalPart = decipher.final();\n return finalPart.length > 0\n ? Buffer.concat([headPart, finalPart])\n : headPart;\n } catch (error) {\n err(\n \"decrypt failed\",\n error,\n type,\n dumpBuffer(data),\n header,\n this.summary\n );\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cipher.js","sourceRoot":"","sources":["../../../../../dtls/src/context/cipher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqD;AACrD,mDAA6C;AAC7C,qDAAuC;AACvC,6CAAoD;AACpD,mCAAoC;AACpC,iEAAyC;AAEzC,2CAQyB;AAEzB,uCAAyE;AACzE,wDAAsE;AAEtE,gDAAsD;AAItD,MAAM,MAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;AAC5B,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAa,CAAC,CAAC;AAEvC,MAAa,aAAa;IAcxB,YACS,WAAyB,EACzB,OAAgB,EAChB,MAAe,EACtB,sBAAsC;QAH/B,gBAAW,GAAX,WAAW,CAAc;QACzB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAS;QAGtB,IAAI,OAAO,IAAI,MAAM,IAAI,sBAAsB,EAAE;YAC/C,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;SACzD;IACH,CAAC;IA2ED,aAAa,CAAC,GAAkB;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CA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AE,EAAE,EAAE,CAAC;QAClC,gBAAgB,EAAE,GAAG;QACrB,IAAI;KACL,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CACrC,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,UAAiB,CAAC,EAC9D,aAAa,CACd,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAC5C,CAAE,CAAA","sourcesContent":["import { Certificate, PrivateKey } from \"@fidm/x509\";\nimport { Crypto } from \"@peculiar/webcrypto\";\nimport * as x509 from \"@peculiar/x509\";\nimport { decode, encode, types } from \"binary-data\";\nimport { createSign } from \"crypto\";\nimport addYears from \"date-fns/addYears\";\n\nimport {\n CipherSuites,\n CurveType,\n HashAlgorithm,\n NamedCurveAlgorithm,\n NamedCurveAlgorithms,\n SignatureAlgorithm,\n SignatureHash,\n} from \"../cipher/const\";\nimport { NamedCurveKeyPair } from \"../cipher/namedCurve\";\nimport { prfVerifyDataClient, prfVerifyDataServer } from \"../cipher/prf\";\nimport { SessionType, SessionTypes } from \"../cipher/suites/abstract\";\nimport AEADCipher from \"../cipher/suites/aead\";\nimport { ProtocolVersion } from \"../handshake/binary\";\nimport { DtlsRandom } from \"../handshake/random\";\nimport { DtlsPlaintext } from \"../record/message/plaintext\";\n\nconst crypto = new Crypto();\nx509.cryptoProvider.set(crypto as any);\n\nexport class CipherContext {\n localRandom!: DtlsRandom;\n remoteRandom!: DtlsRandom;\n cipherSuite!: CipherSuites;\n remoteCertificate?: Buffer;\n remoteKeyPair!: Partial<NamedCurveKeyPair>;\n localKeyPair!: NamedCurveKeyPair;\n masterSecret!: Buffer;\n cipher!: AEADCipher;\n namedCurve!: NamedCurveAlgorithms;\n signatureHashAlgorithm?: SignatureHash;\n localCert!: Buffer;\n localPrivateKey!: PrivateKey;\n\n constructor(\n public sessionType: SessionTypes,\n public certPem?: string,\n public keyPem?: string,\n signatureHashAlgorithm?: SignatureHash\n ) {\n if (certPem && keyPem && signatureHashAlgorithm) {\n this.parseX509(certPem, keyPem, signatureHashAlgorithm);\n }\n }\n\n /**\n *\n * @param signatureHash\n * @param namedCurveAlgorithm necessary when use ecdsa\n */\n static createSelfSignedCertificateWithKey = async (\n signatureHash: SignatureHash,\n namedCurveAlgorithm?: NamedCurveAlgorithms\n ) => {\n const signatureAlgorithmName = (() => {\n switch (signatureHash.signature) {\n case SignatureAlgorithm.rsa_1:\n return \"RSASSA-PKCS1-v1_5\";\n case SignatureAlgorithm.ecdsa_3:\n return \"ECDSA\";\n }\n })();\n const hash = (() => {\n switch (signatureHash.hash) {\n case HashAlgorithm.sha256_4:\n return \"SHA-256\";\n }\n })();\n const namedCurve = (() => {\n switch (namedCurveAlgorithm) {\n case NamedCurveAlgorithm.secp256r1_23:\n return \"P-256\";\n case NamedCurveAlgorithm.x25519_29:\n // todo fix (X25519 not supported with ECDSA)\n if (signatureAlgorithmName === \"ECDSA\") {\n return \"P-256\";\n }\n return \"X25519\";\n default: {\n if (signatureAlgorithmName === \"ECDSA\") return \"P-256\";\n if (signatureAlgorithmName === \"RSASSA-PKCS1-v1_5\") return \"X25519\";\n }\n }\n })();\n const alg = (() => {\n switch (signatureAlgorithmName) {\n case \"ECDSA\":\n return { name: signatureAlgorithmName, hash, namedCurve };\n case \"RSASSA-PKCS1-v1_5\":\n return {\n name: signatureAlgorithmName,\n hash,\n publicExponent: new Uint8Array([1, 0, 1]),\n modulusLength: 2048,\n };\n }\n })();\n\n const keys = await crypto.subtle.generateKey(alg, true, [\"sign\", \"verify\"]);\n\n const cert = await x509.X509CertificateGenerator.createSelfSigned({\n serialNumber: \"01\",\n name: \"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd\",\n notBefore: new Date(),\n notAfter: addYears(Date.now(), 10),\n signingAlgorithm: alg,\n keys,\n });\n\n const certPem = cert.toString(\"pem\");\n const keyPem = x509.PemConverter.encode(\n await crypto.subtle.exportKey(\"pkcs8\", keys.privateKey as any),\n \"private key\"\n );\n\n return { certPem, keyPem, signatureHash };\n };\n\n encryptPacket(pkt: DtlsPlaintext) {\n const header = pkt.recordLayerHeader;\n const enc = this.cipher.encrypt(this.sessionType, pkt.fragment, {\n type: header.contentType,\n version: decode(\n Buffer.from(encode(header.protocolVersion, ProtocolVersion).slice()),\n { version: types.uint16be }\n ).version,\n epoch: header.epoch,\n sequenceNumber: header.sequenceNumber,\n });\n pkt.fragment = enc;\n pkt.recordLayerHeader.contentLen = enc.length;\n return pkt;\n }\n\n decryptPacket(pkt: DtlsPlaintext) {\n const header = pkt.recordLayerHeader;\n const dec = this.cipher.decrypt(this.sessionType, pkt.fragment, {\n type: header.contentType,\n version: decode(\n Buffer.from(encode(header.protocolVersion, ProtocolVersion).slice()),\n { version: types.uint16be }\n ).version,\n epoch: header.epoch,\n sequenceNumber: header.sequenceNumber,\n });\n return dec;\n }\n\n verifyData(buf: Buffer) {\n if (this.sessionType === SessionType.CLIENT)\n return prfVerifyDataClient(this.masterSecret, buf);\n else return prfVerifyDataServer(this.masterSecret, buf);\n }\n\n signatureData(data: Buffer, hash: string) {\n const signature = createSign(hash).update(data);\n const key = this.localPrivateKey.toPEM().toString();\n const signed = signature.sign(key);\n return signed;\n }\n\n generateKeySignature(hashAlgorithm: string) {\n const clientRandom =\n this.sessionType === SessionType.CLIENT\n ? this.localRandom\n : this.remoteRandom;\n const serverRandom =\n this.sessionType === SessionType.SERVER\n ? this.localRandom\n : this.remoteRandom;\n\n const sig = this.valueKeySignature(\n clientRandom.serialize(),\n serverRandom.serialize(),\n this.localKeyPair.publicKey,\n this.namedCurve\n );\n\n const enc = this.localPrivateKey.sign(sig, hashAlgorithm);\n return enc;\n }\n\n parseX509(certPem: string, keyPem: string, signatureHash: SignatureHash) {\n const cert = Certificate.fromPEM(Buffer.from(certPem));\n const sec = PrivateKey.fromPEM(Buffer.from(keyPem));\n this.localCert = cert.raw;\n this.localPrivateKey = sec;\n this.signatureHashAlgorithm = signatureHash;\n }\n\n private valueKeySignature(\n clientRandom: Buffer,\n serverRandom: Buffer,\n publicKey: Buffer,\n namedCurve: number\n ) {\n const serverParams = Buffer.from(\n encode(\n {\n type: CurveType.named_curve_3,\n curve: namedCurve,\n len: publicKey.length,\n },\n { type: types.uint8, curve: types.uint16be, len: types.uint8 }\n ).slice()\n );\n return Buffer.concat([clientRandom, serverRandom, serverParams, publicKey]);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cipher.js","sourceRoot":"","sources":["../../../../../dtls/src/context/cipher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqD;AACrD,mDAA6C;AAC7C,qDAAuC;AACvC,6CAAoD;AACpD,mCAAoC;AACpC,iEAAyC;AAEzC,2CAQyB;AAEzB,uCAAyE;AACzE,wDAAsE;AAEtE,gDAAsD;AAItD,MAAM,MAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;AAC5B,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAa,CAAC,CAAC;AAEvC,MAAa,aAAa;IAcxB,YACS,WAAyB,EACzB,OAAgB,EAChB,MAAe,EACtB,sBAAsC;QAH/B,gBAAW,GAAX,WAAW,CAAc;QACzB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAS;QAGtB,IAAI,OAAO,IAAI,MAAM,IAAI,sBAAsB,EAAE;YAC/C,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;SACzD;IACH,CAAC;IA2ED,aAAa,CAAC,GAAkB;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,QAAQ,EAAE;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IAEH,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CACrC,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,UAAiB,CAAC,EAC9D,aAAa,CACd,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAC5C,CAAE,CAAA","sourcesContent":["import { Certificate, PrivateKey } from \"@fidm/x509\";\nimport { Crypto } from \"@peculiar/webcrypto\";\nimport * as x509 from \"@peculiar/x509\";\nimport { decode, encode, types } from \"binary-data\";\nimport { createSign } from \"crypto\";\nimport addYears from \"date-fns/addYears\";\n\nimport {\n CipherSuites,\n CurveType,\n HashAlgorithm,\n NamedCurveAlgorithm,\n NamedCurveAlgorithms,\n SignatureAlgorithm,\n SignatureHash,\n} from \"../cipher/const\";\nimport { NamedCurveKeyPair } from \"../cipher/namedCurve\";\nimport { prfVerifyDataClient, prfVerifyDataServer } from \"../cipher/prf\";\nimport { SessionType, SessionTypes } from \"../cipher/suites/abstract\";\nimport AEADCipher from \"../cipher/suites/aead\";\nimport { ProtocolVersion } from \"../handshake/binary\";\nimport { DtlsRandom } from \"../handshake/random\";\nimport { DtlsPlaintext } from \"../record/message/plaintext\";\n\nconst crypto = new Crypto();\nx509.cryptoProvider.set(crypto as any);\n\nexport class CipherContext {\n localRandom!: DtlsRandom;\n remoteRandom!: DtlsRandom;\n cipherSuite!: CipherSuites;\n remoteCertificate?: Buffer;\n remoteKeyPair!: Partial<NamedCurveKeyPair>;\n localKeyPair!: NamedCurveKeyPair;\n masterSecret!: Buffer;\n cipher!: AEADCipher;\n namedCurve!: NamedCurveAlgorithms;\n signatureHashAlgorithm?: SignatureHash;\n localCert!: Buffer;\n localPrivateKey!: PrivateKey;\n\n constructor(\n public sessionType: SessionTypes,\n public certPem?: string,\n public keyPem?: string,\n signatureHashAlgorithm?: SignatureHash\n ) {\n if (certPem && keyPem && signatureHashAlgorithm) {\n this.parseX509(certPem, keyPem, signatureHashAlgorithm);\n }\n }\n\n /**\n *\n * @param signatureHash\n * @param namedCurveAlgorithm necessary when use ecdsa\n */\n static createSelfSignedCertificateWithKey = async (\n signatureHash: SignatureHash,\n namedCurveAlgorithm?: NamedCurveAlgorithms\n ) => {\n const signatureAlgorithmName = (() => {\n switch (signatureHash.signature) {\n case SignatureAlgorithm.rsa_1:\n return \"RSASSA-PKCS1-v1_5\";\n case SignatureAlgorithm.ecdsa_3:\n return \"ECDSA\";\n }\n })();\n const hash = (() => {\n switch (signatureHash.hash) {\n case HashAlgorithm.sha256_4:\n return \"SHA-256\";\n }\n })();\n const namedCurve = (() => {\n switch (namedCurveAlgorithm) {\n case NamedCurveAlgorithm.secp256r1_23:\n return \"P-256\";\n case NamedCurveAlgorithm.x25519_29:\n // todo fix (X25519 not supported with ECDSA)\n if (signatureAlgorithmName === \"ECDSA\") {\n return \"P-256\";\n }\n return \"X25519\";\n default: {\n if (signatureAlgorithmName === \"ECDSA\") return \"P-256\";\n if (signatureAlgorithmName === \"RSASSA-PKCS1-v1_5\") return \"X25519\";\n }\n }\n })();\n const alg = (() => {\n switch (signatureAlgorithmName) {\n case \"ECDSA\":\n return { name: signatureAlgorithmName, hash, namedCurve };\n case \"RSASSA-PKCS1-v1_5\":\n return {\n name: signatureAlgorithmName,\n hash,\n publicExponent: new Uint8Array([1, 0, 1]),\n modulusLength: 2048,\n };\n }\n })();\n\n const keys = await crypto.subtle.generateKey(alg, true, [\"sign\", \"verify\"]);\n\n const cert = await x509.X509CertificateGenerator.createSelfSigned({\n serialNumber: \"01\",\n name: \"C=AU, ST=Some-State, O=Internet Widgits Pty Ltd\",\n notBefore: new Date(),\n notAfter: addYears(Date.now(), 10),\n signingAlgorithm: alg,\n keys,\n });\n\n const certPem = cert.toString(\"pem\");\n const keyPem = x509.PemConverter.encode(\n await crypto.subtle.exportKey(\"pkcs8\", keys.privateKey as any),\n \"private key\"\n );\n\n return { certPem, keyPem, signatureHash };\n };\n\n encryptPacket(pkt: DtlsPlaintext) {\n const header = pkt.recordLayerHeader;\n const enc = this.cipher.encrypt(this.sessionType, pkt.fragment, {\n type: header.contentType,\n version: decode(\n Buffer.from(encode(header.protocolVersion, ProtocolVersion).slice()),\n { version: types.uint16be }\n ).version,\n epoch: header.epoch,\n sequenceNumber: header.sequenceNumber,\n });\n pkt.fragment = enc;\n pkt.recordLayerHeader.contentLen = enc.length;\n return pkt;\n }\n\n decryptPacket(pkt: DtlsPlaintext) {\n const header = pkt.recordLayerHeader;\n const dec = this.cipher.decrypt(this.sessionType, pkt.fragment, {\n type: header.contentType,\n version: decode(\n Buffer.from(encode(header.protocolVersion, ProtocolVersion).slice()),\n { version: types.uint16be }\n ).version,\n epoch: header.epoch,\n sequenceNumber: header.sequenceNumber,\n });\n return dec;\n }\n\n verifyData(buf: Buffer) {\n if (this.sessionType === SessionType.CLIENT)\n return prfVerifyDataClient(this.masterSecret, buf);\n else return prfVerifyDataServer(this.masterSecret, buf);\n }\n\n signatureData(data: Buffer, hash: string) {\n const signature = createSign(hash).update(data);\n const key = this.localPrivateKey.toPEM().toString();\n const signed = signature.sign(key);\n return signed;\n }\n\n generateKeySignature(hashAlgorithm: string) {\n const clientRandom =\n this.sessionType === SessionType.CLIENT\n ? this.localRandom\n : this.remoteRandom;\n const serverRandom =\n this.sessionType === SessionType.SERVER\n ? this.localRandom\n : this.remoteRandom;\n\n const sig = this.valueKeySignature(\n clientRandom.serialize(),\n serverRandom.serialize(),\n this.localKeyPair.publicKey,\n this.namedCurve\n );\n\n const enc = this.localPrivateKey.sign(sig, hashAlgorithm);\n return enc;\n }\n\n parseX509(certPem: string, keyPem: string, signatureHash: SignatureHash) {\n const cert = Certificate.fromPEM(Buffer.from(certPem));\n const sec = PrivateKey.fromPEM(Buffer.from(keyPem));\n this.localCert = cert.raw;\n this.localPrivateKey = sec;\n this.signatureHashAlgorithm = signatureHash;\n }\n\n private valueKeySignature(\n clientRandom: Buffer,\n serverRandom: Buffer,\n publicKey: Buffer,\n namedCurve: number\n ) {\n const serverParams = Buffer.from(\n encode(\n {\n type: CurveType.named_curve_3,\n curve: namedCurve,\n len: publicKey.length,\n },\n { type: types.uint8, curve: types.uint16be, len: types.uint8 }\n ).slice()\n );\n return Buffer.concat([clientRandom, serverRandom, serverParams, publicKey]);\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import worker_thread from "worker_threads";
|
|
3
|
+
export declare class DnsLookup {
|
|
4
|
+
thread: worker_thread.Worker;
|
|
5
|
+
cache: Map<string, Promise<string>>;
|
|
6
|
+
constructor();
|
|
7
|
+
lookup(host: string): Promise<string>;
|
|
8
|
+
close(): Promise<number>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DnsLookup = void 0;
|
|
7
|
+
const worker_threads_1 = __importDefault(require("worker_threads"));
|
|
8
|
+
class DnsLookup {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.cache = new Map();
|
|
11
|
+
const lookupWorkerFunction = () => {
|
|
12
|
+
const worker_thread = global.require("worker_threads");
|
|
13
|
+
const { lookup } = global.require("dns");
|
|
14
|
+
const dnsLookup = (host) => lookup(host, (err, address, family) => {
|
|
15
|
+
const res = {
|
|
16
|
+
err: err?.message,
|
|
17
|
+
address,
|
|
18
|
+
family,
|
|
19
|
+
host,
|
|
20
|
+
};
|
|
21
|
+
worker_thread.parentPort?.postMessage(res);
|
|
22
|
+
process.exit();
|
|
23
|
+
});
|
|
24
|
+
worker_thread.parentPort?.on("message", (message) => {
|
|
25
|
+
const { host } = message;
|
|
26
|
+
dnsLookup(host);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const lookupEval = `(${lookupWorkerFunction})()`;
|
|
30
|
+
this.thread = new worker_threads_1.default.Worker(lookupEval, {
|
|
31
|
+
eval: true,
|
|
32
|
+
});
|
|
33
|
+
this.thread.setMaxListeners(100);
|
|
34
|
+
}
|
|
35
|
+
async lookup(host) {
|
|
36
|
+
let cached = this.cache.get(host);
|
|
37
|
+
if (cached) {
|
|
38
|
+
return cached;
|
|
39
|
+
}
|
|
40
|
+
cached = new Promise((r, f) => {
|
|
41
|
+
const exitListener = (exitCode) => f(new Error(`dns.lookup thread exited unexpectedly: ${exitCode}`));
|
|
42
|
+
const threadMessageListener = (result) => {
|
|
43
|
+
if (result.host !== host) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.thread.removeListener("message", threadMessageListener);
|
|
47
|
+
this.thread.removeListener("exit", exitListener);
|
|
48
|
+
if (!result.address)
|
|
49
|
+
return f(new Error(result.err || "dns.lookup thread unknown error"));
|
|
50
|
+
r(result.address);
|
|
51
|
+
};
|
|
52
|
+
this.thread.on("message", threadMessageListener);
|
|
53
|
+
this.thread.on("exit", exitListener);
|
|
54
|
+
this.thread.postMessage({
|
|
55
|
+
host,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
this.cache.set(host, cached);
|
|
59
|
+
return cached;
|
|
60
|
+
}
|
|
61
|
+
close() {
|
|
62
|
+
return this.thread.terminate();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.DnsLookup = DnsLookup;
|
|
66
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../../../../ice/src/dns/lookup.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA2C;AAY3C,MAAa,SAAS;IAIpB;QAFA,UAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;QAGzC,MAAM,oBAA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Y,GAAG,CAAC,QAAgB,EAAE,EAAE,CACxC,CAAC,CAAC,IAAI,KAAK,CAAC,0CAA0C,QAAQ,EAAE,CAAC,CAAC,CAAC;YAErE,MAAM,qBAAqB,GAAG,CAAC,MAAuB,EAAE,EAAE;gBACxD,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;oBACxB,OAAO;iBACR;gBAED,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;gBAEjD,IAAI,CAAC,MAAM,CAAC,OAAO;oBACjB,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,iCAAiC,CAAC,CAAC,CAAC;gBACvE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACpB,CAAC,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;YAErC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBACtB,IAAI;aACe,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AAzED,8BAyEC","sourcesContent":["import worker_thread from \"worker_threads\";\n\ninterface DnsLookupRequest {\n host: string;\n}\n\ninterface DnsLookupResult extends DnsLookupRequest {\n err?: string;\n address?: string;\n family?: number;\n}\n\nexport class DnsLookup {\n thread: worker_thread.Worker;\n cache = new Map<string, Promise<string>>();\n\n constructor() {\n const lookupWorkerFunction = () => {\n const worker_thread = global.require(\"worker_threads\");\n const { lookup } = global.require(\"dns\");\n\n const dnsLookup = (host: string) =>\n lookup(host, (err: Error, address: string, family: number) => {\n const res: DnsLookupResult = {\n err: err?.message,\n address,\n family,\n host,\n };\n worker_thread.parentPort?.postMessage(res);\n process.exit();\n });\n\n worker_thread.parentPort?.on(\"message\", (message: DnsLookupRequest) => {\n const { host } = message;\n dnsLookup(host);\n });\n };\n\n const lookupEval = `(${lookupWorkerFunction})()`;\n\n this.thread = new worker_thread.Worker(lookupEval, {\n eval: true,\n });\n\n this.thread.setMaxListeners(100);\n }\n\n async lookup(host: string): Promise<string> {\n let cached = this.cache.get(host);\n if (cached) {\n return cached;\n }\n cached = new Promise((r, f) => {\n const exitListener = (exitCode: number) =>\n f(new Error(`dns.lookup thread exited unexpectedly: ${exitCode}`));\n\n const threadMessageListener = (result: DnsLookupResult) => {\n if (result.host !== host) {\n return;\n }\n\n this.thread.removeListener(\"message\", threadMessageListener);\n this.thread.removeListener(\"exit\", exitListener);\n\n if (!result.address)\n return f(new Error(result.err || \"dns.lookup thread unknown error\"));\n r(result.address);\n };\n\n this.thread.on(\"message\", threadMessageListener);\n this.thread.on(\"exit\", exitListener);\n\n this.thread.postMessage({\n host,\n } as DnsLookupRequest);\n });\n\n this.cache.set(host, cached);\n return cached;\n }\n\n close() {\n return this.thread.terminate();\n }\n}\n"]}
|
package/lib/ice/src/ice.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import PCancelable from "p-cancelable";
|
|
3
3
|
import { Event } from "rx.mini";
|
|
4
4
|
import { Candidate } from "./candidate";
|
|
5
|
+
import { DnsLookup } from "./dns/lookup";
|
|
5
6
|
import { Future } from "./helper";
|
|
6
7
|
import { Message } from "./stun/message";
|
|
7
8
|
import { Address, Protocol } from "./types/model";
|
|
@@ -24,6 +25,7 @@ export declare class Connection {
|
|
|
24
25
|
_localCandidatesEnd: boolean;
|
|
25
26
|
_tieBreaker: BigInt;
|
|
26
27
|
state: IceState;
|
|
28
|
+
dnsLookup?: DnsLookup;
|
|
27
29
|
readonly onData: Event<[Buffer, number]>;
|
|
28
30
|
readonly stateChanged: Event<[IceState]>;
|
|
29
31
|
private _remoteCandidates;
|
package/lib/ice/src/ice.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -25,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
29
|
exports.validateAddress = exports.serverReflexiveCandidate = exports.getHostAddresses = exports.candidatePairPriority = exports.sortCandidatePairs = exports.validateRemoteCandidate = exports.CandidatePairState = exports.CandidatePair = exports.Connection = void 0;
|
|
26
30
|
const crypto_1 = require("crypto");
|
|
27
31
|
const debug_1 = __importDefault(require("debug"));
|
|
28
|
-
const dns_1 = __importDefault(require("dns"));
|
|
29
32
|
const int64_buffer_1 = require("int64-buffer");
|
|
30
33
|
const nodeIp = __importStar(require("ip"));
|
|
31
34
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
@@ -35,8 +38,8 @@ const os_1 = __importDefault(require("os"));
|
|
|
35
38
|
const p_cancelable_1 = __importDefault(require("p-cancelable"));
|
|
36
39
|
const rx_mini_1 = require("rx.mini");
|
|
37
40
|
const promises_1 = __importDefault(require("timers/promises"));
|
|
38
|
-
const util_1 = __importDefault(require("util"));
|
|
39
41
|
const candidate_1 = require("./candidate");
|
|
42
|
+
const lookup_1 = require("./dns/lookup");
|
|
40
43
|
const helper_1 = require("./helper");
|
|
41
44
|
const const_1 = require("./stun/const");
|
|
42
45
|
const message_1 = require("./stun/message");
|
|
@@ -242,8 +245,9 @@ class Connection {
|
|
|
242
245
|
const candidateAddress = [address, protocol.getExtraInfo()[1]];
|
|
243
246
|
protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "udp", candidateAddress[0]), component, "udp", (0, candidate_1.candidatePriority)(component, "host"), candidateAddress[0], candidateAddress[1], "host");
|
|
244
247
|
candidates.push(protocol.localCandidate);
|
|
245
|
-
if (cb)
|
|
248
|
+
if (cb) {
|
|
246
249
|
cb(protocol.localCandidate);
|
|
250
|
+
}
|
|
247
251
|
}
|
|
248
252
|
// # query STUN server for server-reflexive candidates (IPv4 only)
|
|
249
253
|
const stunServer = this.stunServer;
|
|
@@ -314,18 +318,17 @@ class Connection {
|
|
|
314
318
|
// # perform checks
|
|
315
319
|
// 5.8. Scheduling Checks
|
|
316
320
|
for (;;) {
|
|
321
|
+
if (this.state === "closed")
|
|
322
|
+
break;
|
|
317
323
|
if (!this.schedulingChecks())
|
|
318
324
|
break;
|
|
319
325
|
await promises_1.default.setTimeout(20);
|
|
320
326
|
}
|
|
321
327
|
// # wait for completion
|
|
322
|
-
let res;
|
|
323
|
-
|
|
328
|
+
let res = ICE_FAILED;
|
|
329
|
+
while (this.checkList.length > 0 && res === ICE_FAILED) {
|
|
324
330
|
res = await this.checkListState.get();
|
|
325
331
|
}
|
|
326
|
-
else {
|
|
327
|
-
res = ICE_FAILED;
|
|
328
|
-
}
|
|
329
332
|
// # cancel remaining checks
|
|
330
333
|
this.checkList.forEach((check) => check.handle?.cancel());
|
|
331
334
|
if (res !== ICE_COMPLETED) {
|
|
@@ -414,6 +417,7 @@ class Connection {
|
|
|
414
417
|
}
|
|
415
418
|
this.protocols = [];
|
|
416
419
|
this.localCandidates = [];
|
|
420
|
+
await this.dnsLookup?.close();
|
|
417
421
|
}
|
|
418
422
|
setState(state) {
|
|
419
423
|
this.state = state;
|
|
@@ -433,18 +437,17 @@ class Connection {
|
|
|
433
437
|
return;
|
|
434
438
|
}
|
|
435
439
|
if (remoteCandidate.host.includes(".local")) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
.
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
remoteCandidate.host =
|
|
440
|
+
try {
|
|
441
|
+
if (this.state === "closed")
|
|
442
|
+
return;
|
|
443
|
+
if (!this.dnsLookup) {
|
|
444
|
+
this.dnsLookup = new lookup_1.DnsLookup();
|
|
445
|
+
}
|
|
446
|
+
const host = await this.dnsLookup.lookup(remoteCandidate.host);
|
|
447
|
+
remoteCandidate.host = host;
|
|
444
448
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
remoteCandidate.host = "127.0.0.1";
|
|
449
|
+
catch (error) {
|
|
450
|
+
return;
|
|
448
451
|
}
|
|
449
452
|
}
|
|
450
453
|
try {
|
|
@@ -470,7 +473,8 @@ class Connection {
|
|
|
470
473
|
await activePair.protocol.sendData(data, activePair.remoteAddr);
|
|
471
474
|
}
|
|
472
475
|
else {
|
|
473
|
-
|
|
476
|
+
// log("Cannot send data, ice not connected");
|
|
477
|
+
return;
|
|
474
478
|
}
|
|
475
479
|
}
|
|
476
480
|
getDefaultCandidate(component) {
|
|
@@ -629,7 +633,6 @@ class Connection {
|
|
|
629
633
|
this.checkListState.put(new Promise((r) => {
|
|
630
634
|
r(ICE_FAILED);
|
|
631
635
|
}));
|
|
632
|
-
this.checkListDone = true;
|
|
633
636
|
}
|
|
634
637
|
}
|
|
635
638
|
// 7.2. STUN Server Procedures
|
|
@@ -770,11 +773,12 @@ exports.candidatePairPriority = candidatePairPriority;
|
|
|
770
773
|
function nodeIpAddress(family) {
|
|
771
774
|
// https://chromium.googlesource.com/external/webrtc/+/master/rtc_base/network.cc#236
|
|
772
775
|
const costlyNetworks = ["ipsec", "tun", "utun", "tap"];
|
|
776
|
+
const banNetworks = ["vmnet", "veth"];
|
|
773
777
|
const interfaces = os_1.default.networkInterfaces();
|
|
774
778
|
const all = Object.keys(interfaces)
|
|
775
779
|
.map((nic) => {
|
|
776
|
-
for (const
|
|
777
|
-
if (nic.startsWith(
|
|
780
|
+
for (const word of [...costlyNetworks, ...banNetworks]) {
|
|
781
|
+
if (nic.startsWith(word)) {
|
|
778
782
|
return {
|
|
779
783
|
nic,
|
|
780
784
|
addresses: [],
|