node-opcua-pki 6.16.0 → 6.18.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.
- package/dist/bin/pki.mjs +74 -64
- package/dist/bin/pki.mjs.map +1 -1
- package/dist/index.js +74 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -210,32 +210,11 @@ var import_node_child_process = __toESM(require("child_process"));
|
|
|
210
210
|
var import_node_fs2 = __toESM(require("fs"));
|
|
211
211
|
var import_node_os = __toESM(require("os"));
|
|
212
212
|
var import_node_path2 = __toESM(require("path"));
|
|
213
|
-
var
|
|
213
|
+
var import_promises = require("stream/promises");
|
|
214
214
|
var import_byline = __toESM(require("byline"));
|
|
215
215
|
var import_chalk2 = __toESM(require("chalk"));
|
|
216
|
-
var import_progress = __toESM(require("progress"));
|
|
217
|
-
var import_wget_improved_2 = __toESM(require("wget-improved-2"));
|
|
218
216
|
var import_yauzl = __toESM(require("yauzl"));
|
|
219
217
|
var doDebug2 = process.env.NODEOPCUAPKIDEBUG || false;
|
|
220
|
-
function makeOptions() {
|
|
221
|
-
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || void 0;
|
|
222
|
-
if (proxy) {
|
|
223
|
-
const a = new import_node_url.default.URL(proxy);
|
|
224
|
-
const auth = a.username ? `${a.username}:${a.password}` : void 0;
|
|
225
|
-
const options = {
|
|
226
|
-
proxy: {
|
|
227
|
-
port: a.port ? parseInt(a.port, 10) : 80,
|
|
228
|
-
protocol: a.protocol.replace(":", ""),
|
|
229
|
-
host: a.hostname ?? "",
|
|
230
|
-
proxyAuth: auth
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
warningLog(import_chalk2.default.green("- using proxy "), proxy);
|
|
234
|
-
warningLog(options);
|
|
235
|
-
return options;
|
|
236
|
-
}
|
|
237
|
-
return {};
|
|
238
|
-
}
|
|
239
218
|
async function execute(cmd, cwd) {
|
|
240
219
|
let output = "";
|
|
241
220
|
const options = {
|
|
@@ -269,7 +248,7 @@ function quote2(str) {
|
|
|
269
248
|
return `"${str.replace(/\\/g, "/")}"`;
|
|
270
249
|
}
|
|
271
250
|
function is_expected_openssl_version(strVersion) {
|
|
272
|
-
return !!strVersion.match(/OpenSSL
|
|
251
|
+
return !!strVersion.match(/OpenSSL \d/);
|
|
273
252
|
}
|
|
274
253
|
async function getopensslExecPath() {
|
|
275
254
|
let result1;
|
|
@@ -348,6 +327,31 @@ async function install_and_check_win32_openssl_version() {
|
|
|
348
327
|
};
|
|
349
328
|
}
|
|
350
329
|
}
|
|
330
|
+
async function find_system_openssl_win32() {
|
|
331
|
+
try {
|
|
332
|
+
const result = await execute("where openssl");
|
|
333
|
+
if (result.exitCode !== 0) {
|
|
334
|
+
return void 0;
|
|
335
|
+
}
|
|
336
|
+
const opensslPath2 = result.output.split(/\r?\n/)[0].trim();
|
|
337
|
+
if (!opensslPath2 || !import_node_fs2.default.existsSync(opensslPath2)) {
|
|
338
|
+
return void 0;
|
|
339
|
+
}
|
|
340
|
+
const q4 = quote2(opensslPath2);
|
|
341
|
+
const versionResult = await execute(`${q4} version`);
|
|
342
|
+
const version = versionResult.output.trim();
|
|
343
|
+
if (versionResult.exitCode === 0 && is_expected_openssl_version(version)) {
|
|
344
|
+
warningLog(
|
|
345
|
+
import_chalk2.default.green("Using system OpenSSL: ") + import_chalk2.default.cyan(version) + import_chalk2.default.green(" at ") + import_chalk2.default.cyan(opensslPath2)
|
|
346
|
+
);
|
|
347
|
+
return opensslPath2;
|
|
348
|
+
}
|
|
349
|
+
warningLog(import_chalk2.default.yellow("System OpenSSL found but version not accepted: ") + version);
|
|
350
|
+
return void 0;
|
|
351
|
+
} catch (_err) {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
351
355
|
function win32or64() {
|
|
352
356
|
if (process.env.PROCESSOR_ARCHITECTURE === "x86" && process.env.PROCESSOR_ARCHITEW6432) {
|
|
353
357
|
return 64;
|
|
@@ -361,37 +365,39 @@ async function install_and_check_win32_openssl_version() {
|
|
|
361
365
|
return 32;
|
|
362
366
|
}
|
|
363
367
|
async function download_openssl() {
|
|
364
|
-
const
|
|
365
|
-
const outputFilename = import_node_path2.default.join(downloadFolder, import_node_path2.default.basename(
|
|
366
|
-
warningLog(`downloading ${import_chalk2.default.yellow(
|
|
368
|
+
const url = win32or64() === 64 ? "https://github.com/node-opcua/node-opcua-pki/releases/download/2.14.2/openssl-1.0.2u-x64_86-win64.zip" : "https://github.com/node-opcua/node-opcua-pki/releases/download/2.14.2/openssl-1.0.2u-i386-win32.zip";
|
|
369
|
+
const outputFilename = import_node_path2.default.join(downloadFolder, import_node_path2.default.basename(url));
|
|
370
|
+
warningLog(`downloading ${import_chalk2.default.yellow(url)} to ${outputFilename}`);
|
|
367
371
|
if (import_node_fs2.default.existsSync(outputFilename)) {
|
|
368
372
|
return { downloadedFile: outputFilename };
|
|
369
373
|
}
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (doDebug2) {
|
|
387
|
-
warningLog(output);
|
|
374
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
375
|
+
if (!response.ok || !response.body) {
|
|
376
|
+
throw new Error(`Failed to download OpenSSL from ${url}: ${response.status} ${response.statusText}`);
|
|
377
|
+
}
|
|
378
|
+
const contentLength = parseInt(response.headers.get("content-length") || "0", 10);
|
|
379
|
+
let downloaded = 0;
|
|
380
|
+
let lastPercent = -1;
|
|
381
|
+
const fileStream = import_node_fs2.default.createWriteStream(outputFilename);
|
|
382
|
+
const body = response.body;
|
|
383
|
+
body.on("data", (chunk) => {
|
|
384
|
+
downloaded += chunk.length;
|
|
385
|
+
if (contentLength > 0) {
|
|
386
|
+
const percent = Math.floor(downloaded / contentLength * 100);
|
|
387
|
+
if (percent !== lastPercent && percent % 10 === 0) {
|
|
388
|
+
lastPercent = percent;
|
|
389
|
+
warningLog(` download progress: ${percent}%`);
|
|
388
390
|
}
|
|
389
|
-
|
|
390
|
-
});
|
|
391
|
-
download.on("progress", (progress) => {
|
|
392
|
-
bar.update(progress);
|
|
393
|
-
});
|
|
391
|
+
}
|
|
394
392
|
});
|
|
393
|
+
await (0, import_promises.pipeline)(body, fileStream);
|
|
394
|
+
const stat = import_node_fs2.default.statSync(outputFilename);
|
|
395
|
+
if (stat.size === 0) {
|
|
396
|
+
import_node_fs2.default.unlinkSync(outputFilename);
|
|
397
|
+
throw new Error(`Downloaded file is empty: ${outputFilename}`);
|
|
398
|
+
}
|
|
399
|
+
warningLog(import_chalk2.default.green("Download complete: ") + `${stat.size} bytes`);
|
|
400
|
+
return { downloadedFile: outputFilename };
|
|
395
401
|
}
|
|
396
402
|
async function unzip_openssl(zipFilename) {
|
|
397
403
|
const opensslFolder2 = get_openssl_folder_win32();
|
|
@@ -440,6 +446,10 @@ async function install_and_check_win32_openssl_version() {
|
|
|
440
446
|
});
|
|
441
447
|
});
|
|
442
448
|
}
|
|
449
|
+
const systemOpenssl = await find_system_openssl_win32();
|
|
450
|
+
if (systemOpenssl) {
|
|
451
|
+
return systemOpenssl;
|
|
452
|
+
}
|
|
443
453
|
const opensslFolder = get_openssl_folder_win32();
|
|
444
454
|
const opensslExecPath = get_openssl_exec_path_win32();
|
|
445
455
|
if (!import_node_fs2.default.existsSync(opensslFolder)) {
|
|
@@ -1028,32 +1038,32 @@ function parseOpenSSLDate(dateStr) {
|
|
|
1028
1038
|
const sec = raw.substring(10, 12);
|
|
1029
1039
|
return `${year}-${month}-${day}T${hour}:${min}:${sec}Z`;
|
|
1030
1040
|
}
|
|
1031
|
-
function validateRevocationUrl(
|
|
1032
|
-
if (
|
|
1041
|
+
function validateRevocationUrl(url, fieldName) {
|
|
1042
|
+
if (url === void 0) {
|
|
1033
1043
|
return void 0;
|
|
1034
1044
|
}
|
|
1035
|
-
if (
|
|
1045
|
+
if (url === "") {
|
|
1036
1046
|
throw new Error(`${fieldName} must not be empty \u2014 pass undefined to disable the extension`);
|
|
1037
1047
|
}
|
|
1038
1048
|
let parsed;
|
|
1039
1049
|
try {
|
|
1040
|
-
parsed = new URL(
|
|
1050
|
+
parsed = new URL(url);
|
|
1041
1051
|
} catch {
|
|
1042
|
-
throw new Error(`${fieldName} is not a valid URL: ${
|
|
1052
|
+
throw new Error(`${fieldName} is not a valid URL: ${url}`);
|
|
1043
1053
|
}
|
|
1044
1054
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1045
|
-
throw new Error(`${fieldName} must use http: or https: (got ${parsed.protocol} in ${
|
|
1055
|
+
throw new Error(`${fieldName} must use http: or https: (got ${parsed.protocol} in ${url})`);
|
|
1046
1056
|
}
|
|
1047
1057
|
if (!parsed.pathname || parsed.pathname === "/") {
|
|
1048
|
-
throw new Error(`${fieldName} must include a path component (got ${
|
|
1058
|
+
throw new Error(`${fieldName} must include a path component (got ${url})`);
|
|
1049
1059
|
}
|
|
1050
1060
|
const isLoopback = parsed.hostname === "localhost" || parsed.hostname === "::1" || parsed.hostname.startsWith("127.");
|
|
1051
1061
|
if (isLoopback) {
|
|
1052
1062
|
console.warn(
|
|
1053
|
-
`[node-opcua-pki] ${fieldName} points at loopback (${
|
|
1063
|
+
`[node-opcua-pki] ${fieldName} points at loopback (${url}) \u2014 certificates issued with this URL will be unreachable from any other host.`
|
|
1054
1064
|
);
|
|
1055
1065
|
}
|
|
1056
|
-
return
|
|
1066
|
+
return url;
|
|
1057
1067
|
}
|
|
1058
1068
|
var CertificateAuthority = class {
|
|
1059
1069
|
/** RSA key size used when generating the CA private key. */
|
|
@@ -1115,8 +1125,8 @@ var CertificateAuthority = class {
|
|
|
1115
1125
|
*
|
|
1116
1126
|
* @see US-202
|
|
1117
1127
|
*/
|
|
1118
|
-
setCrlDistributionUrl(
|
|
1119
|
-
this._crlDistributionUrl = validateRevocationUrl(
|
|
1128
|
+
setCrlDistributionUrl(url) {
|
|
1129
|
+
this._crlDistributionUrl = validateRevocationUrl(url, "crlDistributionUrl");
|
|
1120
1130
|
}
|
|
1121
1131
|
/**
|
|
1122
1132
|
* Configure the OCSP responder URL embedded as the `OCSP` leg of
|
|
@@ -1125,8 +1135,8 @@ var CertificateAuthority = class {
|
|
|
1125
1135
|
*
|
|
1126
1136
|
* @see US-202
|
|
1127
1137
|
*/
|
|
1128
|
-
setOcspResponderUrl(
|
|
1129
|
-
this._ocspResponderUrl = validateRevocationUrl(
|
|
1138
|
+
setOcspResponderUrl(url) {
|
|
1139
|
+
this._ocspResponderUrl = validateRevocationUrl(url, "ocspResponderUrl");
|
|
1130
1140
|
}
|
|
1131
1141
|
/**
|
|
1132
1142
|
* Configure the caIssuers URL embedded as the `caIssuers` leg of
|
|
@@ -1135,8 +1145,8 @@ var CertificateAuthority = class {
|
|
|
1135
1145
|
*
|
|
1136
1146
|
* @see US-202
|
|
1137
1147
|
*/
|
|
1138
|
-
setCaIssuersUrl(
|
|
1139
|
-
this._caIssuersUrl = validateRevocationUrl(
|
|
1148
|
+
setCaIssuersUrl(url) {
|
|
1149
|
+
this._caIssuersUrl = validateRevocationUrl(url, "caIssuersUrl");
|
|
1140
1150
|
}
|
|
1141
1151
|
/**
|
|
1142
1152
|
* @internal
|