node-opcua-pki 3.0.2 → 3.1.1
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/.ignore +6 -6
- package/.prettierrc +5 -5
- package/LICENSE +22 -22
- package/bin/crypto_create_CA.js +0 -0
- package/bin/crypto_create_CA_config.example.js +18 -18
- package/bin/install_prerequisite.js +9 -9
- package/dist/crypto_create_CA.d.ts +2 -2
- package/dist/crypto_create_CA.js +897 -897
- package/dist/index.d.ts +6 -6
- package/dist/index.js +44 -44
- package/dist/misc/applicationurn.d.ts +1 -1
- package/dist/misc/applicationurn.js +46 -46
- package/dist/misc/hostname.d.ts +8 -8
- package/dist/misc/hostname.js +102 -102
- package/dist/misc/install_prerequisite.d.ts +9 -9
- package/dist/misc/install_prerequisite.js +363 -360
- package/dist/misc/install_prerequisite.js.map +1 -1
- package/dist/misc/subject.d.ts +26 -26
- package/dist/misc/subject.js +121 -121
- package/dist/pki/certificate_authority.d.ts +61 -61
- package/dist/pki/certificate_authority.js +481 -481
- package/dist/pki/certificate_manager.d.ts +144 -144
- package/dist/pki/certificate_manager.js +883 -883
- package/dist/pki/certificate_manager.js.map +1 -1
- package/dist/pki/common.d.ts +5 -5
- package/dist/pki/common.js +2 -2
- package/dist/pki/templates/ca_config_template.cnf.d.ts +2 -2
- package/dist/pki/templates/ca_config_template.cnf.js +129 -129
- package/dist/pki/templates/simple_config_template.cnf.d.ts +2 -2
- package/dist/pki/templates/simple_config_template.cnf.js +75 -75
- package/dist/pki/toolbox.d.ts +160 -160
- package/dist/pki/toolbox.js +699 -699
- package/dist/pki/toolbox_pfx.js +18 -18
- package/lib/crypto_create_CA.ts +1135 -1135
- package/lib/index.ts +28 -28
- package/lib/misc/applicationurn.ts +45 -45
- package/lib/misc/hostname.ts +89 -89
- package/lib/misc/install_prerequisite.ts +454 -454
- package/lib/misc/subject.ts +141 -141
- package/lib/pki/certificate_manager.ts +1 -1
- package/lib/pki/common.ts +5 -5
- package/lib/pki/templates/ca_config_template.cnf.ts +129 -129
- package/lib/pki/templates/simple_config_template.cnf.ts +75 -75
- package/lib/pki/toolbox_pfx.ts +19 -19
- package/package.json +89 -89
- package/readme.md +214 -214
- package/tsconfig.json +20 -20
- package/dist/misc/fs.d.ts +0 -24
- package/dist/misc/fs.js +0 -21
- package/dist/misc/fs.js.map +0 -1
- package/dist/misc/get_default_filesystem.d.ts +0 -2
- package/dist/misc/get_default_filesystem.js +0 -9
- package/dist/misc/get_default_filesystem.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./pki/toolbox";
|
|
2
|
-
export * from "./pki/certificate_authority";
|
|
3
|
-
export * from "./pki/certificate_manager";
|
|
4
|
-
export * from "./pki/common";
|
|
5
|
-
export * from "./misc/install_prerequisite";
|
|
6
|
-
export * from "./misc/subject";
|
|
1
|
+
export * from "./pki/toolbox";
|
|
2
|
+
export * from "./pki/certificate_authority";
|
|
3
|
+
export * from "./pki/certificate_manager";
|
|
4
|
+
export * from "./pki/common";
|
|
5
|
+
export * from "./misc/install_prerequisite";
|
|
6
|
+
export * from "./misc/subject";
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
18
|
-
// node-opcua-pki
|
|
19
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
20
|
-
// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
|
|
21
|
-
// Copyright (c) 2022 - Sterfive.com
|
|
22
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
23
|
-
//
|
|
24
|
-
// This project is licensed under the terms of the MIT license.
|
|
25
|
-
//
|
|
26
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
27
|
-
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
28
|
-
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
29
|
-
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
-
//
|
|
31
|
-
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
32
|
-
// Software.
|
|
33
|
-
//
|
|
34
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
35
|
-
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
36
|
-
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
37
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
38
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
39
|
-
__exportStar(require("./pki/toolbox"), exports);
|
|
40
|
-
__exportStar(require("./pki/certificate_authority"), exports);
|
|
41
|
-
__exportStar(require("./pki/certificate_manager"), exports);
|
|
42
|
-
__exportStar(require("./pki/common"), exports);
|
|
43
|
-
__exportStar(require("./misc/install_prerequisite"), exports);
|
|
44
|
-
__exportStar(require("./misc/subject"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
18
|
+
// node-opcua-pki
|
|
19
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
20
|
+
// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
|
|
21
|
+
// Copyright (c) 2022 - Sterfive.com
|
|
22
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
//
|
|
24
|
+
// This project is licensed under the terms of the MIT license.
|
|
25
|
+
//
|
|
26
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
27
|
+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
28
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
29
|
+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
+
//
|
|
31
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
32
|
+
// Software.
|
|
33
|
+
//
|
|
34
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
35
|
+
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
36
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
37
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
38
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
39
|
+
__exportStar(require("./pki/toolbox"), exports);
|
|
40
|
+
__exportStar(require("./pki/certificate_authority"), exports);
|
|
41
|
+
__exportStar(require("./pki/certificate_manager"), exports);
|
|
42
|
+
__exportStar(require("./pki/common"), exports);
|
|
43
|
+
__exportStar(require("./misc/install_prerequisite"), exports);
|
|
44
|
+
__exportStar(require("./misc/subject"), exports);
|
|
45
45
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function makeApplicationUrn(hostname: string, suffix: string): string;
|
|
1
|
+
export declare function makeApplicationUrn(hostname: string, suffix: string): string;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeApplicationUrn = void 0;
|
|
4
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
5
|
-
// node-opcua-pki
|
|
6
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
7
|
-
// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
|
|
8
|
-
// Copyright (c) 2022 - Sterfive.com
|
|
9
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
10
|
-
//
|
|
11
|
-
// This project is licensed under the terms of the MIT license.
|
|
12
|
-
//
|
|
13
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
14
|
-
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
15
|
-
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
16
|
-
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
17
|
-
//
|
|
18
|
-
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
19
|
-
// Software.
|
|
20
|
-
//
|
|
21
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
22
|
-
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
23
|
-
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
26
|
-
const assert = require("assert");
|
|
27
|
-
const crypto = require("crypto");
|
|
28
|
-
function makeApplicationUrn(hostname, suffix) {
|
|
29
|
-
// beware : Openssl doesn't support urn with length greater than 64 !!
|
|
30
|
-
// sometimes hostname length could be too long ...
|
|
31
|
-
// application urn length must not exceed 64 car. to comply with openssl
|
|
32
|
-
// see cryptoCA
|
|
33
|
-
let hostnameHash = hostname;
|
|
34
|
-
if (hostnameHash.length + 7 + suffix.length >= 64) {
|
|
35
|
-
// we need to reduce the applicationUrn side => let's take
|
|
36
|
-
// a portion of the hostname hash.
|
|
37
|
-
hostnameHash = crypto.createHash("md5")
|
|
38
|
-
.update(hostname)
|
|
39
|
-
.digest("hex")
|
|
40
|
-
.substr(0, 16);
|
|
41
|
-
}
|
|
42
|
-
const applicationUrn = "urn:" + hostnameHash + ":" + suffix;
|
|
43
|
-
assert(applicationUrn.length <= 64);
|
|
44
|
-
return applicationUrn;
|
|
45
|
-
}
|
|
46
|
-
exports.makeApplicationUrn = makeApplicationUrn;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeApplicationUrn = void 0;
|
|
4
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
// node-opcua-pki
|
|
6
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
7
|
+
// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
|
|
8
|
+
// Copyright (c) 2022 - Sterfive.com
|
|
9
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
10
|
+
//
|
|
11
|
+
// This project is licensed under the terms of the MIT license.
|
|
12
|
+
//
|
|
13
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
14
|
+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
15
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
16
|
+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
17
|
+
//
|
|
18
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
19
|
+
// Software.
|
|
20
|
+
//
|
|
21
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
22
|
+
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
23
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
26
|
+
const assert = require("assert");
|
|
27
|
+
const crypto = require("crypto");
|
|
28
|
+
function makeApplicationUrn(hostname, suffix) {
|
|
29
|
+
// beware : Openssl doesn't support urn with length greater than 64 !!
|
|
30
|
+
// sometimes hostname length could be too long ...
|
|
31
|
+
// application urn length must not exceed 64 car. to comply with openssl
|
|
32
|
+
// see cryptoCA
|
|
33
|
+
let hostnameHash = hostname;
|
|
34
|
+
if (hostnameHash.length + 7 + suffix.length >= 64) {
|
|
35
|
+
// we need to reduce the applicationUrn side => let's take
|
|
36
|
+
// a portion of the hostname hash.
|
|
37
|
+
hostnameHash = crypto.createHash("md5")
|
|
38
|
+
.update(hostname)
|
|
39
|
+
.digest("hex")
|
|
40
|
+
.substr(0, 16);
|
|
41
|
+
}
|
|
42
|
+
const applicationUrn = "urn:" + hostnameHash + ":" + suffix;
|
|
43
|
+
assert(applicationUrn.length <= 64);
|
|
44
|
+
return applicationUrn;
|
|
45
|
+
}
|
|
46
|
+
exports.makeApplicationUrn = makeApplicationUrn;
|
|
47
47
|
//# sourceMappingURL=applicationurn.js.map
|
package/dist/misc/hostname.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* extract FullyQualifiedDomainName of this computer
|
|
3
|
-
*/
|
|
4
|
-
export declare function extractFullyQualifiedDomainName(): Promise<string>;
|
|
5
|
-
export declare function prepareFQDN(): Promise<void>;
|
|
6
|
-
export declare function getFullyQualifiedDomainName(optional_max_length?: number): string;
|
|
7
|
-
export declare function getHostname(): string;
|
|
8
|
-
export declare function resolveFullyQualifiedDomainName(str: string): string;
|
|
1
|
+
/**
|
|
2
|
+
* extract FullyQualifiedDomainName of this computer
|
|
3
|
+
*/
|
|
4
|
+
export declare function extractFullyQualifiedDomainName(): Promise<string>;
|
|
5
|
+
export declare function prepareFQDN(): Promise<void>;
|
|
6
|
+
export declare function getFullyQualifiedDomainName(optional_max_length?: number): string;
|
|
7
|
+
export declare function getHostname(): string;
|
|
8
|
+
export declare function resolveFullyQualifiedDomainName(str: string): string;
|
package/dist/misc/hostname.js
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.resolveFullyQualifiedDomainName = exports.getHostname = exports.getFullyQualifiedDomainName = exports.prepareFQDN = exports.extractFullyQualifiedDomainName = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* @module node-opcua-hostname
|
|
15
|
-
*/
|
|
16
|
-
const dns = require("dns");
|
|
17
|
-
const os = require("os");
|
|
18
|
-
const util_1 = require("util");
|
|
19
|
-
function trim(str, length) {
|
|
20
|
-
if (!length) {
|
|
21
|
-
return str;
|
|
22
|
-
}
|
|
23
|
-
return str.substr(0, Math.min(str.length, length));
|
|
24
|
-
}
|
|
25
|
-
function fqdn(callback) {
|
|
26
|
-
const uqdn = os.hostname();
|
|
27
|
-
dns.lookup(uqdn, { hints: dns.ADDRCONFIG }, (err1, ip) => {
|
|
28
|
-
if (err1) {
|
|
29
|
-
return callback(err1);
|
|
30
|
-
}
|
|
31
|
-
dns.lookupService(ip, 0, (err2, _fqdn) => {
|
|
32
|
-
if (err2) {
|
|
33
|
-
return callback(err2);
|
|
34
|
-
}
|
|
35
|
-
_fqdn = _fqdn.replace(".localdomain", "");
|
|
36
|
-
callback(null, _fqdn);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
let _fullyQualifiedDomainNameInCache;
|
|
41
|
-
/**
|
|
42
|
-
* extract FullyQualifiedDomainName of this computer
|
|
43
|
-
*/
|
|
44
|
-
function extractFullyQualifiedDomainName() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (_fullyQualifiedDomainNameInCache) {
|
|
47
|
-
return _fullyQualifiedDomainNameInCache;
|
|
48
|
-
}
|
|
49
|
-
if (process.platform === "win32") {
|
|
50
|
-
// http://serverfault.com/a/73643/251863
|
|
51
|
-
const env = process.env;
|
|
52
|
-
_fullyQualifiedDomainNameInCache =
|
|
53
|
-
env.COMPUTERNAME + (env.USERDNSDOMAIN && env.USERDNSDOMAIN.length > 0 ? "." + env.USERDNSDOMAIN : "");
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
try {
|
|
57
|
-
_fullyQualifiedDomainNameInCache = yield (0, util_1.promisify)(fqdn)();
|
|
58
|
-
if (_fullyQualifiedDomainNameInCache === "localhost") {
|
|
59
|
-
throw new Error("localhost not expected");
|
|
60
|
-
}
|
|
61
|
-
if (/sethostname/.test(_fullyQualifiedDomainNameInCache)) {
|
|
62
|
-
throw new Error("Detecting fqdn on windows !!!");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
// fall back to old method
|
|
67
|
-
_fullyQualifiedDomainNameInCache = os.hostname();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return _fullyQualifiedDomainNameInCache;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
exports.extractFullyQualifiedDomainName = extractFullyQualifiedDomainName;
|
|
74
|
-
function prepareFQDN() {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
_fullyQualifiedDomainNameInCache = yield extractFullyQualifiedDomainName();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
exports.prepareFQDN = prepareFQDN;
|
|
80
|
-
function getFullyQualifiedDomainName(optional_max_length) {
|
|
81
|
-
if (!_fullyQualifiedDomainNameInCache) {
|
|
82
|
-
throw new Error("FullyQualifiedDomainName computation is not completed yet");
|
|
83
|
-
}
|
|
84
|
-
return _fullyQualifiedDomainNameInCache ? trim(_fullyQualifiedDomainNameInCache, optional_max_length) : "%FQDN%";
|
|
85
|
-
}
|
|
86
|
-
exports.getFullyQualifiedDomainName = getFullyQualifiedDomainName;
|
|
87
|
-
function getHostname() {
|
|
88
|
-
return os.hostname();
|
|
89
|
-
}
|
|
90
|
-
exports.getHostname = getHostname;
|
|
91
|
-
function resolveFullyQualifiedDomainName(str) {
|
|
92
|
-
if (!_fullyQualifiedDomainNameInCache) {
|
|
93
|
-
throw new Error("FullyQualifiedDomainName computation is not completed yet");
|
|
94
|
-
}
|
|
95
|
-
str = str.replace("%FQDN%", _fullyQualifiedDomainNameInCache);
|
|
96
|
-
str = str.replace("{FQDN}", _fullyQualifiedDomainNameInCache);
|
|
97
|
-
str = str.replace("{hostname}", getHostname());
|
|
98
|
-
return str;
|
|
99
|
-
}
|
|
100
|
-
exports.resolveFullyQualifiedDomainName = resolveFullyQualifiedDomainName;
|
|
101
|
-
// note : under windows ... echo %COMPUTERNAME%.%USERDNSDOMAIN%
|
|
102
|
-
prepareFQDN();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.resolveFullyQualifiedDomainName = exports.getHostname = exports.getFullyQualifiedDomainName = exports.prepareFQDN = exports.extractFullyQualifiedDomainName = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* @module node-opcua-hostname
|
|
15
|
+
*/
|
|
16
|
+
const dns = require("dns");
|
|
17
|
+
const os = require("os");
|
|
18
|
+
const util_1 = require("util");
|
|
19
|
+
function trim(str, length) {
|
|
20
|
+
if (!length) {
|
|
21
|
+
return str;
|
|
22
|
+
}
|
|
23
|
+
return str.substr(0, Math.min(str.length, length));
|
|
24
|
+
}
|
|
25
|
+
function fqdn(callback) {
|
|
26
|
+
const uqdn = os.hostname();
|
|
27
|
+
dns.lookup(uqdn, { hints: dns.ADDRCONFIG }, (err1, ip) => {
|
|
28
|
+
if (err1) {
|
|
29
|
+
return callback(err1);
|
|
30
|
+
}
|
|
31
|
+
dns.lookupService(ip, 0, (err2, _fqdn) => {
|
|
32
|
+
if (err2) {
|
|
33
|
+
return callback(err2);
|
|
34
|
+
}
|
|
35
|
+
_fqdn = _fqdn.replace(".localdomain", "");
|
|
36
|
+
callback(null, _fqdn);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
let _fullyQualifiedDomainNameInCache;
|
|
41
|
+
/**
|
|
42
|
+
* extract FullyQualifiedDomainName of this computer
|
|
43
|
+
*/
|
|
44
|
+
function extractFullyQualifiedDomainName() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (_fullyQualifiedDomainNameInCache) {
|
|
47
|
+
return _fullyQualifiedDomainNameInCache;
|
|
48
|
+
}
|
|
49
|
+
if (process.platform === "win32") {
|
|
50
|
+
// http://serverfault.com/a/73643/251863
|
|
51
|
+
const env = process.env;
|
|
52
|
+
_fullyQualifiedDomainNameInCache =
|
|
53
|
+
env.COMPUTERNAME + (env.USERDNSDOMAIN && env.USERDNSDOMAIN.length > 0 ? "." + env.USERDNSDOMAIN : "");
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
try {
|
|
57
|
+
_fullyQualifiedDomainNameInCache = yield (0, util_1.promisify)(fqdn)();
|
|
58
|
+
if (_fullyQualifiedDomainNameInCache === "localhost") {
|
|
59
|
+
throw new Error("localhost not expected");
|
|
60
|
+
}
|
|
61
|
+
if (/sethostname/.test(_fullyQualifiedDomainNameInCache)) {
|
|
62
|
+
throw new Error("Detecting fqdn on windows !!!");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
// fall back to old method
|
|
67
|
+
_fullyQualifiedDomainNameInCache = os.hostname();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return _fullyQualifiedDomainNameInCache;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.extractFullyQualifiedDomainName = extractFullyQualifiedDomainName;
|
|
74
|
+
function prepareFQDN() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
_fullyQualifiedDomainNameInCache = yield extractFullyQualifiedDomainName();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.prepareFQDN = prepareFQDN;
|
|
80
|
+
function getFullyQualifiedDomainName(optional_max_length) {
|
|
81
|
+
if (!_fullyQualifiedDomainNameInCache) {
|
|
82
|
+
throw new Error("FullyQualifiedDomainName computation is not completed yet");
|
|
83
|
+
}
|
|
84
|
+
return _fullyQualifiedDomainNameInCache ? trim(_fullyQualifiedDomainNameInCache, optional_max_length) : "%FQDN%";
|
|
85
|
+
}
|
|
86
|
+
exports.getFullyQualifiedDomainName = getFullyQualifiedDomainName;
|
|
87
|
+
function getHostname() {
|
|
88
|
+
return os.hostname();
|
|
89
|
+
}
|
|
90
|
+
exports.getHostname = getHostname;
|
|
91
|
+
function resolveFullyQualifiedDomainName(str) {
|
|
92
|
+
if (!_fullyQualifiedDomainNameInCache) {
|
|
93
|
+
throw new Error("FullyQualifiedDomainName computation is not completed yet");
|
|
94
|
+
}
|
|
95
|
+
str = str.replace("%FQDN%", _fullyQualifiedDomainNameInCache);
|
|
96
|
+
str = str.replace("{FQDN}", _fullyQualifiedDomainNameInCache);
|
|
97
|
+
str = str.replace("{hostname}", getHostname());
|
|
98
|
+
return str;
|
|
99
|
+
}
|
|
100
|
+
exports.resolveFullyQualifiedDomainName = resolveFullyQualifiedDomainName;
|
|
101
|
+
// note : under windows ... echo %COMPUTERNAME%.%USERDNSDOMAIN%
|
|
102
|
+
prepareFQDN();
|
|
103
103
|
//# sourceMappingURL=hostname.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare function check_system_openssl_version(callback: (err: Error | null, output?: string) => void): void;
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param callback {Function}
|
|
5
|
-
* @param callback.err {Error|null}
|
|
6
|
-
* @param callback.pathToOpenSSL {string}
|
|
7
|
-
*/
|
|
8
|
-
export declare function install_prerequisite(callback: (err: Error | null, pathToOpenSSL?: string) => void): void;
|
|
9
|
-
export declare function get_openssl_exec_path(callback: (err: Error | null, execPath?: string) => void): void;
|
|
1
|
+
export declare function check_system_openssl_version(callback: (err: Error | null, output?: string) => void): void;
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param callback {Function}
|
|
5
|
+
* @param callback.err {Error|null}
|
|
6
|
+
* @param callback.pathToOpenSSL {string}
|
|
7
|
+
*/
|
|
8
|
+
export declare function install_prerequisite(callback: (err: Error | null, pathToOpenSSL?: string) => void): void;
|
|
9
|
+
export declare function get_openssl_exec_path(callback: (err: Error | null, execPath?: string) => void): void;
|