node-opcua-pki 4.2.1 → 4.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.
@@ -23,6 +23,12 @@ export interface CreateSelfSignCertificateParam1 extends CreateSelfSignCertifica
23
23
  startDate: Date;
24
24
  validity: number;
25
25
  }
26
+ export interface VerifyCertificateOptions {
27
+ acceptOutdatedCertificate?: boolean;
28
+ acceptOutDatedIssuerCertificate?: boolean;
29
+ ignoreMissingRevocationList?: boolean;
30
+ acceptPendingCertificate?: boolean;
31
+ }
26
32
  export declare enum VerificationStatus {
27
33
  /** The certificate provided as a parameter is not valid. */
28
34
  BadCertificateInvalid = "BadCertificateInvalid",
@@ -97,14 +103,14 @@ export declare class CertificateManager {
97
103
  get issuersCrlFolder(): string;
98
104
  isCertificateTrusted(certificate: Certificate, callback: (err: Error | null, trustedStatus: string) => void): void;
99
105
  isCertificateTrusted(certificate: Certificate): Promise<string>;
100
- _innerVerifyCertificateAsync(certificate: Certificate, isIssuer: boolean, level: number): Promise<VerificationStatus>;
101
- verifyCertificateAsync(certificate: Certificate): Promise<VerificationStatus>;
106
+ _innerVerifyCertificateAsync(certificate: Certificate, isIssuer: boolean, level: number, options: VerifyCertificateOptions): Promise<VerificationStatus>;
107
+ protected verifyCertificateAsync(certificate: Certificate, options: VerifyCertificateOptions): Promise<VerificationStatus>;
102
108
  /**
103
109
  * Verify certificate validity
104
110
  * @method verifyCertificate
105
111
  * @param certificate
106
112
  */
107
- verifyCertificate(certificate: Certificate): Promise<VerificationStatus>;
113
+ verifyCertificate(certificate: Certificate, options?: VerifyCertificateOptions): Promise<VerificationStatus>;
108
114
  verifyCertificate(certificate: Certificate, callback: (err: Error | null, status?: VerificationStatus) => void): void;
109
115
  initialize(): Promise<void>;
110
116
  initialize(callback: (err?: Error) => void): void;
@@ -95,7 +95,7 @@ var VerificationStatus;
95
95
  VerificationStatus["BadCertificateChainIncomplete"] = "BadCertificateChainIncomplete";
96
96
  /** Validation OK. */
97
97
  VerificationStatus["Good"] = "Good";
98
- })(VerificationStatus = exports.VerificationStatus || (exports.VerificationStatus = {}));
98
+ })(VerificationStatus || (exports.VerificationStatus = VerificationStatus = {}));
99
99
  function makeFingerprint(certificate) {
100
100
  return (0, node_opcua_crypto_1.makeSHA1Thumbprint)(certificate).toString("hex");
101
101
  }
@@ -169,7 +169,7 @@ var CertificateManagerState;
169
169
  CertificateManagerState[CertificateManagerState["Initialized"] = 2] = "Initialized";
170
170
  CertificateManagerState[CertificateManagerState["Disposing"] = 3] = "Disposing";
171
171
  CertificateManagerState[CertificateManagerState["Disposed"] = 4] = "Disposed";
172
- })(CertificateManagerState = exports.CertificateManagerState || (exports.CertificateManagerState = {}));
172
+ })(CertificateManagerState || (exports.CertificateManagerState = CertificateManagerState = {}));
173
173
  class CertificateManager {
174
174
  constructor(options) {
175
175
  this.untrustUnknownCertificate = true;
@@ -299,7 +299,7 @@ class CertificateManager {
299
299
  }
300
300
  });
301
301
  }
302
- _innerVerifyCertificateAsync(certificate, isIssuer, level) {
302
+ _innerVerifyCertificateAsync(certificate, isIssuer, level, options) {
303
303
  var _a, _b, _c, _d, _e;
304
304
  return __awaiter(this, void 0, void 0, function* () {
305
305
  if (level >= 5) {
@@ -333,7 +333,7 @@ class CertificateManager {
333
333
  else {
334
334
  (0, debug_1.debugLog)(" the issuer certificate has been found in the issuer.cert folder !");
335
335
  }
336
- const issuerStatus = yield this._innerVerifyCertificateAsync(issuerCertificate, true, level + 1);
336
+ const issuerStatus = yield this._innerVerifyCertificateAsync(issuerCertificate, true, level + 1, options);
337
337
  if (issuerStatus === VerificationStatus.BadCertificateRevocationUnknown) {
338
338
  // the issuer must have a CRL available .... !
339
339
  return VerificationStatus.BadCertificateIssuerRevocationUnknown;
@@ -343,8 +343,10 @@ class CertificateManager {
343
343
  return VerificationStatus.BadCertificateIssuerRevocationUnknown;
344
344
  }
345
345
  if (issuerStatus === VerificationStatus.BadCertificateTimeInvalid) {
346
- // the issuer must have valid dates ....
347
- return VerificationStatus.BadCertificateIssuerTimeInvalid;
346
+ if (!options || !options.acceptOutDatedIssuerCertificate) {
347
+ // the issuer must have valid dates ....
348
+ return VerificationStatus.BadCertificateIssuerTimeInvalid;
349
+ }
348
350
  }
349
351
  if (issuerStatus == VerificationStatus.BadCertificateUntrusted) {
350
352
  (0, debug_1.debugLog)("warning issuerStatus = ", issuerStatus.toString(), "the issuer certificate is not trusted");
@@ -362,9 +364,14 @@ class CertificateManager {
362
364
  }
363
365
  hasValidIssuer = true;
364
366
  // let detected if our certificate is in the revocation list
365
- const revokedStatus = yield this.isCertificateRevoked(certificate);
367
+ let revokedStatus = yield this.isCertificateRevoked(certificate);
366
368
  if (revokedStatus === VerificationStatus.BadCertificateRevocationUnknown) {
367
- return VerificationStatus.BadCertificateRevocationUnknown;
369
+ if (!options || !options.ignoreMissingRevocationList) {
370
+ return VerificationStatus.BadCertificateRevocationUnknown;
371
+ }
372
+ else {
373
+ revokedStatus = VerificationStatus.Good;
374
+ }
368
375
  }
369
376
  if (revokedStatus !== VerificationStatus.Good) {
370
377
  // certificate is revoked !!!
@@ -412,13 +419,17 @@ class CertificateManager {
412
419
  (0, debug_1.debugLog)(chalk.red("certificate is invalid : certificate is not active yet !") +
413
420
  " not before date =" +
414
421
  certificateInfo.notBefore);
415
- isTimeInvalid = true;
422
+ if (!options.acceptPendingCertificate) {
423
+ isTimeInvalid = true;
424
+ }
416
425
  }
417
426
  // check that certificate has not expired
418
427
  if (certificateInfo.notAfter.getTime() <= now.getTime()) {
419
428
  // certificate is obsolete
420
429
  (0, debug_1.debugLog)(chalk.red("certificate is invalid : certificate has expired !") + " not after date =" + certificateInfo.notAfter);
421
- isTimeInvalid = true;
430
+ if (!options.acceptOutdatedCertificate) {
431
+ isTimeInvalid = true;
432
+ }
422
433
  }
423
434
  if (status === "trusted") {
424
435
  return isTimeInvalid ? VerificationStatus.BadCertificateTimeInvalid : VerificationStatus.Good;
@@ -438,21 +449,31 @@ class CertificateManager {
438
449
  }
439
450
  });
440
451
  }
441
- verifyCertificateAsync(certificate) {
452
+ verifyCertificateAsync(certificate, options) {
442
453
  return __awaiter(this, void 0, void 0, function* () {
443
- const status1 = yield this._innerVerifyCertificateAsync(certificate, false, 0);
454
+ const status1 = yield this._innerVerifyCertificateAsync(certificate, false, 0, options);
444
455
  return status1;
445
456
  });
446
457
  }
447
- verifyCertificate(certificate, callback) {
448
- if (!callback)
458
+ verifyCertificate(certificate, ...args) {
459
+ let options;
460
+ let callback = undefined;
461
+ if (args.length === 1) {
462
+ callback = args[0];
463
+ }
464
+ else if (args.length === 2) {
465
+ options = args[0];
466
+ callback = args[1];
467
+ }
468
+ // istanbul ignore next
469
+ if (!callback || typeof callback !== "function")
449
470
  throw new Error("internal error");
450
471
  // Is the signature on the SoftwareCertificate valid .?
451
472
  if (!certificate) {
452
473
  // missing certificate
453
474
  return callback(null, VerificationStatus.BadSecurityChecksFailed);
454
475
  }
455
- (0, util_1.callbackify)(this.verifyCertificateAsync).call(this, certificate, callback);
476
+ (0, util_1.callbackify)(this.verifyCertificateAsync).call(this, certificate, options || {}, callback);
456
477
  }
457
478
  initialize(...args) {
458
479
  const callback = args[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-pki",
3
- "version": "4.2.1",
3
+ "version": "4.3.0",
4
4
  "description": "PKI management for node-opcua",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/lib/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  "chokidar": "^3.5.3",
50
50
  "cli-table": "^0.3.11",
51
51
  "minimist": "^1.2.8",
52
- "node-opcua-crypto": "3.0.6",
52
+ "node-opcua-crypto": "4.1.0",
53
53
  "progress": "^2.0.3",
54
54
  "rimraf": "3.0.2",
55
55
  "thenify": "^3.3.1",
@@ -58,30 +58,28 @@
58
58
  "yauzl": "^2.10.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@istanbuljs/nyc-config-typescript": "^1.0.2",
62
61
  "@types/async": "^3.2.20",
63
62
  "@types/byline": "^4.2.33",
64
63
  "@types/cli-table": "^0.3.1",
65
64
  "@types/mocha": "^10.0.1",
66
- "@types/node": "^20.2.6",
65
+ "@types/node": "^20.5.0",
67
66
  "@types/node-dir": "0.0.34",
68
67
  "@types/progress": "^2.0.5",
69
68
  "@types/rimraf": "^3.0.2",
70
- "@types/sinon": "^10.0.15",
71
- "@types/underscore": "^1.11.5",
69
+ "@types/sinon": "^10.0.16",
70
+ "@types/underscore": "^1.11.6",
72
71
  "@types/yargs": "^17.0.24",
73
72
  "@types/yauzl": "^2.10.0",
74
- "@typescript-eslint/eslint-plugin": "^5.59.9",
75
- "@typescript-eslint/parser": "^5.59.9",
76
- "eslint": "^8.42.0",
73
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
74
+ "@typescript-eslint/parser": "^6.4.0",
75
+ "eslint": "^8.47.0",
77
76
  "mocha": "^10.2.0",
78
77
  "node-dir": "^0.1.17",
79
- "nyc": "^15.1.0",
80
78
  "should": "^13.2.3",
81
- "sinon": "^15.1.0",
79
+ "sinon": "^15.2.0",
82
80
  "source-map-support": "^0.5.21",
83
81
  "ts-node": "^10.9.1",
84
- "typescript": "^5.1.3"
82
+ "typescript": "^5.1.6"
85
83
  },
86
84
  "bin": {
87
85
  "pki": "./bin/crypto_create_CA.js"