node-ikev2 0.1.4 → 0.3.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/lib/src/configuration-attribute.d.ts +2 -6
- package/lib/src/configuration-attribute.js +130 -203
- package/lib/src/index.d.ts +2 -0
- package/lib/src/index.js +2 -0
- package/lib/src/ip-address.d.ts +6 -0
- package/lib/src/ip-address.js +159 -0
- package/lib/src/payload.d.ts +5 -25
- package/lib/src/payload.js +23 -44
- package/lib/src/selector.d.ts +2 -2
- package/lib/src/selector.js +77 -17
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function parseIPv4AddressString(addressString: string): Buffer;
|
|
2
|
+
export declare function formatIPv4AddressBuffer(buffer: Buffer): string;
|
|
3
|
+
export declare function parseIPv6AddressString(addressString: string): Buffer;
|
|
4
|
+
export declare function formatIPv6AddressBuffer(addressBuffer: Buffer): string;
|
|
5
|
+
export declare function parseIPAddressString(addressString: string): Buffer;
|
|
6
|
+
export declare function formatIPAddressBuffer(addressBuffer: Buffer): string;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIPv4AddressString = parseIPv4AddressString;
|
|
4
|
+
exports.formatIPv4AddressBuffer = formatIPv4AddressBuffer;
|
|
5
|
+
exports.parseIPv6AddressString = parseIPv6AddressString;
|
|
6
|
+
exports.formatIPv6AddressBuffer = formatIPv6AddressBuffer;
|
|
7
|
+
exports.parseIPAddressString = parseIPAddressString;
|
|
8
|
+
exports.formatIPAddressBuffer = formatIPAddressBuffer;
|
|
9
|
+
function parseIPv4AddressString(addressString) {
|
|
10
|
+
if (addressString.length === 0) {
|
|
11
|
+
throw new Error(`Invalid IPv4 address ${addressString}`);
|
|
12
|
+
}
|
|
13
|
+
const buffer = Buffer.alloc(4);
|
|
14
|
+
const stringParts = addressString.split(".");
|
|
15
|
+
const parts = stringParts.map((p) => {
|
|
16
|
+
if (!/^\d+$/.test(p)) {
|
|
17
|
+
throw new Error(`Invalid IPv4 address ${addressString}: part "${p}" contains non-digit characters.`);
|
|
18
|
+
}
|
|
19
|
+
const parsed = parseInt(p, 10);
|
|
20
|
+
if (parsed < 0 || parsed > 255) {
|
|
21
|
+
throw new Error(`Invalid IPv4 address ${addressString}: part "${p}" is not a valid octet.`);
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
});
|
|
25
|
+
if (parts.length !== 4) {
|
|
26
|
+
throw new Error(`Invalid IPv4 address ${addressString}`);
|
|
27
|
+
}
|
|
28
|
+
buffer.writeUInt8(parts[0], 0);
|
|
29
|
+
buffer.writeUInt8(parts[1], 1);
|
|
30
|
+
buffer.writeUInt8(parts[2], 2);
|
|
31
|
+
buffer.writeUInt8(parts[3], 3);
|
|
32
|
+
return buffer;
|
|
33
|
+
}
|
|
34
|
+
function formatIPv4AddressBuffer(buffer) {
|
|
35
|
+
if (buffer.length === 0) {
|
|
36
|
+
throw new Error(`Invalid IPv4 address ${buffer}`);
|
|
37
|
+
}
|
|
38
|
+
if (buffer.length !== 4) {
|
|
39
|
+
throw new Error(`Invalid IPv4 address ${buffer}`);
|
|
40
|
+
}
|
|
41
|
+
const parts = [
|
|
42
|
+
buffer.readUInt8(0),
|
|
43
|
+
buffer.readUInt8(1),
|
|
44
|
+
buffer.readUInt8(2),
|
|
45
|
+
buffer.readUInt8(3),
|
|
46
|
+
];
|
|
47
|
+
return parts.join(".");
|
|
48
|
+
}
|
|
49
|
+
function parseIPv6AddressString(addressString) {
|
|
50
|
+
if (addressString.length === 0) {
|
|
51
|
+
return Buffer.alloc(0);
|
|
52
|
+
}
|
|
53
|
+
const buffer = Buffer.alloc(16);
|
|
54
|
+
let parts;
|
|
55
|
+
let zeroFillCount = 0;
|
|
56
|
+
let currentBufferIndex = 0;
|
|
57
|
+
if (addressString.includes("::")) {
|
|
58
|
+
const partsSplitted = addressString.split("::");
|
|
59
|
+
if (partsSplitted.length > 2) {
|
|
60
|
+
throw new Error(`Invalid IPv6 address ${addressString}: multiple '::' sequences.`);
|
|
61
|
+
}
|
|
62
|
+
const [beforeDoubleColon, afterDoubleColon] = partsSplitted;
|
|
63
|
+
const beforeParts = beforeDoubleColon.split(":").filter((p) => p !== "");
|
|
64
|
+
const afterParts = afterDoubleColon.split(":").filter((p) => p !== "");
|
|
65
|
+
// Calculate how many zero groups are needed for '::'
|
|
66
|
+
zeroFillCount = 8 - (beforeParts.length + afterParts.length);
|
|
67
|
+
if (zeroFillCount < 0) {
|
|
68
|
+
throw new Error(`Invalid IPv6 address ${addressString}: too many parts for '::' expansion.`);
|
|
69
|
+
}
|
|
70
|
+
parts = [...beforeParts];
|
|
71
|
+
for (let i = 0; i < zeroFillCount; i++) {
|
|
72
|
+
parts.push("0"); // Represent the zero groups
|
|
73
|
+
}
|
|
74
|
+
parts.push(...afterParts);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
parts = addressString.split(":");
|
|
78
|
+
}
|
|
79
|
+
if (parts.length !== 8) {
|
|
80
|
+
throw new Error(`Invalid IPv6 address ${addressString}: expected 8 parts, got ${parts.length}.`);
|
|
81
|
+
}
|
|
82
|
+
for (let i = 0; i < 8; i++) {
|
|
83
|
+
const part = parts[i];
|
|
84
|
+
if (part.length > 4) {
|
|
85
|
+
throw new Error(`Invalid IPv6 address ${addressString}: part length: ${part}`);
|
|
86
|
+
}
|
|
87
|
+
const value = parseInt(part, 16);
|
|
88
|
+
if (isNaN(value) || value < 0 || value > 0xffff) {
|
|
89
|
+
throw new Error(`Invalid IPv6 address ${addressString}: part: ${part}`);
|
|
90
|
+
}
|
|
91
|
+
buffer.writeUInt16BE(value, currentBufferIndex);
|
|
92
|
+
currentBufferIndex += 2;
|
|
93
|
+
}
|
|
94
|
+
return buffer;
|
|
95
|
+
}
|
|
96
|
+
function formatIPv6AddressBuffer(addressBuffer) {
|
|
97
|
+
if (addressBuffer.length === 0) {
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
if (addressBuffer.length !== 16) {
|
|
101
|
+
throw new Error(`Invalid buffer length for IPv6 address ${addressBuffer}: expected 16 bytes.`);
|
|
102
|
+
}
|
|
103
|
+
const parts = Array.from({ length: 8 }, (_, i) => addressBuffer
|
|
104
|
+
.readUInt16BE(i * 2)
|
|
105
|
+
.toString(16)
|
|
106
|
+
.replace(/^0+/, "") || "0");
|
|
107
|
+
let maxZeroLength = 0;
|
|
108
|
+
let maxZeroIndex = -1;
|
|
109
|
+
let currentZeroLength = 0;
|
|
110
|
+
let currentZeroIndex = -1;
|
|
111
|
+
for (let i = 0; i < parts.length; i++) {
|
|
112
|
+
if (parts[i] === "0") {
|
|
113
|
+
if (currentZeroLength === 0) {
|
|
114
|
+
currentZeroIndex = i;
|
|
115
|
+
}
|
|
116
|
+
currentZeroLength++;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
if (currentZeroLength > maxZeroLength) {
|
|
120
|
+
maxZeroLength = currentZeroLength;
|
|
121
|
+
maxZeroIndex = currentZeroIndex;
|
|
122
|
+
}
|
|
123
|
+
currentZeroLength = 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (currentZeroLength > maxZeroLength) {
|
|
127
|
+
maxZeroLength = currentZeroLength;
|
|
128
|
+
maxZeroIndex = currentZeroIndex;
|
|
129
|
+
}
|
|
130
|
+
if (maxZeroLength > 1) {
|
|
131
|
+
const before = parts.slice(0, maxZeroIndex).join(":");
|
|
132
|
+
const after = parts.slice(maxZeroIndex + maxZeroLength).join(":");
|
|
133
|
+
return `${before}::${after}`;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return parts.join(":");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function parseIPAddressString(addressString) {
|
|
140
|
+
if (addressString.length === 0) {
|
|
141
|
+
return Buffer.alloc(0);
|
|
142
|
+
}
|
|
143
|
+
if (addressString.includes(":")) {
|
|
144
|
+
return parseIPv6AddressString(addressString);
|
|
145
|
+
}
|
|
146
|
+
return parseIPv4AddressString(addressString);
|
|
147
|
+
}
|
|
148
|
+
function formatIPAddressBuffer(addressBuffer) {
|
|
149
|
+
if (addressBuffer.length === 0) {
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
if (addressBuffer.length === 4) {
|
|
153
|
+
return formatIPv4AddressBuffer(addressBuffer);
|
|
154
|
+
}
|
|
155
|
+
if (addressBuffer.length === 16) {
|
|
156
|
+
return formatIPv6AddressBuffer(addressBuffer);
|
|
157
|
+
}
|
|
158
|
+
throw new Error(`Invalid buffer length for IP address ${addressBuffer}: expected 4 or 16 bytes.`);
|
|
159
|
+
}
|
package/lib/src/payload.d.ts
CHANGED
|
@@ -106,7 +106,6 @@ export declare class PayloadSA extends Payload {
|
|
|
106
106
|
nextPayload: payloadType;
|
|
107
107
|
proposals: Proposal[];
|
|
108
108
|
critical: boolean;
|
|
109
|
-
length: number;
|
|
110
109
|
constructor(nextPayload: payloadType, proposals: Proposal[], critical?: boolean, length?: number);
|
|
111
110
|
/**
|
|
112
111
|
* Parses a Security Association Payload from a buffer
|
|
@@ -153,7 +152,6 @@ export declare class PayloadKE extends Payload {
|
|
|
153
152
|
dhGroup: number;
|
|
154
153
|
keyData: Buffer;
|
|
155
154
|
critical: boolean;
|
|
156
|
-
length: number;
|
|
157
155
|
constructor(nextPayload: payloadType, dhGroup: number, keyData: Buffer, critical?: boolean, length?: number);
|
|
158
156
|
/**
|
|
159
157
|
* Parses a Key Exchange Payload from a buffer
|
|
@@ -213,7 +211,6 @@ export declare class PayloadID extends Payload {
|
|
|
213
211
|
idType: number;
|
|
214
212
|
idData: Buffer;
|
|
215
213
|
critical: boolean;
|
|
216
|
-
length: number;
|
|
217
214
|
constructor(nextPayload: payloadType, idType: number, idData: Buffer, critical?: boolean, length?: number);
|
|
218
215
|
/**
|
|
219
216
|
* Parses an Identification Payload from a buffer
|
|
@@ -260,7 +257,6 @@ export declare class PayloadIDi extends PayloadID {
|
|
|
260
257
|
idType: number;
|
|
261
258
|
idData: Buffer;
|
|
262
259
|
critical: boolean;
|
|
263
|
-
length: number;
|
|
264
260
|
constructor(nextPayload: payloadType, idType: number, idData: Buffer, critical?: boolean, length?: number);
|
|
265
261
|
}
|
|
266
262
|
/**
|
|
@@ -273,8 +269,7 @@ export declare class PayloadIDr extends PayloadID {
|
|
|
273
269
|
idType: number;
|
|
274
270
|
idData: Buffer;
|
|
275
271
|
critical: boolean;
|
|
276
|
-
|
|
277
|
-
constructor(nextPayload: payloadType, idType: number, idData: Buffer, critical: boolean, length: number);
|
|
272
|
+
constructor(nextPayload: payloadType, idType: number, idData: Buffer, critical?: boolean, length?: number);
|
|
278
273
|
}
|
|
279
274
|
/**
|
|
280
275
|
* IKEv2 Notify Message Types
|
|
@@ -307,7 +302,6 @@ export declare class PayloadCERT extends Payload {
|
|
|
307
302
|
certEncoding: number;
|
|
308
303
|
certData: Buffer;
|
|
309
304
|
critical: boolean;
|
|
310
|
-
length: number;
|
|
311
305
|
constructor(nextPayload: payloadType, certEncoding: number, certData: Buffer, critical?: boolean, length?: number);
|
|
312
306
|
/**
|
|
313
307
|
* Parses a Certificate Payload from a buffer
|
|
@@ -354,7 +348,6 @@ export declare class PayloadCERTREQ extends Payload {
|
|
|
354
348
|
certEncoding: number;
|
|
355
349
|
certAuthority: Buffer;
|
|
356
350
|
critical: boolean;
|
|
357
|
-
length: number;
|
|
358
351
|
constructor(nextPayload: payloadType, certEncoding: number, certAuthority: Buffer, critical?: boolean, length?: number);
|
|
359
352
|
/**
|
|
360
353
|
* Parses a Certificate Request Payload from a buffer
|
|
@@ -401,7 +394,6 @@ export declare class PayloadAUTH extends Payload {
|
|
|
401
394
|
authMethod: number;
|
|
402
395
|
authData: Buffer;
|
|
403
396
|
critical: boolean;
|
|
404
|
-
length: number;
|
|
405
397
|
constructor(nextPayload: payloadType, authMethod: number, authData: Buffer, critical?: boolean, length?: number);
|
|
406
398
|
/**
|
|
407
399
|
* Parses an Authentication Payload from a buffer
|
|
@@ -447,7 +439,6 @@ export declare class PayloadNONCE extends Payload {
|
|
|
447
439
|
nextPayload: payloadType;
|
|
448
440
|
nonceData: Buffer;
|
|
449
441
|
critical: boolean;
|
|
450
|
-
length: number;
|
|
451
442
|
constructor(nextPayload: payloadType, nonceData: Buffer, critical?: boolean, length?: number);
|
|
452
443
|
/**
|
|
453
444
|
* Parses a Nonce Payload from a buffer
|
|
@@ -593,7 +584,6 @@ export declare class PayloadNOTIFY extends Payload {
|
|
|
593
584
|
spi: Buffer;
|
|
594
585
|
notifyData: Buffer;
|
|
595
586
|
critical: boolean;
|
|
596
|
-
length: number;
|
|
597
587
|
constructor(nextPayload: payloadType, protocolId: securityProtocolId, spiSize: number, notifyType: number, spi: Buffer, notifyData: Buffer, critical?: boolean, length?: number);
|
|
598
588
|
/**
|
|
599
589
|
* Parses a Notify Payload from a buffer
|
|
@@ -642,7 +632,6 @@ export declare class PayloadDELETE extends Payload {
|
|
|
642
632
|
numSpi: number;
|
|
643
633
|
spis: Buffer[];
|
|
644
634
|
critical: boolean;
|
|
645
|
-
length: number;
|
|
646
635
|
constructor(nextPayload: payloadType, protocolId: number, spiSize: number, numSpi: number, spis: Buffer[], critical?: boolean, length?: number);
|
|
647
636
|
/**
|
|
648
637
|
* Parses a Delete Payload from a buffer
|
|
@@ -688,7 +677,6 @@ export declare class PayloadVENDOR extends Payload {
|
|
|
688
677
|
nextPayload: payloadType;
|
|
689
678
|
vendorId: Buffer;
|
|
690
679
|
critical: boolean;
|
|
691
|
-
length: number;
|
|
692
680
|
constructor(nextPayload: payloadType, vendorId: Buffer, critical?: boolean, length?: number);
|
|
693
681
|
/**
|
|
694
682
|
* Parses a Vendor ID Payload from a buffer
|
|
@@ -732,11 +720,10 @@ export declare class PayloadVENDOR extends Payload {
|
|
|
732
720
|
*/
|
|
733
721
|
export declare class PayloadTS extends Payload {
|
|
734
722
|
nextPayload: payloadType;
|
|
735
|
-
|
|
723
|
+
tsType: payloadType;
|
|
736
724
|
tsList: TrafficSelector[];
|
|
737
725
|
critical: boolean;
|
|
738
|
-
|
|
739
|
-
constructor(nextPayload: payloadType, numTs: number, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
726
|
+
constructor(nextPayload: payloadType, tsType: payloadType, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
740
727
|
/**
|
|
741
728
|
* Parses a Traffic Selector Payload from a buffer
|
|
742
729
|
* @param buffer
|
|
@@ -779,11 +766,9 @@ export declare class PayloadTS extends Payload {
|
|
|
779
766
|
*/
|
|
780
767
|
export declare class PayloadTSi extends PayloadTS {
|
|
781
768
|
nextPayload: payloadType;
|
|
782
|
-
numTs: number;
|
|
783
769
|
tsList: TrafficSelector[];
|
|
784
770
|
critical: boolean;
|
|
785
|
-
|
|
786
|
-
constructor(nextPayload: payloadType, numTs: number, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
771
|
+
constructor(nextPayload: payloadType, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
787
772
|
}
|
|
788
773
|
/**
|
|
789
774
|
* IKEv2 Traffic Selector - Responder Payload
|
|
@@ -792,11 +777,9 @@ export declare class PayloadTSi extends PayloadTS {
|
|
|
792
777
|
*/
|
|
793
778
|
export declare class PayloadTSr extends PayloadTS {
|
|
794
779
|
nextPayload: payloadType;
|
|
795
|
-
numTs: number;
|
|
796
780
|
tsList: TrafficSelector[];
|
|
797
781
|
critical: boolean;
|
|
798
|
-
|
|
799
|
-
constructor(nextPayload: payloadType, numTs: number, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
782
|
+
constructor(nextPayload: payloadType, tsList: TrafficSelector[], critical?: boolean, length?: number);
|
|
800
783
|
}
|
|
801
784
|
/**
|
|
802
785
|
* IKEv2 Encrypted and Authenticated Payload
|
|
@@ -807,7 +790,6 @@ export declare class PayloadSK extends Payload {
|
|
|
807
790
|
nextPayload: payloadType;
|
|
808
791
|
encryptedData: Buffer;
|
|
809
792
|
critical: boolean;
|
|
810
|
-
length: number;
|
|
811
793
|
constructor(nextPayload: payloadType, encryptedData: Buffer, critical?: boolean, length?: number);
|
|
812
794
|
/**
|
|
813
795
|
* Parses an SK Payload from a buffer
|
|
@@ -914,7 +896,6 @@ export declare class PayloadCP extends Payload {
|
|
|
914
896
|
cfgType: number;
|
|
915
897
|
cfgData: Buffer;
|
|
916
898
|
critical: boolean;
|
|
917
|
-
length: number;
|
|
918
899
|
constructor(nextPayload: payloadType, cfgType: number, cfgData: Buffer, critical?: boolean, length?: number);
|
|
919
900
|
/**
|
|
920
901
|
* Parses a Configuration Payload from a buffer
|
|
@@ -960,7 +941,6 @@ export declare class PayloadEAP extends Payload {
|
|
|
960
941
|
nextPayload: payloadType;
|
|
961
942
|
eapMessage: Buffer;
|
|
962
943
|
critical: boolean;
|
|
963
|
-
length: number;
|
|
964
944
|
constructor(nextPayload: payloadType, eapMessage: Buffer, critical?: boolean, length?: number);
|
|
965
945
|
/**
|
|
966
946
|
* Parses an EAP Payload from a buffer
|
package/lib/src/payload.js
CHANGED
|
@@ -226,7 +226,6 @@ class PayloadSA extends Payload {
|
|
|
226
226
|
this.nextPayload = nextPayload;
|
|
227
227
|
this.proposals = proposals;
|
|
228
228
|
this.critical = critical;
|
|
229
|
-
this.length = length;
|
|
230
229
|
}
|
|
231
230
|
/**
|
|
232
231
|
* Parses a Security Association Payload from a buffer
|
|
@@ -339,7 +338,6 @@ class PayloadKE extends Payload {
|
|
|
339
338
|
this.dhGroup = dhGroup;
|
|
340
339
|
this.keyData = keyData;
|
|
341
340
|
this.critical = critical;
|
|
342
|
-
this.length = length;
|
|
343
341
|
}
|
|
344
342
|
/**
|
|
345
343
|
* Parses a Key Exchange Payload from a buffer
|
|
@@ -469,12 +467,11 @@ var IDType;
|
|
|
469
467
|
*/
|
|
470
468
|
class PayloadID extends Payload {
|
|
471
469
|
constructor(nextPayload, idType, idData, critical = false, length = 0) {
|
|
472
|
-
super(payloadType.NONE, nextPayload, critical, length > 0 ? length :
|
|
470
|
+
super(payloadType.NONE, nextPayload, critical, length > 0 ? length : 8 + idData.length);
|
|
473
471
|
this.nextPayload = nextPayload;
|
|
474
472
|
this.idType = idType;
|
|
475
473
|
this.idData = idData;
|
|
476
474
|
this.critical = critical;
|
|
477
|
-
this.length = length;
|
|
478
475
|
}
|
|
479
476
|
/**
|
|
480
477
|
* Parses an Identification Payload from a buffer
|
|
@@ -593,12 +590,11 @@ exports.PayloadID = PayloadID;
|
|
|
593
590
|
*/
|
|
594
591
|
class PayloadIDi extends PayloadID {
|
|
595
592
|
constructor(nextPayload, idType, idData, critical = false, length = 0) {
|
|
596
|
-
super(nextPayload, idType, idData, critical, length > 0 ? length :
|
|
593
|
+
super(nextPayload, idType, idData, critical, length > 0 ? length : 8 + idData.length);
|
|
597
594
|
this.nextPayload = nextPayload;
|
|
598
595
|
this.idType = idType;
|
|
599
596
|
this.idData = idData;
|
|
600
597
|
this.critical = critical;
|
|
601
|
-
this.length = length;
|
|
602
598
|
this.type = payloadType.IDi;
|
|
603
599
|
}
|
|
604
600
|
}
|
|
@@ -609,13 +605,12 @@ exports.PayloadIDi = PayloadIDi;
|
|
|
609
605
|
* @extends PayloadID
|
|
610
606
|
*/
|
|
611
607
|
class PayloadIDr extends PayloadID {
|
|
612
|
-
constructor(nextPayload, idType, idData, critical, length) {
|
|
613
|
-
super(nextPayload, idType, idData, critical, length > 0 ? length :
|
|
608
|
+
constructor(nextPayload, idType, idData, critical = false, length = 0) {
|
|
609
|
+
super(nextPayload, idType, idData, critical, length > 0 ? length : 8 + idData.length);
|
|
614
610
|
this.nextPayload = nextPayload;
|
|
615
611
|
this.idType = idType;
|
|
616
612
|
this.idData = idData;
|
|
617
613
|
this.critical = critical;
|
|
618
|
-
this.length = length;
|
|
619
614
|
this.type = payloadType.IDr;
|
|
620
615
|
}
|
|
621
616
|
}
|
|
@@ -654,7 +649,6 @@ class PayloadCERT extends Payload {
|
|
|
654
649
|
this.certEncoding = certEncoding;
|
|
655
650
|
this.certData = certData;
|
|
656
651
|
this.critical = critical;
|
|
657
|
-
this.length = length;
|
|
658
652
|
}
|
|
659
653
|
/**
|
|
660
654
|
* Parses a Certificate Payload from a buffer
|
|
@@ -740,7 +734,6 @@ class PayloadCERTREQ extends Payload {
|
|
|
740
734
|
this.certEncoding = certEncoding;
|
|
741
735
|
this.certAuthority = certAuthority;
|
|
742
736
|
this.critical = critical;
|
|
743
|
-
this.length = length;
|
|
744
737
|
}
|
|
745
738
|
/**
|
|
746
739
|
* Parses a Certificate Request Payload from a buffer
|
|
@@ -813,12 +806,11 @@ exports.PayloadCERTREQ = PayloadCERTREQ;
|
|
|
813
806
|
*/
|
|
814
807
|
class PayloadAUTH extends Payload {
|
|
815
808
|
constructor(nextPayload, authMethod, authData, critical = false, length = 0) {
|
|
816
|
-
super(payloadType.AUTH, nextPayload, critical, length > 0 ? length :
|
|
809
|
+
super(payloadType.AUTH, nextPayload, critical, length > 0 ? length : 8 + authData.length);
|
|
817
810
|
this.nextPayload = nextPayload;
|
|
818
811
|
this.authMethod = authMethod;
|
|
819
812
|
this.authData = authData;
|
|
820
813
|
this.critical = critical;
|
|
821
|
-
this.length = length;
|
|
822
814
|
}
|
|
823
815
|
/**
|
|
824
816
|
* Parses an Authentication Payload from a buffer
|
|
@@ -901,7 +893,6 @@ class PayloadNONCE extends Payload {
|
|
|
901
893
|
this.nextPayload = nextPayload;
|
|
902
894
|
this.nonceData = nonceData;
|
|
903
895
|
this.critical = critical;
|
|
904
|
-
this.length = length;
|
|
905
896
|
}
|
|
906
897
|
/**
|
|
907
898
|
* Parses a Nonce Payload from a buffer
|
|
@@ -1079,7 +1070,6 @@ class PayloadNOTIFY extends Payload {
|
|
|
1079
1070
|
this.spi = spi;
|
|
1080
1071
|
this.notifyData = notifyData;
|
|
1081
1072
|
this.critical = critical;
|
|
1082
|
-
this.length = length;
|
|
1083
1073
|
}
|
|
1084
1074
|
/**
|
|
1085
1075
|
* Parses a Notify Payload from a buffer
|
|
@@ -1176,7 +1166,6 @@ class PayloadDELETE extends Payload {
|
|
|
1176
1166
|
this.numSpi = numSpi;
|
|
1177
1167
|
this.spis = spis;
|
|
1178
1168
|
this.critical = critical;
|
|
1179
|
-
this.length = length;
|
|
1180
1169
|
}
|
|
1181
1170
|
/**
|
|
1182
1171
|
* Parses a Delete Payload from a buffer
|
|
@@ -1279,7 +1268,6 @@ class PayloadVENDOR extends Payload {
|
|
|
1279
1268
|
this.nextPayload = nextPayload;
|
|
1280
1269
|
this.vendorId = vendorId;
|
|
1281
1270
|
this.critical = critical;
|
|
1282
|
-
this.length = length;
|
|
1283
1271
|
}
|
|
1284
1272
|
/**
|
|
1285
1273
|
* Parses a Vendor ID Payload from a buffer
|
|
@@ -1347,13 +1335,12 @@ exports.PayloadVENDOR = PayloadVENDOR;
|
|
|
1347
1335
|
* @extends Payload
|
|
1348
1336
|
*/
|
|
1349
1337
|
class PayloadTS extends Payload {
|
|
1350
|
-
constructor(nextPayload,
|
|
1351
|
-
super(
|
|
1338
|
+
constructor(nextPayload, tsType, tsList, critical = false, length = 0) {
|
|
1339
|
+
super(tsType, nextPayload, critical, length > 0 ? length : 8 + tsList.reduce((acc, ts) => acc + ts.length, 0));
|
|
1352
1340
|
this.nextPayload = nextPayload;
|
|
1353
|
-
this.
|
|
1341
|
+
this.tsType = tsType;
|
|
1354
1342
|
this.tsList = tsList;
|
|
1355
1343
|
this.critical = critical;
|
|
1356
|
-
this.length = length;
|
|
1357
1344
|
}
|
|
1358
1345
|
/**
|
|
1359
1346
|
* Parses a Traffic Selector Payload from a buffer
|
|
@@ -1372,7 +1359,7 @@ class PayloadTS extends Payload {
|
|
|
1372
1359
|
tsList.push(ts);
|
|
1373
1360
|
offset += ts.length;
|
|
1374
1361
|
}
|
|
1375
|
-
return new PayloadTS(genericPayload.nextPayload,
|
|
1362
|
+
return new PayloadTS(genericPayload.nextPayload, genericPayload.type, tsList, genericPayload.critical, genericPayload.length);
|
|
1376
1363
|
}
|
|
1377
1364
|
/**
|
|
1378
1365
|
* Serializes a JSON representation of the TS payload to a buffer
|
|
@@ -1387,7 +1374,7 @@ class PayloadTS extends Payload {
|
|
|
1387
1374
|
const genericPayload = Payload.serializeJSON(json);
|
|
1388
1375
|
genericPayload.copy(buffer);
|
|
1389
1376
|
buffer.writeUInt8(json.numTs, 4);
|
|
1390
|
-
const tsListBuffer = ((_a = json.
|
|
1377
|
+
const tsListBuffer = ((_a = json.tsList) === null || _a === void 0 ? void 0 : _a.length) > 0
|
|
1391
1378
|
? json.tsList.map((ts) => selector_1.TrafficSelector.serializeJSON(ts))
|
|
1392
1379
|
: [Buffer.alloc(0)];
|
|
1393
1380
|
let offset = 8;
|
|
@@ -1404,13 +1391,16 @@ class PayloadTS extends Payload {
|
|
|
1404
1391
|
*/
|
|
1405
1392
|
serialize() {
|
|
1406
1393
|
// Encode deep first to calculate length
|
|
1394
|
+
if (this.tsList.length > 255) {
|
|
1395
|
+
throw new Error(`Too many traffic selectors ${this.tsList.length}`);
|
|
1396
|
+
}
|
|
1407
1397
|
const tsListBuffer = this.tsList.map((ts) => ts.serialize());
|
|
1408
1398
|
const tsBuffer = Buffer.concat(tsListBuffer);
|
|
1409
1399
|
// Fix the length
|
|
1410
|
-
this.length =
|
|
1400
|
+
this.length = 8 + tsBuffer.length;
|
|
1411
1401
|
const buffer = Buffer.alloc(this.length);
|
|
1412
1402
|
super.serialize().copy(buffer);
|
|
1413
|
-
buffer.writeUInt8(this.
|
|
1403
|
+
buffer.writeUInt8(this.tsList.length, 4);
|
|
1414
1404
|
// No need to blank 3 reserved bytes, Buffer.alloc does that
|
|
1415
1405
|
tsBuffer.copy(buffer, 8);
|
|
1416
1406
|
return buffer;
|
|
@@ -1422,7 +1412,6 @@ class PayloadTS extends Payload {
|
|
|
1422
1412
|
*/
|
|
1423
1413
|
toJSON() {
|
|
1424
1414
|
const json = super.genToJSON();
|
|
1425
|
-
json.numTs = this.numTs;
|
|
1426
1415
|
json.tsList = this.tsList.map((ts) => ts.toJSON());
|
|
1427
1416
|
return json;
|
|
1428
1417
|
}
|
|
@@ -1433,7 +1422,7 @@ class PayloadTS extends Payload {
|
|
|
1433
1422
|
*/
|
|
1434
1423
|
toString() {
|
|
1435
1424
|
const genericString = super.genToString();
|
|
1436
|
-
return `${genericString}\
|
|
1425
|
+
return `${genericString}\ntsList: ${this.tsList.map((ts) => ts.toString()).join(", ")}`;
|
|
1437
1426
|
}
|
|
1438
1427
|
}
|
|
1439
1428
|
exports.PayloadTS = PayloadTS;
|
|
@@ -1443,13 +1432,11 @@ exports.PayloadTS = PayloadTS;
|
|
|
1443
1432
|
* @extends Payload
|
|
1444
1433
|
*/
|
|
1445
1434
|
class PayloadTSi extends PayloadTS {
|
|
1446
|
-
constructor(nextPayload,
|
|
1447
|
-
super(nextPayload,
|
|
1435
|
+
constructor(nextPayload, tsList, critical = false, length = 0) {
|
|
1436
|
+
super(nextPayload, payloadType.TSi, tsList, critical, length);
|
|
1448
1437
|
this.nextPayload = nextPayload;
|
|
1449
|
-
this.numTs = numTs;
|
|
1450
1438
|
this.tsList = tsList;
|
|
1451
1439
|
this.critical = critical;
|
|
1452
|
-
this.length = length;
|
|
1453
1440
|
this.type = payloadType.TSi;
|
|
1454
1441
|
}
|
|
1455
1442
|
}
|
|
@@ -1460,13 +1447,11 @@ exports.PayloadTSi = PayloadTSi;
|
|
|
1460
1447
|
* @extends Payload
|
|
1461
1448
|
*/
|
|
1462
1449
|
class PayloadTSr extends PayloadTS {
|
|
1463
|
-
constructor(nextPayload,
|
|
1464
|
-
super(nextPayload,
|
|
1450
|
+
constructor(nextPayload, tsList, critical = false, length = 0) {
|
|
1451
|
+
super(nextPayload, payloadType.TSr, tsList, critical, length);
|
|
1465
1452
|
this.nextPayload = nextPayload;
|
|
1466
|
-
this.numTs = numTs;
|
|
1467
1453
|
this.tsList = tsList;
|
|
1468
1454
|
this.critical = critical;
|
|
1469
|
-
this.length = length;
|
|
1470
1455
|
this.type = payloadType.TSr;
|
|
1471
1456
|
}
|
|
1472
1457
|
}
|
|
@@ -1482,7 +1467,6 @@ class PayloadSK extends Payload {
|
|
|
1482
1467
|
this.nextPayload = nextPayload;
|
|
1483
1468
|
this.encryptedData = encryptedData;
|
|
1484
1469
|
this.critical = critical;
|
|
1485
|
-
this.length = length;
|
|
1486
1470
|
}
|
|
1487
1471
|
/**
|
|
1488
1472
|
* Parses an SK Payload from a buffer
|
|
@@ -1667,12 +1651,11 @@ var cfgType;
|
|
|
1667
1651
|
*/
|
|
1668
1652
|
class PayloadCP extends Payload {
|
|
1669
1653
|
constructor(nextPayload, cfgType, cfgData, critical = false, length = 0) {
|
|
1670
|
-
super(payloadType.CP, nextPayload, critical, length > 0 ? length :
|
|
1654
|
+
super(payloadType.CP, nextPayload, critical, length > 0 ? length : 8 + cfgData.length);
|
|
1671
1655
|
this.nextPayload = nextPayload;
|
|
1672
1656
|
this.cfgType = cfgType;
|
|
1673
1657
|
this.cfgData = cfgData;
|
|
1674
1658
|
this.critical = critical;
|
|
1675
|
-
this.length = length;
|
|
1676
1659
|
}
|
|
1677
1660
|
/**
|
|
1678
1661
|
* Parses a Configuration Payload from a buffer
|
|
@@ -1684,7 +1667,7 @@ class PayloadCP extends Payload {
|
|
|
1684
1667
|
static parse(buffer) {
|
|
1685
1668
|
const genericPayload = Payload.parse(buffer);
|
|
1686
1669
|
const cfgType = buffer.readUInt8(4);
|
|
1687
|
-
const cfgData = buffer.subarray(
|
|
1670
|
+
const cfgData = buffer.subarray(8, genericPayload.length);
|
|
1688
1671
|
return new PayloadCP(genericPayload.nextPayload, cfgType, cfgData, genericPayload.critical, genericPayload.length);
|
|
1689
1672
|
}
|
|
1690
1673
|
/**
|
|
@@ -1699,10 +1682,7 @@ class PayloadCP extends Payload {
|
|
|
1699
1682
|
const genericPayload = Payload.serializeJSON(json);
|
|
1700
1683
|
genericPayload.copy(buffer);
|
|
1701
1684
|
buffer.writeUInt8(json.cfgType, 4);
|
|
1702
|
-
//
|
|
1703
|
-
buffer.writeUInt8(0, 5);
|
|
1704
|
-
buffer.writeUInt8(0, 6);
|
|
1705
|
-
buffer.writeUInt8(0, 7);
|
|
1685
|
+
// 3-bytes reserved field as zeros in big-endian order
|
|
1706
1686
|
Buffer.from(json.cfgData, "hex").copy(buffer, 8);
|
|
1707
1687
|
return buffer;
|
|
1708
1688
|
}
|
|
@@ -1754,7 +1734,6 @@ class PayloadEAP extends Payload {
|
|
|
1754
1734
|
this.nextPayload = nextPayload;
|
|
1755
1735
|
this.eapMessage = eapMessage;
|
|
1756
1736
|
this.critical = critical;
|
|
1757
|
-
this.length = length;
|
|
1758
1737
|
}
|
|
1759
1738
|
/**
|
|
1760
1739
|
* Parses an EAP Payload from a buffer
|
package/lib/src/selector.d.ts
CHANGED
|
@@ -37,12 +37,12 @@ export declare enum TrafficSelectorType {
|
|
|
37
37
|
export declare class TrafficSelector {
|
|
38
38
|
type: number;
|
|
39
39
|
protocolId: number;
|
|
40
|
-
length: number;
|
|
41
40
|
startPort: number;
|
|
42
41
|
endPort: number;
|
|
43
42
|
startAddress: Buffer;
|
|
44
43
|
endAddress: Buffer;
|
|
45
|
-
|
|
44
|
+
length: number;
|
|
45
|
+
constructor(type: number, protocolId: number, startPort: number, endPort: number, startAddress: Buffer, endAddress: Buffer, length?: number);
|
|
46
46
|
/**
|
|
47
47
|
* Parses a Traffic Selector from a buffer
|
|
48
48
|
* @param buffer The buffer to parse from.
|