node-opcua-pki 4.0.2 → 4.1.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.
|
@@ -24,7 +24,7 @@ exports.makeApplicationUrn = void 0;
|
|
|
24
24
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
25
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
26
26
|
const assert = require("assert");
|
|
27
|
-
const
|
|
27
|
+
const crypto_1 = require("crypto");
|
|
28
28
|
function makeApplicationUrn(hostname, suffix) {
|
|
29
29
|
// beware : Openssl doesn't support urn with length greater than 64 !!
|
|
30
30
|
// sometimes hostname length could be too long ...
|
|
@@ -34,10 +34,7 @@ function makeApplicationUrn(hostname, suffix) {
|
|
|
34
34
|
if (hostnameHash.length + 7 + suffix.length >= 64) {
|
|
35
35
|
// we need to reduce the applicationUrn side => let's take
|
|
36
36
|
// a portion of the hostname hash.
|
|
37
|
-
hostnameHash =
|
|
38
|
-
.update(hostname)
|
|
39
|
-
.digest("hex")
|
|
40
|
-
.substr(0, 16);
|
|
37
|
+
hostnameHash = (0, crypto_1.createHash)("md5").update(hostname).digest("hex").substr(0, 16);
|
|
41
38
|
}
|
|
42
39
|
const applicationUrn = "urn:" + hostnameHash + ":" + suffix;
|
|
43
40
|
assert(applicationUrn.length <= 64);
|
|
@@ -481,35 +481,42 @@ class CertificateManager {
|
|
|
481
481
|
(0, common2_1.mkdir)(path.join(pkiDir, "issuers"));
|
|
482
482
|
(0, common2_1.mkdir)(path.join(pkiDir, "issuers/certs")); // contains Trusted CA certificates
|
|
483
483
|
(0, common2_1.mkdir)(path.join(pkiDir, "issuers/crl")); // contains CRL of revoked CA certificates
|
|
484
|
-
this.
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
//
|
|
501
|
-
(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
484
|
+
if (!fs.existsSync(this.configFile) || !fs.existsSync(this.privateKey)) {
|
|
485
|
+
this.withLock((callback) => {
|
|
486
|
+
assert(this.state !== CertificateManagerState.Disposing);
|
|
487
|
+
if (this.state === CertificateManagerState.Disposed) {
|
|
488
|
+
return callback();
|
|
489
|
+
}
|
|
490
|
+
assert(this.state === CertificateManagerState.Initializing);
|
|
491
|
+
if (!fs.existsSync(this.configFile)) {
|
|
492
|
+
fs.writeFileSync(this.configFile, configurationFileSimpleTemplate);
|
|
493
|
+
}
|
|
494
|
+
// note : openssl 1.1.1 has a bug that causes a failure if
|
|
495
|
+
// random file cannot be found. (should be fixed in 1.1.1.a)
|
|
496
|
+
// if this issue become important we may have to consider checking that rndFile exists and recreate
|
|
497
|
+
// it if not . this could be achieved with the command :
|
|
498
|
+
// "openssl rand -writerand ${this.randomFile}"
|
|
499
|
+
//
|
|
500
|
+
// cf: https://github.com/node-opcua/node-opcua/issues/554
|
|
501
|
+
if (!fs.existsSync(this.privateKey)) {
|
|
502
|
+
(0, debug_1.debugLog)("generating private key ...");
|
|
503
|
+
// setEnv("RANDFILE", this.randomFile);
|
|
504
|
+
(0, without_openssl_1.createPrivateKey)(this.privateKey, this.keySize, (err) => {
|
|
505
|
+
if (err) {
|
|
506
|
+
return callback(err);
|
|
507
|
+
}
|
|
508
|
+
this._readCertificates(() => callback());
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
// debugLog(" initialize : private key already exists ... skipping");
|
|
505
513
|
this._readCertificates(() => callback());
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}, callback);
|
|
514
|
+
}
|
|
515
|
+
}, callback);
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
this._readCertificates(() => callback());
|
|
519
|
+
}
|
|
513
520
|
}
|
|
514
521
|
dispose() {
|
|
515
522
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -545,7 +552,7 @@ class CertificateManager {
|
|
|
545
552
|
withLock2(action) {
|
|
546
553
|
return __awaiter(this, void 0, void 0, function* () {
|
|
547
554
|
const lockFileName = path.join(this.rootDir, "mutex.lock");
|
|
548
|
-
return (0, global_mutex_1.withLock)({
|
|
555
|
+
return (0, global_mutex_1.withLock)({ fileToLock: lockFileName }, () => __awaiter(this, void 0, void 0, function* () {
|
|
549
556
|
return yield action();
|
|
550
557
|
}));
|
|
551
558
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-pki",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "PKI management for node-opcua",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"types": "./dist/lib/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"author": "Etienne Rossignon",
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ster5/global-mutex": "^
|
|
45
|
+
"@ster5/global-mutex": "^2.0.0",
|
|
46
46
|
"async": "^3.2.4",
|
|
47
47
|
"byline": "^5.0.0",
|
|
48
48
|
"chalk": "4.1.2",
|