node-ikev2 0.1.0 → 0.1.2

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/index.js CHANGED
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.ikev2 = void 0;
30
40
  __exportStar(require("./attribute"), exports);
@@ -1,5 +1,4 @@
1
1
  import { Proposal } from "./proposal";
2
- import { Attribute } from "./attribute";
3
2
  import { TrafficSelector } from "./selector";
4
3
  /**
5
4
  * IKEv2 Payload Types: \
@@ -959,10 +958,10 @@ export declare class PayloadCP extends Payload {
959
958
  */
960
959
  export declare class PayloadEAP extends Payload {
961
960
  nextPayload: payloadType;
962
- tlvData: Attribute;
961
+ eapMessage: Buffer;
963
962
  critical: boolean;
964
963
  length: number;
965
- constructor(nextPayload: payloadType, tlvData: Attribute, critical?: boolean, length?: number);
964
+ constructor(nextPayload: payloadType, eapMessage: Buffer, critical?: boolean, length?: number);
966
965
  /**
967
966
  * Parses an EAP Payload from a buffer
968
967
  * @param buffer
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.payloadTypeMapping = exports.PayloadEAP = exports.PayloadCP = exports.cfgType = exports.PayloadSK = exports.PayloadTSr = exports.PayloadTSi = exports.PayloadTS = exports.PayloadVENDOR = exports.PayloadDELETE = exports.PayloadNOTIFY = exports.notifyMessageType = exports.securityProtocolId = exports.PayloadNONCE = exports.PayloadAUTH = exports.PayloadCERTREQ = exports.PayloadCERT = exports.CertificateType = exports.PayloadIDr = exports.PayloadIDi = exports.PayloadID = exports.IDType = exports.PayloadKE = exports.PayloadSA = exports.Payload = exports.payloadType = void 0;
4
4
  const proposal_1 = require("./proposal");
5
- const attribute_1 = require("./attribute");
6
5
  const selector_1 = require("./selector");
7
6
  /*
8
7
  IKEv2 Generic Payload Header
@@ -1593,6 +1592,9 @@ class PayloadSK extends Payload {
1593
1592
  throw new Error(`Insufficient data for payload header at offset ${offset}`);
1594
1593
  }
1595
1594
  const payload = nextPayloadClass.parse(inClearData.subarray(offset, inClearData.length));
1595
+ // Some extended types set NONE in type from the constructor on parse, when there are multiple types with the same
1596
+ // encoding - e.g. PayloadID with IDi and IDr
1597
+ payload.type = nextPayload;
1596
1598
  payloads.push(payload);
1597
1599
  offset += payload.length;
1598
1600
  nextPayload = payload.nextPayload;
@@ -1746,10 +1748,10 @@ exports.PayloadCP = PayloadCP;
1746
1748
  * @extends Payload
1747
1749
  */
1748
1750
  class PayloadEAP extends Payload {
1749
- constructor(nextPayload, tlvData, critical = false, length = 0) {
1750
- super(payloadType.EAP, nextPayload, critical, length > 0 ? length : 4 + tlvData.length);
1751
+ constructor(nextPayload, eapMessage, critical = false, length = 0) {
1752
+ super(payloadType.EAP, nextPayload, critical, length > 0 ? length : 4 + eapMessage.length);
1751
1753
  this.nextPayload = nextPayload;
1752
- this.tlvData = tlvData;
1754
+ this.eapMessage = eapMessage;
1753
1755
  this.critical = critical;
1754
1756
  this.length = length;
1755
1757
  }
@@ -1762,8 +1764,8 @@ class PayloadEAP extends Payload {
1762
1764
  */
1763
1765
  static parse(buffer) {
1764
1766
  const genericPayload = Payload.parse(buffer);
1765
- const tlvData = attribute_1.Attribute.parse(buffer.subarray(4, genericPayload.length));
1766
- return new PayloadEAP(genericPayload.nextPayload, tlvData, genericPayload.critical, genericPayload.length);
1767
+ const eapMessage = buffer.subarray(4, genericPayload.length);
1768
+ return new PayloadEAP(genericPayload.nextPayload, eapMessage, genericPayload.critical, genericPayload.length);
1767
1769
  }
1768
1770
  /**
1769
1771
  * Serializes a JSON representation of the EAP payload to a buffer
@@ -1776,8 +1778,7 @@ class PayloadEAP extends Payload {
1776
1778
  const buffer = Buffer.alloc(json.length);
1777
1779
  const genericPayload = Payload.serializeJSON(json);
1778
1780
  genericPayload.copy(buffer);
1779
- const tlvDataBuffer = attribute_1.Attribute.serializeJSON(json.tlvData);
1780
- tlvDataBuffer.copy(buffer, 4);
1781
+ Buffer.from(json.eapMessage, "hex").copy(buffer, 4);
1781
1782
  return buffer;
1782
1783
  }
1783
1784
  /**
@@ -1786,13 +1787,11 @@ class PayloadEAP extends Payload {
1786
1787
  * @returns {Buffer}
1787
1788
  */
1788
1789
  serialize() {
1789
- // Encode deep first to calculate length
1790
- const tlvDataBuffer = this.tlvData.serialize();
1791
1790
  // Fix the length
1792
- this.length = 4 + tlvDataBuffer.length;
1791
+ this.length = 4 + this.eapMessage.length;
1793
1792
  const buffer = Buffer.alloc(this.length);
1794
1793
  super.serialize().copy(buffer);
1795
- tlvDataBuffer.copy(buffer, 4);
1794
+ this.eapMessage.copy(buffer, 4);
1796
1795
  return buffer;
1797
1796
  }
1798
1797
  /**
@@ -1802,7 +1801,7 @@ class PayloadEAP extends Payload {
1802
1801
  */
1803
1802
  toJSON() {
1804
1803
  const json = super.genToJSON();
1805
- json.tlvData = this.tlvData.toJSON();
1804
+ json.eapMessage = this.eapMessage.toString("hex");
1806
1805
  return json;
1807
1806
  }
1808
1807
  /**
@@ -1812,7 +1811,7 @@ class PayloadEAP extends Payload {
1812
1811
  */
1813
1812
  toString() {
1814
1813
  const genericString = super.genToString();
1815
- return `${genericString}\ntlvData: ${this.tlvData.toString()}`;
1814
+ return `${genericString}\neapMessage: ${this.eapMessage.toString("hex")}`;
1816
1815
  }
1817
1816
  }
1818
1817
  exports.PayloadEAP = PayloadEAP;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-ikev2",
3
3
  "title": "Node-IKEV2",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "IKEv2 parser and serializer for Node.js",
6
6
  "main": "./lib/src/index.js",
7
7
  "types": "./lib/src/index.d.ts",