Skip to content

Commit 4787ee1

Browse files
authored
Merge branch 'develop' into remove-date-fns
2 parents f95e553 + b817002 commit 4787ee1

File tree

9 files changed

+54
-53
lines changed

9 files changed

+54
-53
lines changed

package-lock.json

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dtls/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
"lodash": "^4.17.21",
3838
"tweetnacl": "^1.0.3"
3939
},
40-
"devDependencies": {
41-
"@types/lodash": "^4.17.15"
42-
},
4340
"engines": {
4441
"node": ">=16"
4542
},

packages/dtls/src/cipher/create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CipherGCMTypes } from "crypto";
12
import {
23
type KeyExchange,
34
createECDHEECDSAKeyExchange,
@@ -166,7 +167,7 @@ export function createCipher(cipher: number) {
166167
export function createAEADCipher(
167168
id: number,
168169
name: string,
169-
block: string,
170+
block: CipherGCMTypes,
170171
kx: KeyExchange,
171172
constants: { K_LEN: number; N_MAX: number },
172173
hash = "sha256",

packages/dtls/src/cipher/suites/abstract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CipherGCMTypes } from "crypto";
12
import type { KeyExchange } from "../key-exchange";
23

34
export type CipherHeader = {
@@ -19,7 +20,7 @@ export default abstract class AbstractCipher {
1920
hashAlgorithm?: string;
2021
verifyDataLength = 12;
2122

22-
blockAlgorithm?: string;
23+
blockAlgorithm?: CipherGCMTypes;
2324
kx?: KeyExchange;
2425

2526
/**

packages/dtls/src/cipher/suites/aead.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from "crypto";
1+
import { createCipheriv, createDecipheriv } from "crypto";
22

33
import { dumpBuffer, getObjectSummary } from "../../helper";
44
import { debug } from "../../imports/common";
@@ -72,8 +72,8 @@ export default class AEADCipher extends Cipher {
7272

7373
const additionalBuffer = this.encodeAdditionalBuffer(header, data.length);
7474

75-
const cipher = crypto.createCipheriv(
76-
this.blockAlgorithm as crypto.CipherCCMTypes,
75+
const cipher = createCipheriv(
76+
this.blockAlgorithm!,
7777
writeKey,
7878
iv,
7979
{
@@ -128,8 +128,8 @@ export default class AEADCipher extends Cipher {
128128
encrypted.length,
129129
);
130130

131-
const decipher = crypto.createDecipheriv(
132-
this.blockAlgorithm as crypto.CipherCCMTypes,
131+
const decipher = createDecipheriv(
132+
this.blockAlgorithm!,
133133
writeKey,
134134
iv,
135135
{

packages/dtls/src/context/cipher.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import nodeCrypto, { createSign } from "crypto";
1+
import { webcrypto, createSign, randomBytes } from "crypto";
22
import { Certificate, PrivateKey } from "@fidm/x509";
33
import * as x509 from "@peculiar/x509";
44
import { encode, types } from "@shinyoshiaki/binary-data";
@@ -16,11 +16,10 @@ import type { NamedCurveKeyPair } from "../cipher/namedCurve";
1616
import { prfVerifyDataClient, prfVerifyDataServer } from "../cipher/prf";
1717
import { SessionType, type SessionTypes } from "../cipher/suites/abstract";
1818
import type AEADCipher from "../cipher/suites/aead";
19-
import { ProtocolVersion } from "../handshake/binary";
2019
import type { DtlsRandom } from "../handshake/random";
2120
import type { DtlsPlaintext } from "../record/message/plaintext";
2221

23-
const crypto = nodeCrypto.webcrypto;
22+
const crypto = webcrypto;
2423
x509.cryptoProvider.set(crypto as any);
2524

2625
export class CipherContext {
@@ -104,10 +103,10 @@ export class CipherContext {
104103
const keys = (await crypto.subtle.generateKey(alg, true, [
105104
"sign",
106105
"verify",
107-
])) as nodeCrypto.webcrypto.CryptoKeyPair;
106+
])) as webcrypto.CryptoKeyPair;
108107

109108
const cert = await x509.X509CertificateGenerator.createSelfSigned({
110-
serialNumber: nodeCrypto.randomBytes(8).toString("hex"),
109+
serialNumber: randomBytes(8).toString("hex"),
111110
name: "C=AU, ST=Some-State, O=Internet Widgits Pty Ltd",
112111
notBefore: new Date(),
113112
notAfter: new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000),

packages/dtls/src/handshake/extensions/useSrtp.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { decode, encode, types } from "@shinyoshiaki/binary-data";
2-
import times from "lodash/times.js";
32

43
import type { Extension } from "../../typings/domain";
54

@@ -30,9 +29,11 @@ export class UseSRTP {
3029
static deSerialize(buf: Buffer) {
3130
const useSrtp = new UseSRTP(decode(buf, UseSRTP.spec));
3231
const profileLength = useSrtp.data.readUInt16BE();
33-
const profiles = times(profileLength / 2).map((i) => {
34-
return useSrtp.data.readUInt16BE(i * 2 + 2);
35-
});
32+
33+
const profiles = new Array(profileLength / 2);
34+
for (let i = 0; i < profiles.length; i++) {
35+
profiles[i] = useSrtp.data.readUInt16BE(i * 2 + 2);
36+
}
3637
useSrtp.profiles = profiles;
3738
useSrtp.mki = useSrtp.data.slice(profileLength + 2);
3839
return useSrtp;

packages/rtp/src/srtp/context/context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Hmac, createHmac } from "crypto";
1+
import { createHmac } from "crypto";
22
import AES from "aes-js";
33

44
import type { CipherAesBase } from "../cipher";
@@ -15,12 +15,12 @@ export class Context {
1515
srtpSessionKey: Buffer;
1616
srtpSessionSalt: Buffer;
1717
srtpSessionAuthTag: Buffer;
18-
srtpSessionAuth: Hmac;
18+
srtpSessionAuth: ReturnType<typeof createHmac>;
1919
srtcpSSRCStates: { [ssrc: number]: SrtcpSSRCState } = {};
2020
srtcpSessionKey: Buffer;
2121
srtcpSessionSalt: Buffer;
2222
srtcpSessionAuthTag: Buffer;
23-
srtcpSessionAuth: Hmac;
23+
srtcpSessionAuth: ReturnType<typeof createHmac>;
2424

2525
cipher: CipherAesBase;
2626

packages/webrtc/src/peerConnection.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cloneDeep from "lodash/cloneDeep.js";
21
import * as uuid from "uuid";
32

43
import type { RTCDataChannel } from "./dataChannel";
@@ -57,7 +56,7 @@ const log = debug("werift:packages/webrtc/src/peerConnection.ts");
5756
export class RTCPeerConnection extends EventTarget {
5857
readonly cname = uuid.v4();
5958

60-
config: Required<PeerConfig> = cloneDeep<PeerConfig>(defaultPeerConfig);
59+
config: Required<PeerConfig> = generateDefaultPeerConfig();
6160
signalingState: RTCSignalingState = "stable";
6261
negotiationneeded = false;
6362
needRestart = false;
@@ -196,6 +195,9 @@ export class RTCPeerConnection extends EventTarget {
196195
get remoteDescription() {
197196
return this.sdpManager.remoteDescription;
198197
}
198+
get remoteIsBundled() {
199+
return this.sdpManager.remoteIsBundled;
200+
}
199201
/**@private */
200202
get _localDescription() {
201203
return this.sdpManager._localDescription;
@@ -917,32 +919,35 @@ export type RTCIceServer = {
917919
credential?: string;
918920
};
919921

920-
export const defaultPeerConfig: PeerConfig = {
921-
codecs: {
922-
audio: [useOPUS(), usePCMU()],
923-
video: [useVP8()],
924-
},
925-
headerExtensions: {
926-
audio: [],
927-
video: [],
928-
},
929-
iceTransportPolicy: "all",
930-
iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
931-
icePortRange: undefined,
932-
iceInterfaceAddresses: undefined,
933-
iceAdditionalHostAddresses: undefined,
934-
iceUseIpv4: true,
935-
iceUseIpv6: true,
936-
iceFilterStunResponse: undefined,
937-
iceFilterCandidatePair: undefined,
938-
icePasswordPrefix: undefined,
939-
iceUseLinkLocalAddress: undefined,
940-
dtls: {},
941-
bundlePolicy: "max-compat",
942-
debug: {},
943-
midSuffix: false,
944-
forceTurnTCP: false,
945-
};
922+
function generateDefaultPeerConfig(): PeerConfig {
923+
return {
924+
codecs: {
925+
audio: [useOPUS(), usePCMU()],
926+
video: [useVP8()],
927+
},
928+
headerExtensions: {
929+
audio: [],
930+
video: [],
931+
},
932+
iceTransportPolicy: "all",
933+
iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
934+
icePortRange: undefined,
935+
iceInterfaceAddresses: undefined,
936+
iceAdditionalHostAddresses: undefined,
937+
iceUseIpv4: true,
938+
iceUseIpv6: true,
939+
iceFilterStunResponse: undefined,
940+
iceFilterCandidatePair: undefined,
941+
icePasswordPrefix: undefined,
942+
iceUseLinkLocalAddress: undefined,
943+
dtls: {},
944+
bundlePolicy: "max-compat",
945+
debug: {},
946+
midSuffix: false,
947+
forceTurnTCP: false,
948+
};
949+
}
950+
export const defaultPeerConfig: PeerConfig = generateDefaultPeerConfig();
946951

947952
export interface RTCTrackEvent {
948953
track: MediaStreamTrack;

0 commit comments

Comments
 (0)