@agentdance/node-webrtc-dtls 1.0.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/dist/certificate.d.ts +31 -0
- package/dist/certificate.d.ts.map +1 -0
- package/dist/certificate.js +199 -0
- package/dist/certificate.js.map +1 -0
- package/dist/crypto.d.ts +89 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +193 -0
- package/dist/crypto.js.map +1 -0
- package/dist/handshake.d.ts +113 -0
- package/dist/handshake.d.ts.map +1 -0
- package/dist/handshake.js +420 -0
- package/dist/handshake.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/record.d.ts +19 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +108 -0
- package/dist/record.js.map +1 -0
- package/dist/state.d.ts +44 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +10 -0
- package/dist/state.js.map +1 -0
- package/dist/transport.d.ts +87 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +559 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +44 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
- package/src/certificate.ts +253 -0
- package/src/crypto.ts +279 -0
- package/src/handshake.ts +544 -0
- package/src/index.ts +72 -0
- package/src/record.ts +127 -0
- package/src/state.ts +59 -0
- package/src/transport.ts +692 -0
- package/src/types.ts +57 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// DTLS Handshake message types and encode/decode (RFC 6347 Section 4.2)
|
|
2
|
+
//
|
|
3
|
+
// Handshake message header (12 bytes):
|
|
4
|
+
// 1 byte HandshakeType
|
|
5
|
+
// 3 bytes length
|
|
6
|
+
// 2 bytes message_seq
|
|
7
|
+
// 3 bytes fragment_offset
|
|
8
|
+
// 3 bytes fragment_length
|
|
9
|
+
// [body]
|
|
10
|
+
import { DTLS_VERSION_1_2 } from './types.js';
|
|
11
|
+
export var HandshakeType;
|
|
12
|
+
(function (HandshakeType) {
|
|
13
|
+
HandshakeType[HandshakeType["HelloRequest"] = 0] = "HelloRequest";
|
|
14
|
+
HandshakeType[HandshakeType["ClientHello"] = 1] = "ClientHello";
|
|
15
|
+
HandshakeType[HandshakeType["ServerHello"] = 2] = "ServerHello";
|
|
16
|
+
HandshakeType[HandshakeType["HelloVerifyRequest"] = 3] = "HelloVerifyRequest";
|
|
17
|
+
HandshakeType[HandshakeType["Certificate"] = 11] = "Certificate";
|
|
18
|
+
HandshakeType[HandshakeType["ServerKeyExchange"] = 12] = "ServerKeyExchange";
|
|
19
|
+
HandshakeType[HandshakeType["CertificateRequest"] = 13] = "CertificateRequest";
|
|
20
|
+
HandshakeType[HandshakeType["ServerHelloDone"] = 14] = "ServerHelloDone";
|
|
21
|
+
HandshakeType[HandshakeType["CertificateVerify"] = 15] = "CertificateVerify";
|
|
22
|
+
HandshakeType[HandshakeType["ClientKeyExchange"] = 16] = "ClientKeyExchange";
|
|
23
|
+
HandshakeType[HandshakeType["Finished"] = 20] = "Finished";
|
|
24
|
+
})(HandshakeType || (HandshakeType = {}));
|
|
25
|
+
// Cipher suite values
|
|
26
|
+
export const CipherSuites = {
|
|
27
|
+
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: 0xc02b,
|
|
28
|
+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: 0xc02f,
|
|
29
|
+
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: 0xc02c,
|
|
30
|
+
};
|
|
31
|
+
// Extension type constants
|
|
32
|
+
export const ExtensionType = {
|
|
33
|
+
UseSrtp: 0x000e,
|
|
34
|
+
SupportedGroups: 0x000a, // formerly elliptic_curves
|
|
35
|
+
EcPointFormats: 0x000b,
|
|
36
|
+
SignatureAlgorithms: 0x000d,
|
|
37
|
+
RenegotiationInfo: 0xff01,
|
|
38
|
+
};
|
|
39
|
+
// Named curves
|
|
40
|
+
export const NamedCurve = {
|
|
41
|
+
secp256r1: 23,
|
|
42
|
+
secp384r1: 24,
|
|
43
|
+
};
|
|
44
|
+
// SRTP protection profiles (RFC 5764)
|
|
45
|
+
export const SrtpProtectionProfile = {
|
|
46
|
+
SRTP_AES128_CM_SHA1_80: 0x0001,
|
|
47
|
+
SRTP_AES128_CM_SHA1_32: 0x0002,
|
|
48
|
+
};
|
|
49
|
+
// ─── Handshake Message ────────────────────────────────────────────────────────
|
|
50
|
+
const HANDSHAKE_HEADER_SIZE = 12;
|
|
51
|
+
export function encodeHandshakeMessage(msg) {
|
|
52
|
+
const body = msg.body;
|
|
53
|
+
const buf = Buffer.allocUnsafe(HANDSHAKE_HEADER_SIZE + body.length);
|
|
54
|
+
let off = 0;
|
|
55
|
+
buf.writeUInt8(msg.msgType, off);
|
|
56
|
+
off += 1;
|
|
57
|
+
// 3-byte length
|
|
58
|
+
writeUInt24BE(buf, off, body.length);
|
|
59
|
+
off += 3;
|
|
60
|
+
buf.writeUInt16BE(msg.messageSeq, off);
|
|
61
|
+
off += 2;
|
|
62
|
+
// 3-byte fragment offset
|
|
63
|
+
writeUInt24BE(buf, off, msg.fragmentOffset);
|
|
64
|
+
off += 3;
|
|
65
|
+
// 3-byte fragment length
|
|
66
|
+
writeUInt24BE(buf, off, body.length);
|
|
67
|
+
off += 3;
|
|
68
|
+
body.copy(buf, off);
|
|
69
|
+
return buf;
|
|
70
|
+
}
|
|
71
|
+
export function decodeHandshakeMessage(buf) {
|
|
72
|
+
if (buf.length < HANDSHAKE_HEADER_SIZE) {
|
|
73
|
+
throw new Error(`Buffer too small for handshake message: ${buf.length}`);
|
|
74
|
+
}
|
|
75
|
+
let off = 0;
|
|
76
|
+
const msgType = buf.readUInt8(off);
|
|
77
|
+
off += 1;
|
|
78
|
+
const length = readUInt24BE(buf, off);
|
|
79
|
+
off += 3;
|
|
80
|
+
const messageSeq = buf.readUInt16BE(off);
|
|
81
|
+
off += 2;
|
|
82
|
+
const fragmentOffset = readUInt24BE(buf, off);
|
|
83
|
+
off += 3;
|
|
84
|
+
const fragmentLength = readUInt24BE(buf, off);
|
|
85
|
+
off += 3;
|
|
86
|
+
if (buf.length < off + fragmentLength) {
|
|
87
|
+
throw new Error('Handshake message body truncated');
|
|
88
|
+
}
|
|
89
|
+
const body = Buffer.from(buf.subarray(off, off + fragmentLength));
|
|
90
|
+
return { msgType, length, messageSeq, fragmentOffset, fragmentLength, body };
|
|
91
|
+
}
|
|
92
|
+
// ─── ClientHello ──────────────────────────────────────────────────────────────
|
|
93
|
+
export function encodeClientHello(hello) {
|
|
94
|
+
const parts = [];
|
|
95
|
+
// Version (2 bytes)
|
|
96
|
+
const ver = Buffer.allocUnsafe(2);
|
|
97
|
+
ver.writeUInt8(hello.clientVersion.major, 0);
|
|
98
|
+
ver.writeUInt8(hello.clientVersion.minor, 1);
|
|
99
|
+
parts.push(ver);
|
|
100
|
+
// Random (32 bytes)
|
|
101
|
+
parts.push(hello.random);
|
|
102
|
+
// Session ID
|
|
103
|
+
const sid = Buffer.allocUnsafe(1 + hello.sessionId.length);
|
|
104
|
+
sid.writeUInt8(hello.sessionId.length, 0);
|
|
105
|
+
hello.sessionId.copy(sid, 1);
|
|
106
|
+
parts.push(sid);
|
|
107
|
+
// Cookie
|
|
108
|
+
const ck = Buffer.allocUnsafe(1 + hello.cookie.length);
|
|
109
|
+
ck.writeUInt8(hello.cookie.length, 0);
|
|
110
|
+
hello.cookie.copy(ck, 1);
|
|
111
|
+
parts.push(ck);
|
|
112
|
+
// Cipher suites
|
|
113
|
+
const csLen = hello.cipherSuites.length * 2;
|
|
114
|
+
const cs = Buffer.allocUnsafe(2 + csLen);
|
|
115
|
+
cs.writeUInt16BE(csLen, 0);
|
|
116
|
+
for (let i = 0; i < hello.cipherSuites.length; i++) {
|
|
117
|
+
cs.writeUInt16BE(hello.cipherSuites[i], 2 + i * 2);
|
|
118
|
+
}
|
|
119
|
+
parts.push(cs);
|
|
120
|
+
// Compression methods
|
|
121
|
+
const cm = Buffer.allocUnsafe(1 + hello.compressionMethods.length);
|
|
122
|
+
cm.writeUInt8(hello.compressionMethods.length, 0);
|
|
123
|
+
for (let i = 0; i < hello.compressionMethods.length; i++) {
|
|
124
|
+
cm.writeUInt8(hello.compressionMethods[i], 1 + i);
|
|
125
|
+
}
|
|
126
|
+
parts.push(cm);
|
|
127
|
+
// Extensions
|
|
128
|
+
if (hello.extensions.length > 0) {
|
|
129
|
+
const extsBuf = encodeExtensions(hello.extensions);
|
|
130
|
+
parts.push(extsBuf);
|
|
131
|
+
}
|
|
132
|
+
return Buffer.concat(parts);
|
|
133
|
+
}
|
|
134
|
+
export function decodeClientHello(buf) {
|
|
135
|
+
let off = 0;
|
|
136
|
+
const major = buf.readUInt8(off);
|
|
137
|
+
off += 1;
|
|
138
|
+
const minor = buf.readUInt8(off);
|
|
139
|
+
off += 1;
|
|
140
|
+
const random = Buffer.from(buf.subarray(off, off + 32));
|
|
141
|
+
off += 32;
|
|
142
|
+
const sidLen = buf.readUInt8(off);
|
|
143
|
+
off += 1;
|
|
144
|
+
const sessionId = Buffer.from(buf.subarray(off, off + sidLen));
|
|
145
|
+
off += sidLen;
|
|
146
|
+
const cookieLen = buf.readUInt8(off);
|
|
147
|
+
off += 1;
|
|
148
|
+
const cookie = Buffer.from(buf.subarray(off, off + cookieLen));
|
|
149
|
+
off += cookieLen;
|
|
150
|
+
const csLen = buf.readUInt16BE(off);
|
|
151
|
+
off += 2;
|
|
152
|
+
const cipherSuites = [];
|
|
153
|
+
for (let i = 0; i < csLen; i += 2) {
|
|
154
|
+
cipherSuites.push(buf.readUInt16BE(off + i));
|
|
155
|
+
}
|
|
156
|
+
off += csLen;
|
|
157
|
+
const cmLen = buf.readUInt8(off);
|
|
158
|
+
off += 1;
|
|
159
|
+
const compressionMethods = [];
|
|
160
|
+
for (let i = 0; i < cmLen; i++) {
|
|
161
|
+
compressionMethods.push(buf.readUInt8(off + i));
|
|
162
|
+
}
|
|
163
|
+
off += cmLen;
|
|
164
|
+
let extensions = [];
|
|
165
|
+
if (off < buf.length) {
|
|
166
|
+
extensions = decodeExtensions(buf, off);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
clientVersion: { major, minor },
|
|
170
|
+
random,
|
|
171
|
+
sessionId,
|
|
172
|
+
cookie,
|
|
173
|
+
cipherSuites,
|
|
174
|
+
compressionMethods,
|
|
175
|
+
extensions,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
// ─── ServerHello ──────────────────────────────────────────────────────────────
|
|
179
|
+
export function encodeServerHello(hello) {
|
|
180
|
+
const parts = [];
|
|
181
|
+
const ver = Buffer.allocUnsafe(2);
|
|
182
|
+
ver.writeUInt8(hello.serverVersion.major, 0);
|
|
183
|
+
ver.writeUInt8(hello.serverVersion.minor, 1);
|
|
184
|
+
parts.push(ver);
|
|
185
|
+
parts.push(hello.random);
|
|
186
|
+
const sid = Buffer.allocUnsafe(1 + hello.sessionId.length);
|
|
187
|
+
sid.writeUInt8(hello.sessionId.length, 0);
|
|
188
|
+
hello.sessionId.copy(sid, 1);
|
|
189
|
+
parts.push(sid);
|
|
190
|
+
const cs = Buffer.allocUnsafe(2);
|
|
191
|
+
cs.writeUInt16BE(hello.cipherSuite, 0);
|
|
192
|
+
parts.push(cs);
|
|
193
|
+
const cm = Buffer.allocUnsafe(1);
|
|
194
|
+
cm.writeUInt8(hello.compressionMethod, 0);
|
|
195
|
+
parts.push(cm);
|
|
196
|
+
if (hello.extensions.length > 0) {
|
|
197
|
+
parts.push(encodeExtensions(hello.extensions));
|
|
198
|
+
}
|
|
199
|
+
return Buffer.concat(parts);
|
|
200
|
+
}
|
|
201
|
+
export function decodeServerHello(buf) {
|
|
202
|
+
let off = 0;
|
|
203
|
+
const major = buf.readUInt8(off);
|
|
204
|
+
off += 1;
|
|
205
|
+
const minor = buf.readUInt8(off);
|
|
206
|
+
off += 1;
|
|
207
|
+
const random = Buffer.from(buf.subarray(off, off + 32));
|
|
208
|
+
off += 32;
|
|
209
|
+
const sidLen = buf.readUInt8(off);
|
|
210
|
+
off += 1;
|
|
211
|
+
const sessionId = Buffer.from(buf.subarray(off, off + sidLen));
|
|
212
|
+
off += sidLen;
|
|
213
|
+
const cipherSuite = buf.readUInt16BE(off);
|
|
214
|
+
off += 2;
|
|
215
|
+
const compressionMethod = buf.readUInt8(off);
|
|
216
|
+
off += 1;
|
|
217
|
+
let extensions = [];
|
|
218
|
+
if (off < buf.length) {
|
|
219
|
+
extensions = decodeExtensions(buf, off);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
serverVersion: { major, minor },
|
|
223
|
+
random,
|
|
224
|
+
sessionId,
|
|
225
|
+
cipherSuite,
|
|
226
|
+
compressionMethod,
|
|
227
|
+
extensions,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// ─── HelloVerifyRequest ───────────────────────────────────────────────────────
|
|
231
|
+
export function encodeHelloVerifyRequest(hvr) {
|
|
232
|
+
const buf = Buffer.allocUnsafe(3 + hvr.cookie.length);
|
|
233
|
+
buf.writeUInt8(hvr.serverVersion.major, 0);
|
|
234
|
+
buf.writeUInt8(hvr.serverVersion.minor, 1);
|
|
235
|
+
buf.writeUInt8(hvr.cookie.length, 2);
|
|
236
|
+
hvr.cookie.copy(buf, 3);
|
|
237
|
+
return buf;
|
|
238
|
+
}
|
|
239
|
+
export function decodeHelloVerifyRequest(buf) {
|
|
240
|
+
const major = buf.readUInt8(0);
|
|
241
|
+
const minor = buf.readUInt8(1);
|
|
242
|
+
const cookieLen = buf.readUInt8(2);
|
|
243
|
+
const cookie = Buffer.from(buf.subarray(3, 3 + cookieLen));
|
|
244
|
+
return { serverVersion: { major, minor }, cookie };
|
|
245
|
+
}
|
|
246
|
+
// ─── ServerKeyExchange ────────────────────────────────────────────────────────
|
|
247
|
+
export function encodeServerKeyExchange(ske) {
|
|
248
|
+
// curve_type (1) + named_curve (2) + point_len (1) + point + hash_algo (1) + sig_algo (1) + sig_len (2) + sig
|
|
249
|
+
const pkLen = ske.publicKey.length;
|
|
250
|
+
const sigLen = ske.signature.length;
|
|
251
|
+
const buf = Buffer.allocUnsafe(1 + 2 + 1 + pkLen + 1 + 1 + 2 + sigLen);
|
|
252
|
+
let off = 0;
|
|
253
|
+
buf.writeUInt8(ske.curveType, off++);
|
|
254
|
+
buf.writeUInt16BE(ske.namedCurve, off);
|
|
255
|
+
off += 2;
|
|
256
|
+
buf.writeUInt8(pkLen, off++);
|
|
257
|
+
ske.publicKey.copy(buf, off);
|
|
258
|
+
off += pkLen;
|
|
259
|
+
buf.writeUInt8(ske.signatureAlgorithm.hash, off++);
|
|
260
|
+
buf.writeUInt8(ske.signatureAlgorithm.signature, off++);
|
|
261
|
+
buf.writeUInt16BE(sigLen, off);
|
|
262
|
+
off += 2;
|
|
263
|
+
ske.signature.copy(buf, off);
|
|
264
|
+
return buf;
|
|
265
|
+
}
|
|
266
|
+
export function decodeServerKeyExchange(buf) {
|
|
267
|
+
let off = 0;
|
|
268
|
+
const curveType = buf.readUInt8(off++);
|
|
269
|
+
const namedCurve = buf.readUInt16BE(off);
|
|
270
|
+
off += 2;
|
|
271
|
+
const pkLen = buf.readUInt8(off++);
|
|
272
|
+
const publicKey = Buffer.from(buf.subarray(off, off + pkLen));
|
|
273
|
+
off += pkLen;
|
|
274
|
+
const hash = buf.readUInt8(off++);
|
|
275
|
+
const signature_ = buf.readUInt8(off++);
|
|
276
|
+
const sigLen = buf.readUInt16BE(off);
|
|
277
|
+
off += 2;
|
|
278
|
+
const signature = Buffer.from(buf.subarray(off, off + sigLen));
|
|
279
|
+
return {
|
|
280
|
+
curveType,
|
|
281
|
+
namedCurve,
|
|
282
|
+
publicKey,
|
|
283
|
+
signatureAlgorithm: { hash, signature: signature_ },
|
|
284
|
+
signature,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// ─── Certificate ──────────────────────────────────────────────────────────────
|
|
288
|
+
export function encodeCertificate(certDer) {
|
|
289
|
+
// CertificateList: 3-byte list length, then each cert: 3-byte cert length + DER
|
|
290
|
+
const certLen = certDer.length;
|
|
291
|
+
const listLen = 3 + certLen;
|
|
292
|
+
const buf = Buffer.allocUnsafe(3 + listLen);
|
|
293
|
+
writeUInt24BE(buf, 0, listLen);
|
|
294
|
+
writeUInt24BE(buf, 3, certLen);
|
|
295
|
+
certDer.copy(buf, 6);
|
|
296
|
+
return buf;
|
|
297
|
+
}
|
|
298
|
+
export function decodeCertificate(buf) {
|
|
299
|
+
let off = 0;
|
|
300
|
+
const listLen = readUInt24BE(buf, off);
|
|
301
|
+
off += 3;
|
|
302
|
+
const end = off + listLen;
|
|
303
|
+
const certs = [];
|
|
304
|
+
while (off < end) {
|
|
305
|
+
const certLen = readUInt24BE(buf, off);
|
|
306
|
+
off += 3;
|
|
307
|
+
certs.push(Buffer.from(buf.subarray(off, off + certLen)));
|
|
308
|
+
off += certLen;
|
|
309
|
+
}
|
|
310
|
+
return certs;
|
|
311
|
+
}
|
|
312
|
+
// ─── ClientKeyExchange ────────────────────────────────────────────────────────
|
|
313
|
+
export function encodeClientKeyExchange(cke) {
|
|
314
|
+
const buf = Buffer.allocUnsafe(1 + cke.publicKey.length);
|
|
315
|
+
buf.writeUInt8(cke.publicKey.length, 0);
|
|
316
|
+
cke.publicKey.copy(buf, 1);
|
|
317
|
+
return buf;
|
|
318
|
+
}
|
|
319
|
+
export function decodeClientKeyExchange(buf) {
|
|
320
|
+
const pkLen = buf.readUInt8(0);
|
|
321
|
+
const publicKey = Buffer.from(buf.subarray(1, 1 + pkLen));
|
|
322
|
+
return { publicKey };
|
|
323
|
+
}
|
|
324
|
+
// ─── Extensions ───────────────────────────────────────────────────────────────
|
|
325
|
+
function encodeExtensions(extensions) {
|
|
326
|
+
const parts = [];
|
|
327
|
+
for (const ext of extensions) {
|
|
328
|
+
const hdr = Buffer.allocUnsafe(4);
|
|
329
|
+
hdr.writeUInt16BE(ext.type, 0);
|
|
330
|
+
hdr.writeUInt16BE(ext.data.length, 2);
|
|
331
|
+
parts.push(hdr);
|
|
332
|
+
parts.push(ext.data);
|
|
333
|
+
}
|
|
334
|
+
const extsBuf = Buffer.concat(parts);
|
|
335
|
+
const len = Buffer.allocUnsafe(2);
|
|
336
|
+
len.writeUInt16BE(extsBuf.length, 0);
|
|
337
|
+
return Buffer.concat([len, extsBuf]);
|
|
338
|
+
}
|
|
339
|
+
function decodeExtensions(buf, off) {
|
|
340
|
+
if (off + 2 > buf.length)
|
|
341
|
+
return [];
|
|
342
|
+
const totalLen = buf.readUInt16BE(off);
|
|
343
|
+
off += 2;
|
|
344
|
+
const end = off + totalLen;
|
|
345
|
+
const extensions = [];
|
|
346
|
+
while (off < end && off + 4 <= buf.length) {
|
|
347
|
+
const type = buf.readUInt16BE(off);
|
|
348
|
+
off += 2;
|
|
349
|
+
const dataLen = buf.readUInt16BE(off);
|
|
350
|
+
off += 2;
|
|
351
|
+
const data = Buffer.from(buf.subarray(off, off + dataLen));
|
|
352
|
+
off += dataLen;
|
|
353
|
+
extensions.push({ type, data });
|
|
354
|
+
}
|
|
355
|
+
return extensions;
|
|
356
|
+
}
|
|
357
|
+
// ─── Extension builders ───────────────────────────────────────────────────────
|
|
358
|
+
/**
|
|
359
|
+
* Build use_srtp extension data (RFC 5764)
|
|
360
|
+
* protection_profiles: list of 2-byte profile IDs
|
|
361
|
+
*/
|
|
362
|
+
export function buildUseSrtpExtension(profiles) {
|
|
363
|
+
// 2-byte profiles list length + 2 bytes each + 1 byte MKI length (0)
|
|
364
|
+
const listLen = profiles.length * 2;
|
|
365
|
+
const buf = Buffer.allocUnsafe(2 + listLen + 1);
|
|
366
|
+
buf.writeUInt16BE(listLen, 0);
|
|
367
|
+
for (let i = 0; i < profiles.length; i++) {
|
|
368
|
+
buf.writeUInt16BE(profiles[i], 2 + i * 2);
|
|
369
|
+
}
|
|
370
|
+
buf.writeUInt8(0, 2 + listLen); // MKI length = 0
|
|
371
|
+
return buf;
|
|
372
|
+
}
|
|
373
|
+
export function parseSrtpProfiles(data) {
|
|
374
|
+
if (data.length < 2)
|
|
375
|
+
return [];
|
|
376
|
+
const listLen = data.readUInt16BE(0);
|
|
377
|
+
const profiles = [];
|
|
378
|
+
for (let i = 0; i < listLen; i += 2) {
|
|
379
|
+
if (2 + i + 1 < data.length) {
|
|
380
|
+
profiles.push(data.readUInt16BE(2 + i));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return profiles;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Build supported_groups extension (named curves)
|
|
387
|
+
*/
|
|
388
|
+
export function buildSupportedGroupsExtension(curves) {
|
|
389
|
+
const listLen = curves.length * 2;
|
|
390
|
+
const buf = Buffer.allocUnsafe(2 + listLen);
|
|
391
|
+
buf.writeUInt16BE(listLen, 0);
|
|
392
|
+
for (let i = 0; i < curves.length; i++) {
|
|
393
|
+
buf.writeUInt16BE(curves[i], 2 + i * 2);
|
|
394
|
+
}
|
|
395
|
+
return buf;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Build signature_algorithms extension
|
|
399
|
+
*/
|
|
400
|
+
export function buildSignatureAlgorithmsExtension(pairs) {
|
|
401
|
+
const listLen = pairs.length * 2;
|
|
402
|
+
const buf = Buffer.allocUnsafe(2 + listLen);
|
|
403
|
+
buf.writeUInt16BE(listLen, 0);
|
|
404
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
405
|
+
buf.writeUInt8(pairs[i].hash, 2 + i * 2);
|
|
406
|
+
buf.writeUInt8(pairs[i].sig, 2 + i * 2 + 1);
|
|
407
|
+
}
|
|
408
|
+
return buf;
|
|
409
|
+
}
|
|
410
|
+
// ─── Utility ──────────────────────────────────────────────────────────────────
|
|
411
|
+
function writeUInt24BE(buf, offset, value) {
|
|
412
|
+
buf.writeUInt8((value >> 16) & 0xff, offset);
|
|
413
|
+
buf.writeUInt8((value >> 8) & 0xff, offset + 1);
|
|
414
|
+
buf.writeUInt8(value & 0xff, offset + 2);
|
|
415
|
+
}
|
|
416
|
+
function readUInt24BE(buf, offset) {
|
|
417
|
+
return (buf.readUInt8(offset) << 16) | (buf.readUInt8(offset + 1) << 8) | buf.readUInt8(offset + 2);
|
|
418
|
+
}
|
|
419
|
+
export { DTLS_VERSION_1_2 };
|
|
420
|
+
//# sourceMappingURL=handshake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../src/handshake.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,uCAAuC;AACvC,0BAA0B;AAC1B,mBAAmB;AACnB,wBAAwB;AACxB,4BAA4B;AAC5B,4BAA4B;AAC5B,UAAU;AAEV,OAAO,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAC;AAEhE,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,iEAAgB,CAAA;IAChB,+DAAe,CAAA;IACf,+DAAe,CAAA;IACf,6EAAsB,CAAA;IACtB,gEAAgB,CAAA;IAChB,4EAAsB,CAAA;IACtB,8EAAuB,CAAA;IACvB,wEAAoB,CAAA;IACpB,4EAAsB,CAAA;IACtB,4EAAsB,CAAA;IACtB,0DAAa,CAAA;AACf,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB;AAuDD,sBAAsB;AACtB,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,uCAAuC,EAAE,MAAM;IAC/C,qCAAqC,EAAE,MAAM;IAC7C,uCAAuC,EAAE,MAAM;CACvC,CAAC;AAEX,2BAA2B;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,MAAM;IACf,eAAe,EAAE,MAAM,EAAE,2BAA2B;IACpD,cAAc,EAAE,MAAM;IACtB,mBAAmB,EAAE,MAAM;IAC3B,iBAAiB,EAAE,MAAM;CACjB,CAAC;AAEX,eAAe;AACf,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS,E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js';
|
|
2
|
+
export { encodeRecord, decodeRecords, isDtlsPacket, makeRecord, } from './record.js';
|
|
3
|
+
export { HandshakeType, CipherSuites, ExtensionType, NamedCurve, SrtpProtectionProfile, type HandshakeMessage, type ClientHello, type ServerHello, type HelloVerifyRequest, type ServerKeyExchange, type ClientKeyExchange, type TlsExtension, encodeHandshakeMessage, decodeHandshakeMessage, encodeClientHello, decodeClientHello, encodeServerHello, decodeServerHello, encodeHelloVerifyRequest, decodeHelloVerifyRequest, encodeCertificate, decodeCertificate, encodeServerKeyExchange, decodeServerKeyExchange, encodeClientKeyExchange, decodeClientKeyExchange, buildUseSrtpExtension, buildSupportedGroupsExtension, } from './handshake.js';
|
|
4
|
+
export { prf, hmacSha256, computeMasterSecret, expandKeyMaterial, exportKeyingMaterial, aesgcmEncrypt, aesgcmDecrypt, generateEcdhKeyPair, computeEcdhPreMasterSecret, encodeEcPublicKey, decodeEcPublicKey, ecdsaSign, ecdsaVerify, sha256, type AesGcmResult, type EcdhKeyPair, type KeyBlock, } from './crypto.js';
|
|
5
|
+
export { type DtlsCertificate, generateSelfSignedCertificate, computeFingerprint, verifyFingerprint, extractPublicKeyFromCert, } from './certificate.js';
|
|
6
|
+
export { DtlsState, type SecurityParameters, type HandshakeContext, type CipherState } from './state.js';
|
|
7
|
+
export { DtlsTransport, type DtlsTransportOptions, type SrtpKeyingMaterial, } from './transport.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,GAAG,EACH,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EACpB,6BAA6B,EAC7B,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACzG,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @agentdance/node-webrtc-dtls – DTLS 1.2 implementation
|
|
2
|
+
// Public API
|
|
3
|
+
export { ContentType, DTLS_VERSION_1_2 } from './types.js';
|
|
4
|
+
export { encodeRecord, decodeRecords, isDtlsPacket, makeRecord, } from './record.js';
|
|
5
|
+
export { HandshakeType, CipherSuites, ExtensionType, NamedCurve, SrtpProtectionProfile, encodeHandshakeMessage, decodeHandshakeMessage, encodeClientHello, decodeClientHello, encodeServerHello, decodeServerHello, encodeHelloVerifyRequest, decodeHelloVerifyRequest, encodeCertificate, decodeCertificate, encodeServerKeyExchange, decodeServerKeyExchange, encodeClientKeyExchange, decodeClientKeyExchange, buildUseSrtpExtension, buildSupportedGroupsExtension, } from './handshake.js';
|
|
6
|
+
export { prf, hmacSha256, computeMasterSecret, expandKeyMaterial, exportKeyingMaterial, aesgcmEncrypt, aesgcmDecrypt, generateEcdhKeyPair, computeEcdhPreMasterSecret, encodeEcPublicKey, decodeEcPublicKey, ecdsaSign, ecdsaVerify, sha256, } from './crypto.js';
|
|
7
|
+
export { generateSelfSignedCertificate, computeFingerprint, verifyFingerprint, extractPublicKeyFromCert, } from './certificate.js';
|
|
8
|
+
export { DtlsState } from './state.js';
|
|
9
|
+
export { DtlsTransport, } from './transport.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,aAAa;AAEb,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,YAAY,CAAC;AAC9F,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,qBAAqB,EAQrB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,GAAG,EACH,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,MAAM,GAIP,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,6BAA6B,EAC7B,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAoE,MAAM,YAAY,CAAC;AACzG,OAAO,EACL,aAAa,GAGd,MAAM,gBAAgB,CAAC"}
|
package/dist/record.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ContentType, type DtlsRecord } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Encode a single DTLS record into a Buffer.
|
|
4
|
+
*/
|
|
5
|
+
export declare function encodeRecord(record: DtlsRecord): Buffer;
|
|
6
|
+
/**
|
|
7
|
+
* Decode one or more DTLS records from a UDP datagram.
|
|
8
|
+
* A single datagram may contain multiple records.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeRecords(buf: Buffer): DtlsRecord[];
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the buffer looks like a DTLS packet.
|
|
13
|
+
* Content type must be 20-63 and version bytes must match DTLS 1.x.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDtlsPacket(buf: Buffer): boolean;
|
|
16
|
+
/** Create a record with DTLS 1.2 version defaults */
|
|
17
|
+
export declare function makeRecord(contentType: ContentType, epoch: number, sequenceNumber: bigint, fragment: Buffer): DtlsRecord;
|
|
18
|
+
export { ContentType };
|
|
19
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AAI5E;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAyBvD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,CA4CvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAWjD;AAED,qDAAqD;AACrD,wBAAgB,UAAU,CACxB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,UAAU,CAQZ;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/record.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// DTLS Record Layer encode/decode (RFC 6347 Section 4.1)
|
|
2
|
+
//
|
|
3
|
+
// Record header format (13 bytes):
|
|
4
|
+
// 1 byte content type
|
|
5
|
+
// 2 bytes version (major, minor)
|
|
6
|
+
// 2 bytes epoch
|
|
7
|
+
// 6 bytes sequence number (48-bit)
|
|
8
|
+
// 2 bytes length
|
|
9
|
+
import { ContentType, DTLS_VERSION_1_2 } from './types.js';
|
|
10
|
+
const RECORD_HEADER_SIZE = 13;
|
|
11
|
+
/**
|
|
12
|
+
* Encode a single DTLS record into a Buffer.
|
|
13
|
+
*/
|
|
14
|
+
export function encodeRecord(record) {
|
|
15
|
+
const buf = Buffer.allocUnsafe(RECORD_HEADER_SIZE + record.fragment.length);
|
|
16
|
+
let offset = 0;
|
|
17
|
+
buf.writeUInt8(record.contentType, offset);
|
|
18
|
+
offset += 1;
|
|
19
|
+
buf.writeUInt8(record.version.major, offset);
|
|
20
|
+
offset += 1;
|
|
21
|
+
buf.writeUInt8(record.version.minor, offset);
|
|
22
|
+
offset += 1;
|
|
23
|
+
buf.writeUInt16BE(record.epoch, offset);
|
|
24
|
+
offset += 2;
|
|
25
|
+
// 48-bit sequence number (big-endian)
|
|
26
|
+
const seq = record.sequenceNumber;
|
|
27
|
+
buf.writeUInt16BE(Number((seq >> 32n) & 0xffffn), offset);
|
|
28
|
+
offset += 2;
|
|
29
|
+
buf.writeUInt32BE(Number(seq & 0xffffffffn), offset);
|
|
30
|
+
offset += 4;
|
|
31
|
+
buf.writeUInt16BE(record.fragment.length, offset);
|
|
32
|
+
offset += 2;
|
|
33
|
+
record.fragment.copy(buf, offset);
|
|
34
|
+
return buf;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decode one or more DTLS records from a UDP datagram.
|
|
38
|
+
* A single datagram may contain multiple records.
|
|
39
|
+
*/
|
|
40
|
+
export function decodeRecords(buf) {
|
|
41
|
+
const records = [];
|
|
42
|
+
let offset = 0;
|
|
43
|
+
while (offset < buf.length) {
|
|
44
|
+
if (buf.length - offset < RECORD_HEADER_SIZE) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
const contentType = buf.readUInt8(offset);
|
|
48
|
+
offset += 1;
|
|
49
|
+
const major = buf.readUInt8(offset);
|
|
50
|
+
offset += 1;
|
|
51
|
+
const minor = buf.readUInt8(offset);
|
|
52
|
+
offset += 1;
|
|
53
|
+
const epoch = buf.readUInt16BE(offset);
|
|
54
|
+
offset += 2;
|
|
55
|
+
const seqHigh = BigInt(buf.readUInt16BE(offset));
|
|
56
|
+
offset += 2;
|
|
57
|
+
const seqLow = BigInt(buf.readUInt32BE(offset));
|
|
58
|
+
offset += 4;
|
|
59
|
+
const sequenceNumber = (seqHigh << 32n) | seqLow;
|
|
60
|
+
const length = buf.readUInt16BE(offset);
|
|
61
|
+
offset += 2;
|
|
62
|
+
if (buf.length - offset < length) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const fragment = buf.subarray(offset, offset + length);
|
|
66
|
+
offset += length;
|
|
67
|
+
records.push({
|
|
68
|
+
contentType,
|
|
69
|
+
version: { major, minor },
|
|
70
|
+
epoch,
|
|
71
|
+
sequenceNumber,
|
|
72
|
+
fragment: Buffer.from(fragment),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return records;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns true if the buffer looks like a DTLS packet.
|
|
79
|
+
* Content type must be 20-63 and version bytes must match DTLS 1.x.
|
|
80
|
+
*/
|
|
81
|
+
export function isDtlsPacket(buf) {
|
|
82
|
+
if (buf.length < RECORD_HEADER_SIZE)
|
|
83
|
+
return false;
|
|
84
|
+
const ct = buf.readUInt8(0);
|
|
85
|
+
// ContentType: 20 (ChangeCipherSpec), 21 (Alert), 22 (Handshake), 23 (ApplicationData)
|
|
86
|
+
if (ct < 20 || ct > 63)
|
|
87
|
+
return false;
|
|
88
|
+
const major = buf.readUInt8(1);
|
|
89
|
+
const minor = buf.readUInt8(2);
|
|
90
|
+
// DTLS 1.0 = {254, 255}, DTLS 1.2 = {254, 253}
|
|
91
|
+
if (major !== 254)
|
|
92
|
+
return false;
|
|
93
|
+
if (minor !== 253 && minor !== 255)
|
|
94
|
+
return false;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
/** Create a record with DTLS 1.2 version defaults */
|
|
98
|
+
export function makeRecord(contentType, epoch, sequenceNumber, fragment) {
|
|
99
|
+
return {
|
|
100
|
+
contentType,
|
|
101
|
+
version: DTLS_VERSION_1_2,
|
|
102
|
+
epoch,
|
|
103
|
+
sequenceNumber,
|
|
104
|
+
fragment,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export { ContentType };
|
|
108
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,mCAAmC;AACnC,yBAAyB;AACzB,mCAAmC;AACnC,kBAAkB;AAClB,qCAAqC;AACrC,mBAAmB;AAEnB,OAAO,EAAE,WAAW,EAAmB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE5E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AAM,IAAI,MAAM,CAAC;QAEjB,OAAO,CAAC,IAAI,CAAC;YACX,WAAW;YACX,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,KAAK;YACL,cAAc;YACd,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SAChC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,GAAG,CAAC,MAAM,GAAG,kBAAkB;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5B,uFAAuF;IACvF,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/B,+CAA+C;IAC/C,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACjD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,UAAU,CACxB,WAAwB,EACxB,KAAa,EACb,cAAsB,EACtB,QAAgB;IAEhB,OAAO;QACL,WAAW;QACX,OAAO,EAAE,gBAAgB;QACzB,KAAK;QACL,cAAc;QACd,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
export declare enum DtlsState {
|
|
3
|
+
New = "new",
|
|
4
|
+
Connecting = "connecting",
|
|
5
|
+
Connected = "connected",
|
|
6
|
+
Closed = "closed",
|
|
7
|
+
Failed = "failed"
|
|
8
|
+
}
|
|
9
|
+
export interface SecurityParameters {
|
|
10
|
+
entity: 'client' | 'server';
|
|
11
|
+
cipherSuite: number;
|
|
12
|
+
masterSecret: Buffer;
|
|
13
|
+
clientRandom: Buffer;
|
|
14
|
+
serverRandom: Buffer;
|
|
15
|
+
clientWriteKey: Buffer;
|
|
16
|
+
serverWriteKey: Buffer;
|
|
17
|
+
clientWriteIv: Buffer;
|
|
18
|
+
serverWriteIv: Buffer;
|
|
19
|
+
}
|
|
20
|
+
export interface CipherState {
|
|
21
|
+
writeKey: Buffer;
|
|
22
|
+
writeIv: Buffer;
|
|
23
|
+
readKey: Buffer;
|
|
24
|
+
readIv: Buffer;
|
|
25
|
+
writeEpoch: number;
|
|
26
|
+
writeSeq: bigint;
|
|
27
|
+
readEpoch: number;
|
|
28
|
+
readSeq: bigint;
|
|
29
|
+
}
|
|
30
|
+
export interface HandshakeContext {
|
|
31
|
+
messages: Buffer[];
|
|
32
|
+
cookie?: Buffer;
|
|
33
|
+
ecdhPrivateKey?: crypto.KeyObject;
|
|
34
|
+
ecdhPublicKey?: crypto.KeyObject;
|
|
35
|
+
peerEcPublicKeyBytes?: Buffer;
|
|
36
|
+
preMasterSecret?: Buffer;
|
|
37
|
+
peerCertDer?: Buffer;
|
|
38
|
+
selectedCipherSuite?: number;
|
|
39
|
+
sendMessageSeq: number;
|
|
40
|
+
recvMessageSeq: number;
|
|
41
|
+
serverRandom?: Buffer;
|
|
42
|
+
clientRandom?: Buffer;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=state.d.ts.map
|