node-ikev2 0.1.2 → 0.1.4
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.
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Attribute Types
|
|
3
|
+
*
|
|
4
|
+
* See: https://datatracker.ietf.org/doc/html/rfc7296#section-3.15.1
|
|
5
|
+
*
|
|
6
|
+
* Attribute Type Value Multi-Valued Length
|
|
7
|
+
* ------------------------------------------------------------
|
|
8
|
+
* INTERNAL_IP4_ADDRESS 1 YES* 0 or 4 octets
|
|
9
|
+
* INTERNAL_IP4_NETMASK 2 NO 0 or 4 octets
|
|
10
|
+
* INTERNAL_IP4_DNS 3 YES 0 or 4 octets
|
|
11
|
+
* INTERNAL_IP4_NBNS 4 YES 0 or 4 octets
|
|
12
|
+
* INTERNAL_IP4_DHCP 6 YES 0 or 4 octets
|
|
13
|
+
* APPLICATION_VERSION 7 NO 0 or more
|
|
14
|
+
* INTERNAL_IP6_ADDRESS 8 YES* 0 or 17 octets
|
|
15
|
+
* INTERNAL_IP6_DNS 10 YES 0 or 16 octets
|
|
16
|
+
* INTERNAL_IP6_DHCP 12 YES 0 or 16 octets
|
|
17
|
+
* INTERNAL_IP4_SUBNET 13 YES 0 or 8 octets
|
|
18
|
+
* SUPPORTED_ATTRIBUTES 14 NO Multiple of 2
|
|
19
|
+
* INTERNAL_IP6_SUBNET 15 YES 17 octets
|
|
20
|
+
*
|
|
21
|
+
* See: https://www.iana.org/assignments/ikev2-parameters/ikev2-parameters.xhtml#ikev2-parameters-20
|
|
22
|
+
*
|
|
23
|
+
* Value Attribute Type Multi-Valued Length Reference
|
|
24
|
+
* 0 Reserved [RFC7296]
|
|
25
|
+
* 1 INTERNAL_IP4_ADDRESS YES* 0 or 4 octets [RFC7296]
|
|
26
|
+
* 2 INTERNAL_IP4_NETMASK NO 0 or 4 octets [RFC7296]
|
|
27
|
+
* 3 INTERNAL_IP4_DNS YES 0 or 4 octets [RFC7296]
|
|
28
|
+
* 4 INTERNAL_IP4_NBNS YES 0 or 4 octets [RFC7296]
|
|
29
|
+
* 5 Reserved [RFC7296]
|
|
30
|
+
* 6 INTERNAL_IP4_DHCP YES 0 or 4 octets [RFC7296]
|
|
31
|
+
* 7 APPLICATION_VERSION NO 0 or more [RFC7296]
|
|
32
|
+
* 8 INTERNAL_IP6_ADDRESS YES* 0 or 17 octets [RFC7296]
|
|
33
|
+
* 9 Reserved [RFC7296]
|
|
34
|
+
* 10 INTERNAL_IP6_DNS YES 0 or 16 octets [RFC7296]
|
|
35
|
+
* 11 Reserved [RFC7296]
|
|
36
|
+
* 12 INTERNAL_IP6_DHCP YES 0 or 16 octets [RFC7296]
|
|
37
|
+
* 13 INTERNAL_IP4_SUBNET YES 0 or 8 octets [RFC7296]
|
|
38
|
+
* 14 SUPPORTED_ATTRIBUTES NO Multiple of 2 [RFC7296]
|
|
39
|
+
* 15 INTERNAL_IP6_SUBNET YES 17 octets [RFC7296]
|
|
40
|
+
* 16 MIP6_HOME_PREFIX YES 0 or 21 octets [RFC5026]
|
|
41
|
+
* 17 INTERNAL_IP6_LINK NO 8 or more [RFC5739]
|
|
42
|
+
* 18 INTERNAL_IP6_PREFIX YES 17 octets [RFC5739]
|
|
43
|
+
* 19 HOME_AGENT_ADDRESS NO 16 or 20 [http://www.3gpp.org/ftp/Specs/html-info/24302.htm][John_Meredith]
|
|
44
|
+
* 20 P_CSCF_IP4_ADDRESS YES 0 or 4 octets [RFC7651]
|
|
45
|
+
* 21 P_CSCF_IP6_ADDRESS YES 0 or 16 octets [RFC7651]
|
|
46
|
+
* 22 FTT_KAT NO 2 octets [TS 24.302 12.6.0]
|
|
47
|
+
* 23 EXTERNAL_SOURCE_IP4_NAT_INFO NO 0 or 6 [TS 29.139][Kimmo_Kymalainen]
|
|
48
|
+
* 24 TIMEOUT_PERIOD_FOR_LIVENESS_CHECK NO 0 or 4 octets [TS 24.302 13.4.0][Frederic_Firmin]
|
|
49
|
+
* 25 INTERNAL_DNS_DOMAIN YES 0 or more [RFC8598]
|
|
50
|
+
* 26 INTERNAL_DNSSEC_TA YES 0 or more [RFC8598]
|
|
51
|
+
* 27 ENCDNS_IP4 YES 0 or more [RFC9464]
|
|
52
|
+
* 28 ENCDNS_IP6 YES 0 or more [RFC9464]
|
|
53
|
+
* 29 ENCDNS_DIGEST_INFO YES 0 or more [RFC9464]
|
|
54
|
+
* 30-16383 Unassigned
|
|
55
|
+
* 16384-32767 Reserved for Private Use [RFC7296]
|
|
56
|
+
*/
|
|
57
|
+
export declare enum configurationAttributeType {
|
|
58
|
+
INTERNAL_IP4_ADDRESS = 1,
|
|
59
|
+
INTERNAL_IP4_NETMASK = 2,
|
|
60
|
+
INTERNAL_IP4_DNS = 3,
|
|
61
|
+
INTERNAL_IP4_NBNS = 4,
|
|
62
|
+
INTERNAL_IP4_DHCP = 6,
|
|
63
|
+
APPLICATION_VERSION = 7,
|
|
64
|
+
INTERNAL_IP6_ADDRESS = 8,
|
|
65
|
+
INTERNAL_IP6_DNS = 10,
|
|
66
|
+
INTERNAL_IP6_DHCP = 12,
|
|
67
|
+
INTERNAL_IP4_SUBNET = 13,
|
|
68
|
+
SUPPORTED_ATTRIBUTES = 14,
|
|
69
|
+
INTERNAL_IP6_SUBNET = 15,
|
|
70
|
+
MIP6_HOME_PREFIX = 16,
|
|
71
|
+
INTERNAL_IP6_LINK = 17,
|
|
72
|
+
INTERNAL_IP6_PREFIX = 18,
|
|
73
|
+
HOME_AGENT_ADDRESS = 19,
|
|
74
|
+
P_CSCF_IP4_ADDRESS = 20,
|
|
75
|
+
P_CSCF_IP6_ADDRESS = 21,
|
|
76
|
+
FTT_KAT = 22,
|
|
77
|
+
EXTERNAL_SOURCE_IP4_NAT_INFO = 23,
|
|
78
|
+
TIMEOUT_PERIOD_FOR_LIVENESS_CHECK = 24,
|
|
79
|
+
INTERNAL_DNS_DOMAIN = 25,
|
|
80
|
+
INTERNAL_DNSSEC_TA = 26,
|
|
81
|
+
ENCDNS_IP4 = 27,
|
|
82
|
+
ENCDNS_IP6 = 28,
|
|
83
|
+
ENCDNS_DIGEST_INFO = 29
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Configuration Attributes
|
|
87
|
+
*
|
|
88
|
+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
89
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
90
|
+
* |R| Attribute Type | Length |
|
|
91
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
92
|
+
* | |
|
|
93
|
+
* ~ Value ~
|
|
94
|
+
* | |
|
|
95
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
96
|
+
*
|
|
97
|
+
* Figure 23: Configuration Attribute Format
|
|
98
|
+
*
|
|
99
|
+
* See: https://datatracker.ietf.org/doc/html/rfc7296#section-3.15.1
|
|
100
|
+
*
|
|
101
|
+
* As used in the PayloadCP
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
export declare class ConfigurationAttribute {
|
|
105
|
+
type: configurationAttributeType;
|
|
106
|
+
value: Buffer;
|
|
107
|
+
constructor(type: configurationAttributeType, value: Buffer);
|
|
108
|
+
/**
|
|
109
|
+
* Parses a ConfigurationAttribute from a Buffer
|
|
110
|
+
* @param {Buffer} buffer
|
|
111
|
+
* @static
|
|
112
|
+
* @public
|
|
113
|
+
* @returns {ConfigurationAttribute}
|
|
114
|
+
*/
|
|
115
|
+
static parse(buffer: Buffer): ConfigurationAttribute;
|
|
116
|
+
/**
|
|
117
|
+
* Serializes a Configuration Attribute from a JSON object
|
|
118
|
+
* @param {any} json
|
|
119
|
+
* @static
|
|
120
|
+
* @public
|
|
121
|
+
* @returns {Buffer}
|
|
122
|
+
*/
|
|
123
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
124
|
+
/**
|
|
125
|
+
* Serializes a Configuration Attribute to a Buffer
|
|
126
|
+
* @public
|
|
127
|
+
* @returns {Buffer}
|
|
128
|
+
*/
|
|
129
|
+
serialize(): Buffer;
|
|
130
|
+
/**
|
|
131
|
+
* Parses Configuration Attributes from a Buffer
|
|
132
|
+
* @param {Buffer} buffer
|
|
133
|
+
* @static
|
|
134
|
+
* @public
|
|
135
|
+
* @returns {ConfigurationAttribute[]}
|
|
136
|
+
*/
|
|
137
|
+
static parseConfigurationAttributes(buffer: Buffer): ConfigurationAttribute[];
|
|
138
|
+
/**
|
|
139
|
+
* Converts Configuration Attribute to JSON
|
|
140
|
+
* @public
|
|
141
|
+
* @returns {Record<string, any>} JSON object
|
|
142
|
+
*/
|
|
143
|
+
toJSON(): Record<string, any>;
|
|
144
|
+
/**
|
|
145
|
+
* Returns a string representation of the configuration attribute
|
|
146
|
+
* @public
|
|
147
|
+
* @returns {string}
|
|
148
|
+
*/
|
|
149
|
+
toString(): string;
|
|
150
|
+
}
|
|
151
|
+
export declare class INTERNAL_IP4_ADDRESS extends ConfigurationAttribute {
|
|
152
|
+
address: Buffer;
|
|
153
|
+
constructor(address: Buffer);
|
|
154
|
+
static parse(buffer: Buffer): INTERNAL_IP4_ADDRESS;
|
|
155
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
156
|
+
toJSON(): Record<string, any>;
|
|
157
|
+
toString(): string;
|
|
158
|
+
}
|
|
159
|
+
export declare class INTERNAL_IP4_NETMASK extends ConfigurationAttribute {
|
|
160
|
+
netmask: Buffer;
|
|
161
|
+
constructor(netmask: Buffer);
|
|
162
|
+
static parse(buffer: Buffer): INTERNAL_IP4_NETMASK;
|
|
163
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
164
|
+
toJSON(): Record<string, any>;
|
|
165
|
+
toString(): string;
|
|
166
|
+
}
|
|
167
|
+
export declare class INTERNAL_IP4_DNS extends ConfigurationAttribute {
|
|
168
|
+
dns: Buffer;
|
|
169
|
+
constructor(dns: Buffer);
|
|
170
|
+
static parse(buffer: Buffer): INTERNAL_IP4_DNS;
|
|
171
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
172
|
+
toJSON(): Record<string, any>;
|
|
173
|
+
toString(): string;
|
|
174
|
+
}
|
|
175
|
+
export declare class INTERNAL_IP4_NBNS extends ConfigurationAttribute {
|
|
176
|
+
nbns: Buffer;
|
|
177
|
+
constructor(nbns: Buffer);
|
|
178
|
+
static parse(buffer: Buffer): INTERNAL_IP4_NBNS;
|
|
179
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
180
|
+
toJSON(): Record<string, any>;
|
|
181
|
+
toString(): string;
|
|
182
|
+
}
|
|
183
|
+
export declare class INTERNAL_IP4_DHCP extends ConfigurationAttribute {
|
|
184
|
+
dhcp: Buffer;
|
|
185
|
+
constructor(dhcp: Buffer);
|
|
186
|
+
static parse(buffer: Buffer): INTERNAL_IP4_DHCP;
|
|
187
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
188
|
+
toJSON(): Record<string, any>;
|
|
189
|
+
toString(): string;
|
|
190
|
+
}
|
|
191
|
+
export declare class APPLICATION_VERSION extends ConfigurationAttribute {
|
|
192
|
+
versionString: string;
|
|
193
|
+
constructor(versionString: string);
|
|
194
|
+
static parse(buffer: Buffer): APPLICATION_VERSION;
|
|
195
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
196
|
+
toJSON(): Record<string, any>;
|
|
197
|
+
toString(): string;
|
|
198
|
+
}
|
|
199
|
+
export declare class INTERNAL_IP6_ADDRESS extends ConfigurationAttribute {
|
|
200
|
+
address: Buffer;
|
|
201
|
+
prefixLength: number;
|
|
202
|
+
constructor(address: Buffer, prefixLength: number);
|
|
203
|
+
static parse(buffer: Buffer): INTERNAL_IP6_ADDRESS;
|
|
204
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
205
|
+
toJSON(): Record<string, any>;
|
|
206
|
+
toString(): string;
|
|
207
|
+
}
|
|
208
|
+
export declare class INTERNAL_IP6_DNS extends ConfigurationAttribute {
|
|
209
|
+
dns: Buffer;
|
|
210
|
+
constructor(dns: Buffer);
|
|
211
|
+
static parse(buffer: Buffer): INTERNAL_IP6_DNS;
|
|
212
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
213
|
+
toJSON(): Record<string, any>;
|
|
214
|
+
toString(): string;
|
|
215
|
+
}
|
|
216
|
+
export declare class INTERNAL_IP6_DHCP extends ConfigurationAttribute {
|
|
217
|
+
dhcp: Buffer;
|
|
218
|
+
constructor(dhcp: Buffer);
|
|
219
|
+
static parse(buffer: Buffer): INTERNAL_IP6_DHCP;
|
|
220
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
221
|
+
toJSON(): Record<string, any>;
|
|
222
|
+
toString(): string;
|
|
223
|
+
}
|
|
224
|
+
export declare class INTERNAL_IP4_SUBNET extends ConfigurationAttribute {
|
|
225
|
+
address: Buffer;
|
|
226
|
+
netmask: Buffer;
|
|
227
|
+
constructor(address: Buffer, netmask: Buffer);
|
|
228
|
+
static parse(buffer: Buffer): INTERNAL_IP4_SUBNET;
|
|
229
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
230
|
+
toJSON(): Record<string, any>;
|
|
231
|
+
toString(): string;
|
|
232
|
+
}
|
|
233
|
+
export declare class SUPPORTED_ATTRIBUTES extends ConfigurationAttribute {
|
|
234
|
+
values: configurationAttributeType[];
|
|
235
|
+
constructor(values: configurationAttributeType[]);
|
|
236
|
+
static parse(buffer: Buffer): SUPPORTED_ATTRIBUTES;
|
|
237
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
238
|
+
toJSON(): Record<string, any>;
|
|
239
|
+
toString(): string;
|
|
240
|
+
}
|
|
241
|
+
export declare class INTERNAL_IP6_SUBNET extends ConfigurationAttribute {
|
|
242
|
+
address: Buffer;
|
|
243
|
+
prefixLength: number;
|
|
244
|
+
constructor(address: Buffer, prefixLength: number);
|
|
245
|
+
static parse(buffer: Buffer): INTERNAL_IP6_SUBNET;
|
|
246
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
247
|
+
toJSON(): Record<string, any>;
|
|
248
|
+
toString(): string;
|
|
249
|
+
}
|
|
250
|
+
export declare class P_CSCF_IP4_ADDRESS extends ConfigurationAttribute {
|
|
251
|
+
address: Buffer;
|
|
252
|
+
constructor(address: Buffer);
|
|
253
|
+
static parse(buffer: Buffer): P_CSCF_IP4_ADDRESS;
|
|
254
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
255
|
+
toJSON(): Record<string, any>;
|
|
256
|
+
toString(): string;
|
|
257
|
+
}
|
|
258
|
+
export declare class P_CSCF_IP6_ADDRESS extends ConfigurationAttribute {
|
|
259
|
+
address: Buffer;
|
|
260
|
+
constructor(address: Buffer);
|
|
261
|
+
static parse(buffer: Buffer): P_CSCF_IP6_ADDRESS;
|
|
262
|
+
static serializeJSON(json: Record<string, any>): Buffer;
|
|
263
|
+
toJSON(): Record<string, any>;
|
|
264
|
+
toString(): string;
|
|
265
|
+
}
|
|
266
|
+
export declare class CP_Attributes {
|
|
267
|
+
INTERNAL_IP4_ADDRESS: INTERNAL_IP4_ADDRESS[];
|
|
268
|
+
INTERNAL_IP4_NETMASK: INTERNAL_IP4_NETMASK | undefined;
|
|
269
|
+
INTERNAL_IP4_DNS: INTERNAL_IP4_DNS[];
|
|
270
|
+
INTERNAL_IP4_NBNS: INTERNAL_IP4_NBNS[];
|
|
271
|
+
INTERNAL_IP4_DHCP: INTERNAL_IP4_DHCP[];
|
|
272
|
+
APPLICATION_VERSION: APPLICATION_VERSION | undefined;
|
|
273
|
+
INTERNAL_IP6_ADDRESS: INTERNAL_IP6_ADDRESS[];
|
|
274
|
+
INTERNAL_IP6_DNS: INTERNAL_IP6_DNS[];
|
|
275
|
+
INTERNAL_IP6_DHCP: INTERNAL_IP6_DHCP[];
|
|
276
|
+
INTERNAL_IP4_SUBNET: INTERNAL_IP4_SUBNET[];
|
|
277
|
+
SUPPORTED_ATTRIBUTES: SUPPORTED_ATTRIBUTES | undefined;
|
|
278
|
+
INTERNAL_IP6_SUBNET: INTERNAL_IP6_SUBNET[];
|
|
279
|
+
P_CSCF_IP4_ADDRESS: P_CSCF_IP4_ADDRESS[];
|
|
280
|
+
P_CSCF_IP6_ADDRESS: P_CSCF_IP6_ADDRESS[];
|
|
281
|
+
OtherAttributes: ConfigurationAttribute[];
|
|
282
|
+
constructor();
|
|
283
|
+
parse(buffer: Buffer): void;
|
|
284
|
+
/**
|
|
285
|
+
* Serializes the configuration attributes to a buffer
|
|
286
|
+
* @public
|
|
287
|
+
* @returns {Buffer}
|
|
288
|
+
*/
|
|
289
|
+
serialize(): Buffer;
|
|
290
|
+
/**
|
|
291
|
+
* Converts Configuration Attribute to JSON
|
|
292
|
+
* @public
|
|
293
|
+
* @returns {Record<string, any>}
|
|
294
|
+
*/
|
|
295
|
+
toJSON(): Record<string, any>;
|
|
296
|
+
/**
|
|
297
|
+
* Returns a string representation of the configuration attributes
|
|
298
|
+
* @public
|
|
299
|
+
* @returns {string}
|
|
300
|
+
*/
|
|
301
|
+
toString(): string;
|
|
302
|
+
}
|
|
303
|
+
export declare function parseIPv4AddressString(addressString: string): Buffer;
|
|
304
|
+
export declare function formatIPv4AddressBuffer(buffer: Buffer): string;
|
|
305
|
+
export declare function parseIPv6AddressString(addressString: string): Buffer;
|
|
306
|
+
export declare function formatIPv6AddressBuffer(addressBuffer: Buffer): string;
|
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CP_Attributes = exports.P_CSCF_IP6_ADDRESS = exports.P_CSCF_IP4_ADDRESS = exports.INTERNAL_IP6_SUBNET = exports.SUPPORTED_ATTRIBUTES = exports.INTERNAL_IP4_SUBNET = exports.INTERNAL_IP6_DHCP = exports.INTERNAL_IP6_DNS = exports.INTERNAL_IP6_ADDRESS = exports.APPLICATION_VERSION = exports.INTERNAL_IP4_DHCP = exports.INTERNAL_IP4_NBNS = exports.INTERNAL_IP4_DNS = exports.INTERNAL_IP4_NETMASK = exports.INTERNAL_IP4_ADDRESS = exports.ConfigurationAttribute = exports.configurationAttributeType = void 0;
|
|
4
|
+
exports.parseIPv4AddressString = parseIPv4AddressString;
|
|
5
|
+
exports.formatIPv4AddressBuffer = formatIPv4AddressBuffer;
|
|
6
|
+
exports.parseIPv6AddressString = parseIPv6AddressString;
|
|
7
|
+
exports.formatIPv6AddressBuffer = formatIPv6AddressBuffer;
|
|
8
|
+
/**
|
|
9
|
+
* Configuration Attribute Types
|
|
10
|
+
*
|
|
11
|
+
* See: https://datatracker.ietf.org/doc/html/rfc7296#section-3.15.1
|
|
12
|
+
*
|
|
13
|
+
* Attribute Type Value Multi-Valued Length
|
|
14
|
+
* ------------------------------------------------------------
|
|
15
|
+
* INTERNAL_IP4_ADDRESS 1 YES* 0 or 4 octets
|
|
16
|
+
* INTERNAL_IP4_NETMASK 2 NO 0 or 4 octets
|
|
17
|
+
* INTERNAL_IP4_DNS 3 YES 0 or 4 octets
|
|
18
|
+
* INTERNAL_IP4_NBNS 4 YES 0 or 4 octets
|
|
19
|
+
* INTERNAL_IP4_DHCP 6 YES 0 or 4 octets
|
|
20
|
+
* APPLICATION_VERSION 7 NO 0 or more
|
|
21
|
+
* INTERNAL_IP6_ADDRESS 8 YES* 0 or 17 octets
|
|
22
|
+
* INTERNAL_IP6_DNS 10 YES 0 or 16 octets
|
|
23
|
+
* INTERNAL_IP6_DHCP 12 YES 0 or 16 octets
|
|
24
|
+
* INTERNAL_IP4_SUBNET 13 YES 0 or 8 octets
|
|
25
|
+
* SUPPORTED_ATTRIBUTES 14 NO Multiple of 2
|
|
26
|
+
* INTERNAL_IP6_SUBNET 15 YES 17 octets
|
|
27
|
+
*
|
|
28
|
+
* See: https://www.iana.org/assignments/ikev2-parameters/ikev2-parameters.xhtml#ikev2-parameters-20
|
|
29
|
+
*
|
|
30
|
+
* Value Attribute Type Multi-Valued Length Reference
|
|
31
|
+
* 0 Reserved [RFC7296]
|
|
32
|
+
* 1 INTERNAL_IP4_ADDRESS YES* 0 or 4 octets [RFC7296]
|
|
33
|
+
* 2 INTERNAL_IP4_NETMASK NO 0 or 4 octets [RFC7296]
|
|
34
|
+
* 3 INTERNAL_IP4_DNS YES 0 or 4 octets [RFC7296]
|
|
35
|
+
* 4 INTERNAL_IP4_NBNS YES 0 or 4 octets [RFC7296]
|
|
36
|
+
* 5 Reserved [RFC7296]
|
|
37
|
+
* 6 INTERNAL_IP4_DHCP YES 0 or 4 octets [RFC7296]
|
|
38
|
+
* 7 APPLICATION_VERSION NO 0 or more [RFC7296]
|
|
39
|
+
* 8 INTERNAL_IP6_ADDRESS YES* 0 or 17 octets [RFC7296]
|
|
40
|
+
* 9 Reserved [RFC7296]
|
|
41
|
+
* 10 INTERNAL_IP6_DNS YES 0 or 16 octets [RFC7296]
|
|
42
|
+
* 11 Reserved [RFC7296]
|
|
43
|
+
* 12 INTERNAL_IP6_DHCP YES 0 or 16 octets [RFC7296]
|
|
44
|
+
* 13 INTERNAL_IP4_SUBNET YES 0 or 8 octets [RFC7296]
|
|
45
|
+
* 14 SUPPORTED_ATTRIBUTES NO Multiple of 2 [RFC7296]
|
|
46
|
+
* 15 INTERNAL_IP6_SUBNET YES 17 octets [RFC7296]
|
|
47
|
+
* 16 MIP6_HOME_PREFIX YES 0 or 21 octets [RFC5026]
|
|
48
|
+
* 17 INTERNAL_IP6_LINK NO 8 or more [RFC5739]
|
|
49
|
+
* 18 INTERNAL_IP6_PREFIX YES 17 octets [RFC5739]
|
|
50
|
+
* 19 HOME_AGENT_ADDRESS NO 16 or 20 [http://www.3gpp.org/ftp/Specs/html-info/24302.htm][John_Meredith]
|
|
51
|
+
* 20 P_CSCF_IP4_ADDRESS YES 0 or 4 octets [RFC7651]
|
|
52
|
+
* 21 P_CSCF_IP6_ADDRESS YES 0 or 16 octets [RFC7651]
|
|
53
|
+
* 22 FTT_KAT NO 2 octets [TS 24.302 12.6.0]
|
|
54
|
+
* 23 EXTERNAL_SOURCE_IP4_NAT_INFO NO 0 or 6 [TS 29.139][Kimmo_Kymalainen]
|
|
55
|
+
* 24 TIMEOUT_PERIOD_FOR_LIVENESS_CHECK NO 0 or 4 octets [TS 24.302 13.4.0][Frederic_Firmin]
|
|
56
|
+
* 25 INTERNAL_DNS_DOMAIN YES 0 or more [RFC8598]
|
|
57
|
+
* 26 INTERNAL_DNSSEC_TA YES 0 or more [RFC8598]
|
|
58
|
+
* 27 ENCDNS_IP4 YES 0 or more [RFC9464]
|
|
59
|
+
* 28 ENCDNS_IP6 YES 0 or more [RFC9464]
|
|
60
|
+
* 29 ENCDNS_DIGEST_INFO YES 0 or more [RFC9464]
|
|
61
|
+
* 30-16383 Unassigned
|
|
62
|
+
* 16384-32767 Reserved for Private Use [RFC7296]
|
|
63
|
+
*/
|
|
64
|
+
var configurationAttributeType;
|
|
65
|
+
(function (configurationAttributeType) {
|
|
66
|
+
// Reserved 0
|
|
67
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_ADDRESS"] = 1] = "INTERNAL_IP4_ADDRESS";
|
|
68
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_NETMASK"] = 2] = "INTERNAL_IP4_NETMASK";
|
|
69
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_DNS"] = 3] = "INTERNAL_IP4_DNS";
|
|
70
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_NBNS"] = 4] = "INTERNAL_IP4_NBNS";
|
|
71
|
+
// Reserved 5
|
|
72
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_DHCP"] = 6] = "INTERNAL_IP4_DHCP";
|
|
73
|
+
configurationAttributeType[configurationAttributeType["APPLICATION_VERSION"] = 7] = "APPLICATION_VERSION";
|
|
74
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_ADDRESS"] = 8] = "INTERNAL_IP6_ADDRESS";
|
|
75
|
+
// Reserved 9
|
|
76
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_DNS"] = 10] = "INTERNAL_IP6_DNS";
|
|
77
|
+
// Reserved 11
|
|
78
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_DHCP"] = 12] = "INTERNAL_IP6_DHCP";
|
|
79
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP4_SUBNET"] = 13] = "INTERNAL_IP4_SUBNET";
|
|
80
|
+
configurationAttributeType[configurationAttributeType["SUPPORTED_ATTRIBUTES"] = 14] = "SUPPORTED_ATTRIBUTES";
|
|
81
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_SUBNET"] = 15] = "INTERNAL_IP6_SUBNET";
|
|
82
|
+
configurationAttributeType[configurationAttributeType["MIP6_HOME_PREFIX"] = 16] = "MIP6_HOME_PREFIX";
|
|
83
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_LINK"] = 17] = "INTERNAL_IP6_LINK";
|
|
84
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_IP6_PREFIX"] = 18] = "INTERNAL_IP6_PREFIX";
|
|
85
|
+
configurationAttributeType[configurationAttributeType["HOME_AGENT_ADDRESS"] = 19] = "HOME_AGENT_ADDRESS";
|
|
86
|
+
configurationAttributeType[configurationAttributeType["P_CSCF_IP4_ADDRESS"] = 20] = "P_CSCF_IP4_ADDRESS";
|
|
87
|
+
configurationAttributeType[configurationAttributeType["P_CSCF_IP6_ADDRESS"] = 21] = "P_CSCF_IP6_ADDRESS";
|
|
88
|
+
configurationAttributeType[configurationAttributeType["FTT_KAT"] = 22] = "FTT_KAT";
|
|
89
|
+
configurationAttributeType[configurationAttributeType["EXTERNAL_SOURCE_IP4_NAT_INFO"] = 23] = "EXTERNAL_SOURCE_IP4_NAT_INFO";
|
|
90
|
+
configurationAttributeType[configurationAttributeType["TIMEOUT_PERIOD_FOR_LIVENESS_CHECK"] = 24] = "TIMEOUT_PERIOD_FOR_LIVENESS_CHECK";
|
|
91
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_DNS_DOMAIN"] = 25] = "INTERNAL_DNS_DOMAIN";
|
|
92
|
+
configurationAttributeType[configurationAttributeType["INTERNAL_DNSSEC_TA"] = 26] = "INTERNAL_DNSSEC_TA";
|
|
93
|
+
configurationAttributeType[configurationAttributeType["ENCDNS_IP4"] = 27] = "ENCDNS_IP4";
|
|
94
|
+
configurationAttributeType[configurationAttributeType["ENCDNS_IP6"] = 28] = "ENCDNS_IP6";
|
|
95
|
+
configurationAttributeType[configurationAttributeType["ENCDNS_DIGEST_INFO"] = 29] = "ENCDNS_DIGEST_INFO";
|
|
96
|
+
// 30-16383 Unassigned
|
|
97
|
+
// 16384-32767 Reserved for Private Use
|
|
98
|
+
})(configurationAttributeType || (exports.configurationAttributeType = configurationAttributeType = {}));
|
|
99
|
+
/**
|
|
100
|
+
* Configuration Attributes
|
|
101
|
+
*
|
|
102
|
+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
103
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
104
|
+
* |R| Attribute Type | Length |
|
|
105
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
106
|
+
* | |
|
|
107
|
+
* ~ Value ~
|
|
108
|
+
* | |
|
|
109
|
+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
110
|
+
*
|
|
111
|
+
* Figure 23: Configuration Attribute Format
|
|
112
|
+
*
|
|
113
|
+
* See: https://datatracker.ietf.org/doc/html/rfc7296#section-3.15.1
|
|
114
|
+
*
|
|
115
|
+
* As used in the PayloadCP
|
|
116
|
+
*
|
|
117
|
+
*/
|
|
118
|
+
class ConfigurationAttribute {
|
|
119
|
+
constructor(type,
|
|
120
|
+
// public length: number,
|
|
121
|
+
value) {
|
|
122
|
+
this.type = type;
|
|
123
|
+
this.value = value;
|
|
124
|
+
if (type < 0 || type > 0x7fff) {
|
|
125
|
+
throw new Error("Invalid attribute type");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Parses a ConfigurationAttribute from a Buffer
|
|
130
|
+
* @param {Buffer} buffer
|
|
131
|
+
* @static
|
|
132
|
+
* @public
|
|
133
|
+
* @returns {ConfigurationAttribute}
|
|
134
|
+
*/
|
|
135
|
+
static parse(buffer) {
|
|
136
|
+
if (!Buffer.isBuffer(buffer)) {
|
|
137
|
+
throw new Error("Input must be a Buffer");
|
|
138
|
+
}
|
|
139
|
+
if (buffer.length < 4) {
|
|
140
|
+
throw new Error("Buffer too short for attribute header (minimum 4 bytes)");
|
|
141
|
+
}
|
|
142
|
+
const attributeType = buffer.readUInt16BE(0) & 0x7fff;
|
|
143
|
+
const length = buffer.readUInt16BE(2);
|
|
144
|
+
if (buffer.length < 4 + length) {
|
|
145
|
+
throw new Error(`Buffer too short for TLV attribute value. Expected ${4 + length} bytes, got ${buffer.length}`);
|
|
146
|
+
}
|
|
147
|
+
const value = buffer.subarray(4, 4 + length);
|
|
148
|
+
return new ConfigurationAttribute(attributeType, value);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Serializes a Configuration Attribute from a JSON object
|
|
152
|
+
* @param {any} json
|
|
153
|
+
* @static
|
|
154
|
+
* @public
|
|
155
|
+
* @returns {Buffer}
|
|
156
|
+
*/
|
|
157
|
+
static serializeJSON(json) {
|
|
158
|
+
const attributeType = json.attributeType;
|
|
159
|
+
const value = json.value;
|
|
160
|
+
const configurationAttribute = new ConfigurationAttribute(attributeType, value);
|
|
161
|
+
return configurationAttribute.serialize();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Serializes a Configuration Attribute to a Buffer
|
|
165
|
+
* @public
|
|
166
|
+
* @returns {Buffer}
|
|
167
|
+
*/
|
|
168
|
+
serialize() {
|
|
169
|
+
const buffer = Buffer.alloc(4 + this.value.length);
|
|
170
|
+
buffer.writeUInt16BE(this.type, 0);
|
|
171
|
+
buffer.writeUInt16BE(this.value.length, 2);
|
|
172
|
+
this.value.copy(buffer, 4);
|
|
173
|
+
return buffer;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Parses Configuration Attributes from a Buffer
|
|
177
|
+
* @param {Buffer} buffer
|
|
178
|
+
* @static
|
|
179
|
+
* @public
|
|
180
|
+
* @returns {ConfigurationAttribute[]}
|
|
181
|
+
*/
|
|
182
|
+
static parseConfigurationAttributes(buffer) {
|
|
183
|
+
const attributes = [];
|
|
184
|
+
let offset = 0;
|
|
185
|
+
while (offset < buffer.length) {
|
|
186
|
+
// const attributeType = buffer.readUInt16BE(offset) & 0x7fff;
|
|
187
|
+
const attributeLength = buffer.readUInt16BE(offset + 2);
|
|
188
|
+
const attributeBuffer = buffer.subarray(offset, offset + 4 + attributeLength);
|
|
189
|
+
const attribute = ConfigurationAttribute.parse(attributeBuffer);
|
|
190
|
+
attributes.push(attribute);
|
|
191
|
+
offset += 4 + attributeLength;
|
|
192
|
+
}
|
|
193
|
+
return attributes;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Converts Configuration Attribute to JSON
|
|
197
|
+
* @public
|
|
198
|
+
* @returns {Record<string, any>} JSON object
|
|
199
|
+
*/
|
|
200
|
+
toJSON() {
|
|
201
|
+
return {
|
|
202
|
+
attributeType: this.type,
|
|
203
|
+
value: this.value.toString("hex"),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Returns a string representation of the configuration attribute
|
|
208
|
+
* @public
|
|
209
|
+
* @returns {string}
|
|
210
|
+
*/
|
|
211
|
+
toString() {
|
|
212
|
+
const prettyJson = this.toJSON();
|
|
213
|
+
prettyJson.configurationAttributeType = `${configurationAttributeType[prettyJson.attributeType]} (${prettyJson.attributeType})`;
|
|
214
|
+
prettyJson.value = this.value.toString("hex");
|
|
215
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.ConfigurationAttribute = ConfigurationAttribute;
|
|
219
|
+
class INTERNAL_IP4_ADDRESS extends ConfigurationAttribute {
|
|
220
|
+
constructor(address) {
|
|
221
|
+
if (address.length !== 4) {
|
|
222
|
+
throw new Error("Invalid value length for INTERNAL_IP4_ADDRESS");
|
|
223
|
+
}
|
|
224
|
+
super(configurationAttributeType.INTERNAL_IP4_ADDRESS, address);
|
|
225
|
+
this.address = address;
|
|
226
|
+
}
|
|
227
|
+
static parse(buffer) {
|
|
228
|
+
if (buffer.length !== 4) {
|
|
229
|
+
throw new Error("Invalid value length for INTERNAL_IP4_ADDRESS");
|
|
230
|
+
}
|
|
231
|
+
return new INTERNAL_IP4_ADDRESS(buffer.subarray(0, 4));
|
|
232
|
+
}
|
|
233
|
+
static serializeJSON(json) {
|
|
234
|
+
const address = parseIPv4AddressString(json.address);
|
|
235
|
+
return new INTERNAL_IP4_ADDRESS(address).serialize();
|
|
236
|
+
}
|
|
237
|
+
toJSON() {
|
|
238
|
+
return {
|
|
239
|
+
address: formatIPv4AddressBuffer(this.address),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
toString() {
|
|
243
|
+
const prettyJson = this.toJSON();
|
|
244
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.INTERNAL_IP4_ADDRESS = INTERNAL_IP4_ADDRESS;
|
|
248
|
+
class INTERNAL_IP4_NETMASK extends ConfigurationAttribute {
|
|
249
|
+
constructor(netmask) {
|
|
250
|
+
if (netmask.length !== 4) {
|
|
251
|
+
throw new Error("Invalid value length for INTERNAL_IP4_NETMASK");
|
|
252
|
+
}
|
|
253
|
+
super(configurationAttributeType.INTERNAL_IP4_NETMASK, netmask);
|
|
254
|
+
this.netmask = netmask;
|
|
255
|
+
}
|
|
256
|
+
static parse(buffer) {
|
|
257
|
+
if (buffer.length !== 4) {
|
|
258
|
+
throw new Error("Invalid value length for INTERNAL_IP4_NETMASK");
|
|
259
|
+
}
|
|
260
|
+
return new INTERNAL_IP4_NETMASK(buffer.subarray(0, 4));
|
|
261
|
+
}
|
|
262
|
+
static serializeJSON(json) {
|
|
263
|
+
const netmask = parseIPv4AddressString(json.netmask);
|
|
264
|
+
return new INTERNAL_IP4_NETMASK(netmask).serialize();
|
|
265
|
+
}
|
|
266
|
+
toJSON() {
|
|
267
|
+
return {
|
|
268
|
+
netmask: formatIPv4AddressBuffer(this.netmask),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
toString() {
|
|
272
|
+
const prettyJson = this.toJSON();
|
|
273
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.INTERNAL_IP4_NETMASK = INTERNAL_IP4_NETMASK;
|
|
277
|
+
class INTERNAL_IP4_DNS extends ConfigurationAttribute {
|
|
278
|
+
constructor(dns) {
|
|
279
|
+
if (dns.length !== 4) {
|
|
280
|
+
throw new Error("Invalid value length for INTERNAL_IP4_DNS");
|
|
281
|
+
}
|
|
282
|
+
super(configurationAttributeType.INTERNAL_IP4_DNS, dns);
|
|
283
|
+
this.dns = dns;
|
|
284
|
+
}
|
|
285
|
+
static parse(buffer) {
|
|
286
|
+
if (buffer.length !== 4) {
|
|
287
|
+
throw new Error("Invalid value length for INTERNAL_IP4_DNS");
|
|
288
|
+
}
|
|
289
|
+
return new INTERNAL_IP4_DNS(buffer.subarray(0, 4));
|
|
290
|
+
}
|
|
291
|
+
static serializeJSON(json) {
|
|
292
|
+
const dns = parseIPv4AddressString(json.dns);
|
|
293
|
+
return new INTERNAL_IP4_DNS(dns).serialize();
|
|
294
|
+
}
|
|
295
|
+
toJSON() {
|
|
296
|
+
return {
|
|
297
|
+
dns: formatIPv4AddressBuffer(this.dns),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
toString() {
|
|
301
|
+
const prettyJson = this.toJSON();
|
|
302
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.INTERNAL_IP4_DNS = INTERNAL_IP4_DNS;
|
|
306
|
+
class INTERNAL_IP4_NBNS extends ConfigurationAttribute {
|
|
307
|
+
constructor(nbns) {
|
|
308
|
+
if (nbns.length !== 4) {
|
|
309
|
+
throw new Error("Invalid value length for INTERNAL_IP4_NBNS");
|
|
310
|
+
}
|
|
311
|
+
super(configurationAttributeType.INTERNAL_IP4_NBNS, nbns);
|
|
312
|
+
this.nbns = nbns;
|
|
313
|
+
}
|
|
314
|
+
static parse(buffer) {
|
|
315
|
+
if (buffer.length !== 4) {
|
|
316
|
+
throw new Error("Invalid value length for INTERNAL_IP4_NBNS");
|
|
317
|
+
}
|
|
318
|
+
return new INTERNAL_IP4_NBNS(buffer.subarray(0, 4));
|
|
319
|
+
}
|
|
320
|
+
static serializeJSON(json) {
|
|
321
|
+
const nbns = parseIPv4AddressString(json.nbns);
|
|
322
|
+
return new INTERNAL_IP4_NBNS(nbns).serialize();
|
|
323
|
+
}
|
|
324
|
+
toJSON() {
|
|
325
|
+
return {
|
|
326
|
+
nbns: formatIPv4AddressBuffer(this.nbns),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
toString() {
|
|
330
|
+
const prettyJson = this.toJSON();
|
|
331
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
exports.INTERNAL_IP4_NBNS = INTERNAL_IP4_NBNS;
|
|
335
|
+
class INTERNAL_IP4_DHCP extends ConfigurationAttribute {
|
|
336
|
+
constructor(dhcp) {
|
|
337
|
+
if (dhcp.length !== 4) {
|
|
338
|
+
throw new Error("Invalid value length for INTERNAL_IP4_DHCP");
|
|
339
|
+
}
|
|
340
|
+
super(configurationAttributeType.INTERNAL_IP4_DHCP, dhcp);
|
|
341
|
+
this.dhcp = dhcp;
|
|
342
|
+
}
|
|
343
|
+
static parse(buffer) {
|
|
344
|
+
if (buffer.length !== 4) {
|
|
345
|
+
throw new Error("Invalid value length for INTERNAL_IP4_DHCP");
|
|
346
|
+
}
|
|
347
|
+
return new INTERNAL_IP4_DHCP(buffer.subarray(0, 4));
|
|
348
|
+
}
|
|
349
|
+
static serializeJSON(json) {
|
|
350
|
+
const dhcp = parseIPv4AddressString(json.dhcp);
|
|
351
|
+
return new INTERNAL_IP4_DHCP(dhcp).serialize();
|
|
352
|
+
}
|
|
353
|
+
toJSON() {
|
|
354
|
+
return {
|
|
355
|
+
dhcp: formatIPv4AddressBuffer(this.dhcp),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
toString() {
|
|
359
|
+
const prettyJson = this.toJSON();
|
|
360
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.INTERNAL_IP4_DHCP = INTERNAL_IP4_DHCP;
|
|
364
|
+
class APPLICATION_VERSION extends ConfigurationAttribute {
|
|
365
|
+
constructor(versionString) {
|
|
366
|
+
super(configurationAttributeType.APPLICATION_VERSION, Buffer.from(versionString));
|
|
367
|
+
this.versionString = versionString;
|
|
368
|
+
}
|
|
369
|
+
static parse(buffer) {
|
|
370
|
+
return new APPLICATION_VERSION(buffer.toString("utf8"));
|
|
371
|
+
}
|
|
372
|
+
static serializeJSON(json) {
|
|
373
|
+
const versionString = json.versionString;
|
|
374
|
+
const applicationVersion = new APPLICATION_VERSION(versionString);
|
|
375
|
+
return applicationVersion.serialize();
|
|
376
|
+
}
|
|
377
|
+
toJSON() {
|
|
378
|
+
return {
|
|
379
|
+
versionString: this.versionString,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
toString() {
|
|
383
|
+
const prettyJson = this.toJSON();
|
|
384
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
exports.APPLICATION_VERSION = APPLICATION_VERSION;
|
|
388
|
+
class INTERNAL_IP6_ADDRESS extends ConfigurationAttribute {
|
|
389
|
+
constructor(address, prefixLength) {
|
|
390
|
+
if (address.length !== 16) {
|
|
391
|
+
throw new Error("Invalid value length for INTERNAL_IP6_ADDRESS");
|
|
392
|
+
}
|
|
393
|
+
if (prefixLength < 0 || prefixLength > 128) {
|
|
394
|
+
throw new Error("Invalid prefix length for INTERNAL_IP6_ADDRESS");
|
|
395
|
+
}
|
|
396
|
+
let value = Buffer.alloc(17);
|
|
397
|
+
address.copy(value, 0);
|
|
398
|
+
value.writeUInt8(prefixLength, 16);
|
|
399
|
+
super(configurationAttributeType.INTERNAL_IP6_ADDRESS, value);
|
|
400
|
+
this.address = address;
|
|
401
|
+
this.prefixLength = prefixLength;
|
|
402
|
+
}
|
|
403
|
+
static parse(buffer) {
|
|
404
|
+
if (buffer.length !== 17) {
|
|
405
|
+
throw new Error("Invalid value length for INTERNAL_IP6_ADDRESS");
|
|
406
|
+
}
|
|
407
|
+
return new INTERNAL_IP6_ADDRESS(buffer.subarray(0, 16), buffer.readUInt8(16));
|
|
408
|
+
}
|
|
409
|
+
static serializeJSON(json) {
|
|
410
|
+
const address = parseIPv6AddressString(json.address);
|
|
411
|
+
const prefixLength = json.prefixLength;
|
|
412
|
+
return new INTERNAL_IP6_ADDRESS(address, prefixLength).serialize();
|
|
413
|
+
}
|
|
414
|
+
toJSON() {
|
|
415
|
+
return {
|
|
416
|
+
address: formatIPv6AddressBuffer(this.address),
|
|
417
|
+
prefixLength: this.prefixLength,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
toString() {
|
|
421
|
+
const prettyJson = this.toJSON();
|
|
422
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
exports.INTERNAL_IP6_ADDRESS = INTERNAL_IP6_ADDRESS;
|
|
426
|
+
class INTERNAL_IP6_DNS extends ConfigurationAttribute {
|
|
427
|
+
constructor(dns) {
|
|
428
|
+
if (dns.length !== 16) {
|
|
429
|
+
throw new Error("Invalid value length for INTERNAL_IP6_DNS");
|
|
430
|
+
}
|
|
431
|
+
super(configurationAttributeType.INTERNAL_IP6_DNS, dns);
|
|
432
|
+
this.dns = dns;
|
|
433
|
+
}
|
|
434
|
+
static parse(buffer) {
|
|
435
|
+
if (buffer.length !== 16) {
|
|
436
|
+
throw new Error("Invalid value length for INTERNAL_IP6_DNS");
|
|
437
|
+
}
|
|
438
|
+
return new INTERNAL_IP6_DNS(buffer.subarray(0, 16));
|
|
439
|
+
}
|
|
440
|
+
static serializeJSON(json) {
|
|
441
|
+
const dns = parseIPv6AddressString(json.dns);
|
|
442
|
+
return new INTERNAL_IP6_DNS(dns).serialize();
|
|
443
|
+
}
|
|
444
|
+
toJSON() {
|
|
445
|
+
return {
|
|
446
|
+
dns: formatIPv6AddressBuffer(this.dns),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
toString() {
|
|
450
|
+
const prettyJson = this.toJSON();
|
|
451
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
exports.INTERNAL_IP6_DNS = INTERNAL_IP6_DNS;
|
|
455
|
+
class INTERNAL_IP6_DHCP extends ConfigurationAttribute {
|
|
456
|
+
constructor(dhcp) {
|
|
457
|
+
if (dhcp.length !== 16) {
|
|
458
|
+
throw new Error("Invalid value length for INTERNAL_IP6_DHCP");
|
|
459
|
+
}
|
|
460
|
+
super(configurationAttributeType.INTERNAL_IP6_DHCP, dhcp);
|
|
461
|
+
this.dhcp = dhcp;
|
|
462
|
+
}
|
|
463
|
+
static parse(buffer) {
|
|
464
|
+
if (buffer.length !== 16) {
|
|
465
|
+
throw new Error("Invalid value length for INTERNAL_IP6_DHCP");
|
|
466
|
+
}
|
|
467
|
+
return new INTERNAL_IP6_DHCP(buffer.subarray(0, 16));
|
|
468
|
+
}
|
|
469
|
+
static serializeJSON(json) {
|
|
470
|
+
const dhcp = parseIPv6AddressString(json.dhcp);
|
|
471
|
+
return new INTERNAL_IP6_DHCP(dhcp).serialize();
|
|
472
|
+
}
|
|
473
|
+
toJSON() {
|
|
474
|
+
return {
|
|
475
|
+
dhcp: formatIPv6AddressBuffer(this.dhcp),
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
toString() {
|
|
479
|
+
const prettyJson = this.toJSON();
|
|
480
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
exports.INTERNAL_IP6_DHCP = INTERNAL_IP6_DHCP;
|
|
484
|
+
class INTERNAL_IP4_SUBNET extends ConfigurationAttribute {
|
|
485
|
+
constructor(address, netmask) {
|
|
486
|
+
if (address.length !== 4) {
|
|
487
|
+
throw new Error("Invalid value length for INTERNAL_IP4_SUBNET");
|
|
488
|
+
}
|
|
489
|
+
if (netmask.length !== 4) {
|
|
490
|
+
throw new Error("Invalid value length for INTERNAL_IP4_SUBNET");
|
|
491
|
+
}
|
|
492
|
+
let value = Buffer.alloc(8);
|
|
493
|
+
address.copy(value, 0);
|
|
494
|
+
netmask.copy(value, 4);
|
|
495
|
+
super(configurationAttributeType.INTERNAL_IP4_SUBNET, value);
|
|
496
|
+
this.address = address;
|
|
497
|
+
this.netmask = netmask;
|
|
498
|
+
}
|
|
499
|
+
static parse(buffer) {
|
|
500
|
+
if (buffer.length !== 8) {
|
|
501
|
+
throw new Error("Invalid value length for INTERNAL_IP4_SUBNET");
|
|
502
|
+
}
|
|
503
|
+
return new INTERNAL_IP4_SUBNET(buffer.subarray(0, 4), buffer.subarray(4, 8));
|
|
504
|
+
}
|
|
505
|
+
static serializeJSON(json) {
|
|
506
|
+
const address = parseIPv4AddressString(json.address);
|
|
507
|
+
const netmask = parseIPv4AddressString(json.netmask);
|
|
508
|
+
return new INTERNAL_IP4_SUBNET(address, netmask).serialize();
|
|
509
|
+
}
|
|
510
|
+
toJSON() {
|
|
511
|
+
return {
|
|
512
|
+
address: formatIPv4AddressBuffer(this.address),
|
|
513
|
+
netmask: formatIPv4AddressBuffer(this.netmask),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
toString() {
|
|
517
|
+
const prettyJson = this.toJSON();
|
|
518
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
exports.INTERNAL_IP4_SUBNET = INTERNAL_IP4_SUBNET;
|
|
522
|
+
class SUPPORTED_ATTRIBUTES extends ConfigurationAttribute {
|
|
523
|
+
constructor(values) {
|
|
524
|
+
let value = Buffer.alloc(values.length * 2);
|
|
525
|
+
values.forEach((cfgAttrType, index) => {
|
|
526
|
+
value.writeUInt16BE(cfgAttrType, index * 2);
|
|
527
|
+
});
|
|
528
|
+
super(configurationAttributeType.SUPPORTED_ATTRIBUTES, value);
|
|
529
|
+
this.values = values;
|
|
530
|
+
}
|
|
531
|
+
static parse(buffer) {
|
|
532
|
+
if (buffer.length % 2 !== 0) {
|
|
533
|
+
throw new Error("Invalid value length for SUPPORTED_ATTRIBUTES");
|
|
534
|
+
}
|
|
535
|
+
const values = [];
|
|
536
|
+
for (let i = 0; i < buffer.length; i += 2) {
|
|
537
|
+
values.push(buffer.readUInt16BE(i));
|
|
538
|
+
}
|
|
539
|
+
return new SUPPORTED_ATTRIBUTES(values);
|
|
540
|
+
}
|
|
541
|
+
static serializeJSON(json) {
|
|
542
|
+
return new SUPPORTED_ATTRIBUTES(json.values).serialize();
|
|
543
|
+
}
|
|
544
|
+
toJSON() {
|
|
545
|
+
return {
|
|
546
|
+
values: this.values,
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
toString() {
|
|
550
|
+
const prettyJson = this.toJSON();
|
|
551
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
exports.SUPPORTED_ATTRIBUTES = SUPPORTED_ATTRIBUTES;
|
|
555
|
+
class INTERNAL_IP6_SUBNET extends ConfigurationAttribute {
|
|
556
|
+
constructor(address, prefixLength) {
|
|
557
|
+
if (address.length !== 16) {
|
|
558
|
+
throw new Error("Invalid value length for INTERNAL_IP6_SUBNET");
|
|
559
|
+
}
|
|
560
|
+
if (prefixLength < 0 || prefixLength > 128) {
|
|
561
|
+
throw new Error("Invalid prefix length for INTERNAL_IP6_SUBNET");
|
|
562
|
+
}
|
|
563
|
+
let value = Buffer.alloc(17);
|
|
564
|
+
address.copy(value, 0);
|
|
565
|
+
value.writeUInt8(prefixLength, 16);
|
|
566
|
+
super(configurationAttributeType.INTERNAL_IP6_SUBNET, value);
|
|
567
|
+
this.address = address;
|
|
568
|
+
this.prefixLength = prefixLength;
|
|
569
|
+
}
|
|
570
|
+
static parse(buffer) {
|
|
571
|
+
if (buffer.length !== 17) {
|
|
572
|
+
throw new Error("Invalid value length for INTERNAL_IP6_SUBNET");
|
|
573
|
+
}
|
|
574
|
+
return new INTERNAL_IP6_SUBNET(buffer.subarray(0, 16), buffer.readUInt8(16));
|
|
575
|
+
}
|
|
576
|
+
static serializeJSON(json) {
|
|
577
|
+
const address = parseIPv6AddressString(json.address);
|
|
578
|
+
const prefixLength = json.prefixLength;
|
|
579
|
+
return new INTERNAL_IP6_SUBNET(address, prefixLength).serialize();
|
|
580
|
+
}
|
|
581
|
+
toJSON() {
|
|
582
|
+
return {
|
|
583
|
+
address: formatIPv6AddressBuffer(this.address),
|
|
584
|
+
prefixLength: this.prefixLength,
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
toString() {
|
|
588
|
+
const prettyJson = this.toJSON();
|
|
589
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
exports.INTERNAL_IP6_SUBNET = INTERNAL_IP6_SUBNET;
|
|
593
|
+
class P_CSCF_IP4_ADDRESS extends ConfigurationAttribute {
|
|
594
|
+
constructor(address) {
|
|
595
|
+
if (address.length !== 4) {
|
|
596
|
+
throw new Error("Invalid value length for P_CSCF_IP4_ADDRESS");
|
|
597
|
+
}
|
|
598
|
+
super(configurationAttributeType.P_CSCF_IP4_ADDRESS, address);
|
|
599
|
+
this.address = address;
|
|
600
|
+
}
|
|
601
|
+
static parse(buffer) {
|
|
602
|
+
if (buffer.length !== 4) {
|
|
603
|
+
throw new Error("Invalid value length for P_CSCF_IP4_ADDRESS");
|
|
604
|
+
}
|
|
605
|
+
return new P_CSCF_IP4_ADDRESS(buffer.subarray(0, 4));
|
|
606
|
+
}
|
|
607
|
+
static serializeJSON(json) {
|
|
608
|
+
const address = parseIPv4AddressString(json.address);
|
|
609
|
+
return new P_CSCF_IP4_ADDRESS(address).serialize();
|
|
610
|
+
}
|
|
611
|
+
toJSON() {
|
|
612
|
+
return {
|
|
613
|
+
address: formatIPv4AddressBuffer(this.address),
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
toString() {
|
|
617
|
+
const prettyJson = this.toJSON();
|
|
618
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
exports.P_CSCF_IP4_ADDRESS = P_CSCF_IP4_ADDRESS;
|
|
622
|
+
class P_CSCF_IP6_ADDRESS extends ConfigurationAttribute {
|
|
623
|
+
constructor(address) {
|
|
624
|
+
if (address.length !== 16) {
|
|
625
|
+
throw new Error("Invalid value length for P_CSCF_IP6_ADDRESS");
|
|
626
|
+
}
|
|
627
|
+
super(configurationAttributeType.P_CSCF_IP6_ADDRESS, address);
|
|
628
|
+
this.address = address;
|
|
629
|
+
}
|
|
630
|
+
static parse(buffer) {
|
|
631
|
+
if (buffer.length !== 16) {
|
|
632
|
+
throw new Error("Invalid value length for P_CSCF_IP6_ADDRESS");
|
|
633
|
+
}
|
|
634
|
+
return new P_CSCF_IP6_ADDRESS(buffer.subarray(0, 16));
|
|
635
|
+
}
|
|
636
|
+
static serializeJSON(json) {
|
|
637
|
+
const address = parseIPv6AddressString(json.address);
|
|
638
|
+
return new P_CSCF_IP6_ADDRESS(address).serialize();
|
|
639
|
+
}
|
|
640
|
+
toJSON() {
|
|
641
|
+
return {
|
|
642
|
+
address: formatIPv6AddressBuffer(this.address),
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
toString() {
|
|
646
|
+
const prettyJson = this.toJSON();
|
|
647
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
exports.P_CSCF_IP6_ADDRESS = P_CSCF_IP6_ADDRESS;
|
|
651
|
+
class CP_Attributes {
|
|
652
|
+
constructor() {
|
|
653
|
+
this.INTERNAL_IP4_ADDRESS = [];
|
|
654
|
+
this.INTERNAL_IP4_NETMASK = undefined;
|
|
655
|
+
this.INTERNAL_IP4_DNS = [];
|
|
656
|
+
this.INTERNAL_IP4_NBNS = [];
|
|
657
|
+
this.INTERNAL_IP4_DHCP = [];
|
|
658
|
+
this.APPLICATION_VERSION = undefined;
|
|
659
|
+
this.INTERNAL_IP6_ADDRESS = [];
|
|
660
|
+
this.INTERNAL_IP6_DNS = [];
|
|
661
|
+
this.INTERNAL_IP6_DHCP = [];
|
|
662
|
+
this.INTERNAL_IP4_SUBNET = [];
|
|
663
|
+
this.SUPPORTED_ATTRIBUTES = undefined;
|
|
664
|
+
this.INTERNAL_IP6_SUBNET = [];
|
|
665
|
+
this.P_CSCF_IP4_ADDRESS = [];
|
|
666
|
+
this.P_CSCF_IP6_ADDRESS = [];
|
|
667
|
+
this.OtherAttributes = [];
|
|
668
|
+
}
|
|
669
|
+
parse(buffer) {
|
|
670
|
+
let attributes = ConfigurationAttribute.parseConfigurationAttributes(buffer);
|
|
671
|
+
for (let attribute of attributes) {
|
|
672
|
+
switch (attribute.type) {
|
|
673
|
+
case configurationAttributeType.INTERNAL_IP4_ADDRESS:
|
|
674
|
+
this.INTERNAL_IP4_ADDRESS.push(INTERNAL_IP4_ADDRESS.parse(attribute.value));
|
|
675
|
+
break;
|
|
676
|
+
case configurationAttributeType.INTERNAL_IP4_NETMASK:
|
|
677
|
+
this.INTERNAL_IP4_NETMASK = INTERNAL_IP4_NETMASK.parse(attribute.value);
|
|
678
|
+
break;
|
|
679
|
+
case configurationAttributeType.INTERNAL_IP4_DNS:
|
|
680
|
+
this.INTERNAL_IP4_DNS.push(INTERNAL_IP4_DNS.parse(attribute.value));
|
|
681
|
+
break;
|
|
682
|
+
case configurationAttributeType.INTERNAL_IP4_NBNS:
|
|
683
|
+
this.INTERNAL_IP4_NBNS.push(INTERNAL_IP4_NBNS.parse(attribute.value));
|
|
684
|
+
break;
|
|
685
|
+
case configurationAttributeType.INTERNAL_IP4_DHCP:
|
|
686
|
+
this.INTERNAL_IP4_DHCP.push(INTERNAL_IP4_DHCP.parse(attribute.value));
|
|
687
|
+
break;
|
|
688
|
+
case configurationAttributeType.APPLICATION_VERSION:
|
|
689
|
+
this.APPLICATION_VERSION = APPLICATION_VERSION.parse(attribute.value);
|
|
690
|
+
break;
|
|
691
|
+
case configurationAttributeType.INTERNAL_IP6_ADDRESS:
|
|
692
|
+
this.INTERNAL_IP6_ADDRESS.push(INTERNAL_IP6_ADDRESS.parse(attribute.value));
|
|
693
|
+
break;
|
|
694
|
+
case configurationAttributeType.INTERNAL_IP6_DNS:
|
|
695
|
+
this.INTERNAL_IP6_DNS.push(INTERNAL_IP6_DNS.parse(attribute.value));
|
|
696
|
+
break;
|
|
697
|
+
case configurationAttributeType.INTERNAL_IP6_DHCP:
|
|
698
|
+
this.INTERNAL_IP6_DHCP.push(INTERNAL_IP6_DHCP.parse(attribute.value));
|
|
699
|
+
break;
|
|
700
|
+
case configurationAttributeType.INTERNAL_IP4_SUBNET:
|
|
701
|
+
this.INTERNAL_IP4_SUBNET.push(INTERNAL_IP4_SUBNET.parse(attribute.value));
|
|
702
|
+
break;
|
|
703
|
+
case configurationAttributeType.SUPPORTED_ATTRIBUTES:
|
|
704
|
+
this.SUPPORTED_ATTRIBUTES = SUPPORTED_ATTRIBUTES.parse(attribute.value);
|
|
705
|
+
break;
|
|
706
|
+
case configurationAttributeType.INTERNAL_IP6_SUBNET:
|
|
707
|
+
this.INTERNAL_IP6_SUBNET.push(INTERNAL_IP6_SUBNET.parse(attribute.value));
|
|
708
|
+
break;
|
|
709
|
+
case configurationAttributeType.P_CSCF_IP4_ADDRESS:
|
|
710
|
+
this.P_CSCF_IP4_ADDRESS.push(P_CSCF_IP4_ADDRESS.parse(attribute.value));
|
|
711
|
+
break;
|
|
712
|
+
case configurationAttributeType.P_CSCF_IP6_ADDRESS:
|
|
713
|
+
this.P_CSCF_IP6_ADDRESS.push(P_CSCF_IP6_ADDRESS.parse(attribute.value));
|
|
714
|
+
break;
|
|
715
|
+
default:
|
|
716
|
+
this.OtherAttributes.push(attribute);
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Serializes the configuration attributes to a buffer
|
|
723
|
+
* @public
|
|
724
|
+
* @returns {Buffer}
|
|
725
|
+
*/
|
|
726
|
+
serialize() {
|
|
727
|
+
let buffer = Buffer.alloc(0);
|
|
728
|
+
for (let attribute of this.INTERNAL_IP4_ADDRESS) {
|
|
729
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
730
|
+
}
|
|
731
|
+
if (this.INTERNAL_IP4_NETMASK) {
|
|
732
|
+
buffer = Buffer.concat([buffer, this.INTERNAL_IP4_NETMASK.serialize()]);
|
|
733
|
+
}
|
|
734
|
+
for (let attribute of this.INTERNAL_IP4_DNS) {
|
|
735
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
736
|
+
}
|
|
737
|
+
for (let attribute of this.INTERNAL_IP4_NBNS) {
|
|
738
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
739
|
+
}
|
|
740
|
+
for (let attribute of this.INTERNAL_IP4_DHCP) {
|
|
741
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
742
|
+
}
|
|
743
|
+
if (this.APPLICATION_VERSION) {
|
|
744
|
+
buffer = Buffer.concat([buffer, this.APPLICATION_VERSION.serialize()]);
|
|
745
|
+
}
|
|
746
|
+
for (let attribute of this.INTERNAL_IP6_ADDRESS) {
|
|
747
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
748
|
+
}
|
|
749
|
+
for (let attribute of this.INTERNAL_IP6_DNS) {
|
|
750
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
751
|
+
}
|
|
752
|
+
for (let attribute of this.INTERNAL_IP6_DHCP) {
|
|
753
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
754
|
+
}
|
|
755
|
+
for (let attribute of this.INTERNAL_IP4_SUBNET) {
|
|
756
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
757
|
+
}
|
|
758
|
+
if (this.SUPPORTED_ATTRIBUTES) {
|
|
759
|
+
buffer = Buffer.concat([buffer, this.SUPPORTED_ATTRIBUTES.serialize()]);
|
|
760
|
+
}
|
|
761
|
+
for (let attribute of this.INTERNAL_IP6_SUBNET) {
|
|
762
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
763
|
+
}
|
|
764
|
+
for (let attribute of this.P_CSCF_IP4_ADDRESS) {
|
|
765
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
766
|
+
}
|
|
767
|
+
for (let attribute of this.P_CSCF_IP6_ADDRESS) {
|
|
768
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
769
|
+
}
|
|
770
|
+
for (let attribute of this.OtherAttributes) {
|
|
771
|
+
buffer = Buffer.concat([buffer, attribute.serialize()]);
|
|
772
|
+
}
|
|
773
|
+
return buffer;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Converts Configuration Attribute to JSON
|
|
777
|
+
* @public
|
|
778
|
+
* @returns {Record<string, any>}
|
|
779
|
+
*/
|
|
780
|
+
toJSON() {
|
|
781
|
+
return {
|
|
782
|
+
INTERNAL_IP4_ADDRESS: this.INTERNAL_IP4_ADDRESS,
|
|
783
|
+
INTERNAL_IP4_NETMASK: this.INTERNAL_IP4_NETMASK,
|
|
784
|
+
INTERNAL_IP4_DNS: this.INTERNAL_IP4_DNS,
|
|
785
|
+
INTERNAL_IP4_NBNS: this.INTERNAL_IP4_NBNS,
|
|
786
|
+
INTERNAL_IP4_DHCP: this.INTERNAL_IP4_DHCP,
|
|
787
|
+
APPLICATION_VERSION: this.APPLICATION_VERSION,
|
|
788
|
+
INTERNAL_IP6_ADDRESS: this.INTERNAL_IP6_ADDRESS,
|
|
789
|
+
INTERNAL_IP6_DNS: this.INTERNAL_IP6_DNS,
|
|
790
|
+
INTERNAL_IP6_DHCP: this.INTERNAL_IP6_DHCP,
|
|
791
|
+
INTERNAL_IP4_SUBNET: this.INTERNAL_IP4_SUBNET,
|
|
792
|
+
SUPPORTED_ATTRIBUTES: this.SUPPORTED_ATTRIBUTES,
|
|
793
|
+
INTERNAL_IP6_SUBNET: this.INTERNAL_IP6_SUBNET,
|
|
794
|
+
P_CSCF_IP4_ADDRESS: this.P_CSCF_IP4_ADDRESS,
|
|
795
|
+
P_CSCF_IP6_ADDRESS: this.P_CSCF_IP6_ADDRESS,
|
|
796
|
+
OtherAttributes: this.OtherAttributes,
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Returns a string representation of the configuration attributes
|
|
801
|
+
* @public
|
|
802
|
+
* @returns {string}
|
|
803
|
+
*/
|
|
804
|
+
toString() {
|
|
805
|
+
const prettyJson = this.toJSON();
|
|
806
|
+
return JSON.stringify(prettyJson, null, 2);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
exports.CP_Attributes = CP_Attributes;
|
|
810
|
+
function parseIPv4AddressString(addressString) {
|
|
811
|
+
const buffer = Buffer.alloc(4);
|
|
812
|
+
const stringParts = addressString.split('.');
|
|
813
|
+
const parts = stringParts.map(p => {
|
|
814
|
+
if (!/^\d+$/.test(p)) {
|
|
815
|
+
throw new Error(`Invalid IPv4 address: part "${p}" contains non-digit characters.`);
|
|
816
|
+
}
|
|
817
|
+
const parsed = parseInt(p, 10);
|
|
818
|
+
if (parsed < 0 || parsed > 255) {
|
|
819
|
+
throw new Error(`Invalid IPv4 address: part "${p}" is not a valid octet.`);
|
|
820
|
+
}
|
|
821
|
+
return parsed;
|
|
822
|
+
});
|
|
823
|
+
if (parts.length !== 4) {
|
|
824
|
+
throw new Error("Invalid IPv4 address");
|
|
825
|
+
}
|
|
826
|
+
buffer.writeUInt8(parts[0], 0);
|
|
827
|
+
buffer.writeUInt8(parts[1], 1);
|
|
828
|
+
buffer.writeUInt8(parts[2], 2);
|
|
829
|
+
buffer.writeUInt8(parts[3], 3);
|
|
830
|
+
return buffer;
|
|
831
|
+
}
|
|
832
|
+
function formatIPv4AddressBuffer(buffer) {
|
|
833
|
+
if (buffer.length !== 4) {
|
|
834
|
+
throw new Error("Invalid IPv4 address");
|
|
835
|
+
}
|
|
836
|
+
const parts = [
|
|
837
|
+
buffer.readUInt8(0),
|
|
838
|
+
buffer.readUInt8(1),
|
|
839
|
+
buffer.readUInt8(2),
|
|
840
|
+
buffer.readUInt8(3),
|
|
841
|
+
];
|
|
842
|
+
return parts.join('.');
|
|
843
|
+
}
|
|
844
|
+
function parseIPv6AddressString(addressString) {
|
|
845
|
+
const buffer = Buffer.alloc(16);
|
|
846
|
+
let parts;
|
|
847
|
+
let zeroFillCount = 0;
|
|
848
|
+
let currentBufferIndex = 0;
|
|
849
|
+
if (addressString.includes('::')) {
|
|
850
|
+
const partsSplitted = addressString.split('::');
|
|
851
|
+
if (partsSplitted.length > 2) {
|
|
852
|
+
throw new Error("Invalid IPv6 address: multiple '::' sequences.");
|
|
853
|
+
}
|
|
854
|
+
const [beforeDoubleColon, afterDoubleColon] = partsSplitted;
|
|
855
|
+
const beforeParts = beforeDoubleColon.split(':').filter(p => p !== '');
|
|
856
|
+
const afterParts = afterDoubleColon.split(':').filter(p => p !== '');
|
|
857
|
+
// Calculate how many zero groups are needed for '::'
|
|
858
|
+
zeroFillCount = 8 - (beforeParts.length + afterParts.length);
|
|
859
|
+
if (zeroFillCount < 0) {
|
|
860
|
+
throw new Error("Invalid IPv6 address: too many parts for '::' expansion.");
|
|
861
|
+
}
|
|
862
|
+
parts = [...beforeParts];
|
|
863
|
+
for (let i = 0; i < zeroFillCount; i++) {
|
|
864
|
+
parts.push('0'); // Represent the zero groups
|
|
865
|
+
}
|
|
866
|
+
parts.push(...afterParts);
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
parts = addressString.split(':');
|
|
870
|
+
}
|
|
871
|
+
if (parts.length !== 8) {
|
|
872
|
+
throw new Error(`Invalid IPv6 address: expected 8 parts, got ${parts.length}.`);
|
|
873
|
+
}
|
|
874
|
+
for (let i = 0; i < 8; i++) {
|
|
875
|
+
const part = parts[i];
|
|
876
|
+
if (part.length > 4) {
|
|
877
|
+
throw new Error(`Invalid IPv6 address part length: ${part}`);
|
|
878
|
+
}
|
|
879
|
+
const value = parseInt(part, 16);
|
|
880
|
+
if (isNaN(value) || value < 0 || value > 0xFFFF) {
|
|
881
|
+
throw new Error(`Invalid IPv6 address part: ${part}`);
|
|
882
|
+
}
|
|
883
|
+
buffer.writeUInt16BE(value, currentBufferIndex);
|
|
884
|
+
currentBufferIndex += 2;
|
|
885
|
+
}
|
|
886
|
+
return buffer;
|
|
887
|
+
}
|
|
888
|
+
function formatIPv6AddressBuffer(addressBuffer) {
|
|
889
|
+
if (addressBuffer.length !== 16) {
|
|
890
|
+
throw new Error("Invalid buffer length for IPv6 address; expected 16 bytes.");
|
|
891
|
+
}
|
|
892
|
+
const parts = Array.from({ length: 8 }, (_, i) => addressBuffer.readUInt16BE(i * 2).toString(16).replace(/^0+/, '') || '0');
|
|
893
|
+
let maxZeroLength = 0;
|
|
894
|
+
let maxZeroIndex = -1;
|
|
895
|
+
let currentZeroLength = 0;
|
|
896
|
+
let currentZeroIndex = -1;
|
|
897
|
+
for (let i = 0; i < parts.length; i++) {
|
|
898
|
+
if (parts[i] === '0') {
|
|
899
|
+
if (currentZeroLength === 0) {
|
|
900
|
+
currentZeroIndex = i;
|
|
901
|
+
}
|
|
902
|
+
currentZeroLength++;
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
if (currentZeroLength > maxZeroLength) {
|
|
906
|
+
maxZeroLength = currentZeroLength;
|
|
907
|
+
maxZeroIndex = currentZeroIndex;
|
|
908
|
+
}
|
|
909
|
+
currentZeroLength = 0;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
if (currentZeroLength > maxZeroLength) {
|
|
913
|
+
maxZeroLength = currentZeroLength;
|
|
914
|
+
maxZeroIndex = currentZeroIndex;
|
|
915
|
+
}
|
|
916
|
+
if (maxZeroLength > 1) {
|
|
917
|
+
const before = parts.slice(0, maxZeroIndex).join(':');
|
|
918
|
+
const after = parts.slice(maxZeroIndex + maxZeroLength).join(':');
|
|
919
|
+
return `${before}::${after}`;
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
return parts.join(':');
|
|
923
|
+
}
|
|
924
|
+
}
|
package/lib/src/payload.js
CHANGED
|
@@ -830,7 +830,8 @@ class PayloadAUTH extends Payload {
|
|
|
830
830
|
static parse(buffer) {
|
|
831
831
|
const genericPayload = Payload.parse(buffer);
|
|
832
832
|
const authMethod = buffer.readUInt8(4);
|
|
833
|
-
|
|
833
|
+
// Skip 3 reserved bytes
|
|
834
|
+
const authData = buffer.subarray(8, genericPayload.length);
|
|
834
835
|
return new PayloadAUTH(genericPayload.nextPayload, authMethod, authData, genericPayload.critical, genericPayload.length);
|
|
835
836
|
}
|
|
836
837
|
/**
|