node-opcua-pki 6.22.0 → 7.0.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.
Files changed (137) hide show
  1. package/bin/install_prerequisite.ts +1 -1
  2. package/bin/pki.ts +1 -1
  3. package/dist/bin/install_prerequisite.d.ts +2 -0
  4. package/dist/bin/install_prerequisite.js +6 -0
  5. package/dist/bin/install_prerequisite.js.map +1 -0
  6. package/dist/bin/pki.d.ts +2 -0
  7. package/dist/bin/pki.js +4 -0
  8. package/dist/bin/pki.js.map +1 -0
  9. package/dist/lib/ca/backends/native_ca_backend.d.ts +49 -0
  10. package/dist/lib/ca/backends/native_ca_backend.js +365 -0
  11. package/dist/lib/ca/backends/native_ca_backend.js.map +1 -0
  12. package/dist/lib/ca/backends/openssl_ca_backend.d.ts +47 -0
  13. package/dist/lib/ca/backends/openssl_ca_backend.js +398 -0
  14. package/dist/lib/ca/backends/openssl_ca_backend.js.map +1 -0
  15. package/dist/lib/ca/certificate_authority.d.ts +62 -0
  16. package/dist/lib/ca/certificate_authority.js +91 -0
  17. package/dist/lib/ca/certificate_authority.js.map +1 -0
  18. package/dist/lib/ca/core/ca_backend.d.ts +89 -0
  19. package/dist/lib/ca/core/ca_backend.js +24 -0
  20. package/dist/lib/ca/core/ca_backend.js.map +1 -0
  21. package/dist/lib/ca/core/ca_database.d.ts +91 -0
  22. package/dist/lib/ca/core/ca_database.js +267 -0
  23. package/dist/lib/ca/core/ca_database.js.map +1 -0
  24. package/dist/{core-BwqSJPHc.d.mts → lib/ca/core/certificate_authority_core.d.ts} +45 -394
  25. package/dist/lib/ca/core/certificate_authority_core.js +1300 -0
  26. package/dist/lib/ca/core/certificate_authority_core.js.map +1 -0
  27. package/dist/lib/ca/core/index.d.ts +17 -0
  28. package/dist/lib/ca/core/index.js +25 -0
  29. package/dist/lib/ca/core/index.js.map +1 -0
  30. package/dist/lib/ca/crypto_create_CA.d.ts +1 -0
  31. package/dist/lib/ca/crypto_create_CA.js +821 -0
  32. package/dist/lib/ca/crypto_create_CA.js.map +1 -0
  33. package/dist/lib/ca/index.d.ts +1 -0
  34. package/dist/lib/ca/index.js +2 -0
  35. package/dist/lib/ca/index.js.map +1 -0
  36. package/dist/lib/ca/templates/ca_config_template.cnf.d.ts +2 -0
  37. package/dist/lib/ca/templates/ca_config_template.cnf.js +170 -0
  38. package/dist/lib/ca/templates/ca_config_template.cnf.js.map +1 -0
  39. package/dist/lib/core.d.ts +33 -0
  40. package/dist/lib/core.js +56 -0
  41. package/dist/lib/core.js.map +1 -0
  42. package/dist/lib/index.d.ts +11 -0
  43. package/dist/lib/index.js +37 -0
  44. package/dist/lib/index.js.map +1 -0
  45. package/dist/lib/misc/applicationurn.d.ts +1 -0
  46. package/dist/lib/misc/applicationurn.js +40 -0
  47. package/dist/lib/misc/applicationurn.js.map +1 -0
  48. package/dist/lib/misc/hostname.d.ts +8 -0
  49. package/dist/lib/misc/hostname.js +82 -0
  50. package/dist/lib/misc/hostname.js.map +1 -0
  51. package/dist/lib/misc/subject.d.ts +2 -0
  52. package/dist/lib/misc/subject.js +2 -0
  53. package/dist/lib/misc/subject.js.map +1 -0
  54. package/dist/{index.d.ts → lib/pki/certificate_manager.d.ts} +24 -246
  55. package/dist/lib/pki/certificate_manager.js +2302 -0
  56. package/dist/lib/pki/certificate_manager.js.map +1 -0
  57. package/dist/lib/pki/templates/simple_config_template.cnf.d.ts +2 -0
  58. package/dist/lib/pki/templates/simple_config_template.cnf.js +74 -0
  59. package/dist/lib/pki/templates/simple_config_template.cnf.js.map +1 -0
  60. package/dist/lib/pki/toolbox_pfx.d.ts +127 -0
  61. package/dist/lib/pki/toolbox_pfx.js +248 -0
  62. package/dist/lib/pki/toolbox_pfx.js.map +1 -0
  63. package/dist/lib/toolbox/common.d.ts +150 -0
  64. package/dist/lib/toolbox/common.js +82 -0
  65. package/dist/lib/toolbox/common.js.map +1 -0
  66. package/dist/lib/toolbox/common2.d.ts +25 -0
  67. package/dist/lib/toolbox/common2.js +97 -0
  68. package/dist/lib/toolbox/common2.js.map +1 -0
  69. package/dist/lib/toolbox/config.d.ts +5 -0
  70. package/dist/lib/toolbox/config.js +28 -0
  71. package/dist/lib/toolbox/config.js.map +1 -0
  72. package/dist/lib/toolbox/debug.d.ts +5 -0
  73. package/dist/lib/toolbox/debug.js +35 -0
  74. package/dist/lib/toolbox/debug.js.map +1 -0
  75. package/dist/lib/toolbox/display.d.ts +4 -0
  76. package/dist/lib/toolbox/display.js +56 -0
  77. package/dist/lib/toolbox/display.js.map +1 -0
  78. package/dist/lib/toolbox/index.d.ts +5 -0
  79. package/dist/lib/toolbox/index.js +28 -0
  80. package/dist/lib/toolbox/index.js.map +1 -0
  81. package/dist/lib/toolbox/with_openssl/_create_random_file.d.ts +4 -0
  82. package/dist/lib/toolbox/with_openssl/_create_random_file.js +50 -0
  83. package/dist/lib/toolbox/with_openssl/_create_random_file.js.map +1 -0
  84. package/dist/lib/toolbox/with_openssl/_env.d.ts +58 -0
  85. package/dist/lib/toolbox/with_openssl/_env.js +126 -0
  86. package/dist/lib/toolbox/with_openssl/_env.js.map +1 -0
  87. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.d.ts +5 -0
  88. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js +72 -0
  89. package/dist/lib/toolbox/with_openssl/create_certificate_signing_request.js.map +1 -0
  90. package/dist/lib/toolbox/with_openssl/create_private_key.d.ts +5 -0
  91. package/dist/lib/toolbox/with_openssl/create_private_key.js +92 -0
  92. package/dist/lib/toolbox/with_openssl/create_private_key.js.map +1 -0
  93. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.d.ts +5 -0
  94. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js +135 -0
  95. package/dist/lib/toolbox/with_openssl/create_self_signed_certificate.js.map +1 -0
  96. package/dist/lib/toolbox/with_openssl/execute_openssl.d.ts +67 -0
  97. package/dist/lib/toolbox/with_openssl/execute_openssl.js +246 -0
  98. package/dist/lib/toolbox/with_openssl/execute_openssl.js.map +1 -0
  99. package/dist/lib/toolbox/with_openssl/index.d.ts +5 -0
  100. package/dist/lib/toolbox/with_openssl/index.js +30 -0
  101. package/dist/lib/toolbox/with_openssl/index.js.map +1 -0
  102. package/dist/lib/toolbox/with_openssl/install_prerequisite.d.ts +7 -0
  103. package/dist/lib/toolbox/with_openssl/install_prerequisite.js +358 -0
  104. package/dist/lib/toolbox/with_openssl/install_prerequisite.js.map +1 -0
  105. package/dist/lib/toolbox/with_openssl/toolbox.d.ts +53 -0
  106. package/dist/lib/toolbox/with_openssl/toolbox.js +190 -0
  107. package/dist/lib/toolbox/with_openssl/toolbox.js.map +1 -0
  108. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.d.ts +5 -0
  109. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js +69 -0
  110. package/dist/lib/toolbox/without_openssl/create_certificate_signing_request.js.map +1 -0
  111. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.d.ts +3 -0
  112. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js +78 -0
  113. package/dist/lib/toolbox/without_openssl/create_self_signed_certificate.js.map +1 -0
  114. package/dist/lib/toolbox/without_openssl/index.d.ts +2 -0
  115. package/dist/lib/toolbox/without_openssl/index.js +25 -0
  116. package/dist/lib/toolbox/without_openssl/index.js.map +1 -0
  117. package/package.json +11 -30
  118. package/dist/bin/install_prerequisite.mjs +0 -18
  119. package/dist/bin/install_prerequisite.mjs.map +0 -1
  120. package/dist/bin/pki.mjs +0 -5895
  121. package/dist/bin/pki.mjs.map +0 -1
  122. package/dist/chunk-EQ4DGI4M.mjs +0 -1917
  123. package/dist/chunk-EQ4DGI4M.mjs.map +0 -1
  124. package/dist/chunk-GCHH54PS.mjs +0 -30
  125. package/dist/chunk-GCHH54PS.mjs.map +0 -1
  126. package/dist/core-BwqSJPHc.d.ts +0 -1041
  127. package/dist/core.d.mts +0 -2
  128. package/dist/core.d.ts +0 -2
  129. package/dist/core.js +0 -1902
  130. package/dist/core.js.map +0 -1
  131. package/dist/core.mjs +0 -21
  132. package/dist/core.mjs.map +0 -1
  133. package/dist/index.d.mts +0 -1001
  134. package/dist/index.js +0 -4968
  135. package/dist/index.js.map +0 -1
  136. package/dist/index.mjs +0 -3106
  137. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,58 @@
1
+ import type { ProcessAltNamesParam } from "../common.js";
2
+ /**
3
+ * Environment variables passed through to every openssl child process,
4
+ * beyond whatever a specific call explicitly needs (e.g. a passphrase via
5
+ * `ExecuteOptions.env`).
6
+ *
7
+ * This app's own config-templating (ALTNAME, CDP_URL, AIA_VALUE — see
8
+ * `generateStaticConfig`) substitutes values directly into the config file
9
+ * content; it never relies on the openssl child actually seeing those as
10
+ * real OS environment variables. Only `OPENSSL_CONF` and `RANDFILE` are
11
+ * genuinely required at the OS level, alongside whatever the shell, the
12
+ * dynamic loader, and the openssl binary themselves need to start up on
13
+ * each platform.
14
+ *
15
+ * Rather than handing the child the full parent process environment —
16
+ * which, in a hosting application, may hold unrelated secrets (API keys,
17
+ * database credentials, tokens) that have no business being visible to a
18
+ * spawned openssl process — only this curated, minimal set is passed
19
+ * through. The same set is used to *discover* the openssl binary
20
+ * (`install_prerequisite`) and to *run* it, so a binary that is found is
21
+ * also one that can start.
22
+ */
23
+ export declare const SAFE_ENV_PASSTHROUGH: ReadonlySet<string>;
24
+ /**
25
+ * Build the environment for an openssl child process: the allowlisted
26
+ * subset of `process.env` (see {@link SAFE_ENV_PASSTHROUGH}), overlaid with
27
+ * `extra` (per-invocation values such as a passphrase for `-passin env:`).
28
+ * Never writes to `process.env`.
29
+ */
30
+ export declare function buildChildEnv(extra?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
31
+ /**
32
+ * A copy of `options` safe to hand to a logger: the values of any
33
+ * per-invocation `env` are replaced by their variable names, so a passphrase
34
+ * passed for `-passin env:NAME` can never end up in debug output.
35
+ */
36
+ export declare function redactEnvForLog<T extends {
37
+ env?: NodeJS.ProcessEnv;
38
+ }>(options: T): Omit<T, "env"> & {
39
+ env?: string[];
40
+ };
41
+ export declare const exportedEnvVars: Record<string, string>;
42
+ export declare function setEnv(varName: string, value: string): void;
43
+ export declare function hasEnv(varName: string): boolean;
44
+ export declare function getEnv(varName: string): string;
45
+ export declare function unsetEnv(varName: string): void;
46
+ export declare function getEnvironmentVarNames(): {
47
+ key: string;
48
+ pattern: string;
49
+ }[];
50
+ /**
51
+ * Build the openssl `subjectAltName` value string (`URI:..., DNS:..., IP:...`)
52
+ * from SAN parameters. The single implementation of this format — used both
53
+ * by {@link processAltNames} (which publishes it to the shared env registry)
54
+ * and by callers that pass it as an explicit per-render override — so a
55
+ * format fix cannot land in one copy only.
56
+ */
57
+ export declare function buildSubjectAltNameString(params: ProcessAltNamesParam): string;
58
+ export declare function processAltNames(params: ProcessAltNamesParam): void;
@@ -0,0 +1,126 @@
1
+ import { g_config } from "../config.js";
2
+ import { warningLog } from "../debug.js";
3
+ /**
4
+ * Environment variables passed through to every openssl child process,
5
+ * beyond whatever a specific call explicitly needs (e.g. a passphrase via
6
+ * `ExecuteOptions.env`).
7
+ *
8
+ * This app's own config-templating (ALTNAME, CDP_URL, AIA_VALUE — see
9
+ * `generateStaticConfig`) substitutes values directly into the config file
10
+ * content; it never relies on the openssl child actually seeing those as
11
+ * real OS environment variables. Only `OPENSSL_CONF` and `RANDFILE` are
12
+ * genuinely required at the OS level, alongside whatever the shell, the
13
+ * dynamic loader, and the openssl binary themselves need to start up on
14
+ * each platform.
15
+ *
16
+ * Rather than handing the child the full parent process environment —
17
+ * which, in a hosting application, may hold unrelated secrets (API keys,
18
+ * database credentials, tokens) that have no business being visible to a
19
+ * spawned openssl process — only this curated, minimal set is passed
20
+ * through. The same set is used to *discover* the openssl binary
21
+ * (`install_prerequisite`) and to *run* it, so a binary that is found is
22
+ * also one that can start.
23
+ */
24
+ export const SAFE_ENV_PASSTHROUGH = new Set([
25
+ // POSIX/Windows shell and process essentials
26
+ "path",
27
+ "home",
28
+ "userprofile",
29
+ "temp",
30
+ "tmp",
31
+ "tmpdir",
32
+ "systemroot",
33
+ "windir",
34
+ "comspec",
35
+ "pathext",
36
+ "appdata",
37
+ "localappdata",
38
+ // dynamic loader: a custom-built or relocated openssl (e.g. under /opt,
39
+ // or Homebrew on macOS) may need these to find its own libcrypto/libssl
40
+ "ld_library_path",
41
+ "dyld_library_path",
42
+ "dyld_fallback_library_path",
43
+ // locale, so openssl's textual output stays parseable
44
+ "lang",
45
+ "lc_all",
46
+ "lc_ctype",
47
+ // openssl configuration this app, or the host OS/user, may rely on
48
+ "openssl_conf",
49
+ "randfile",
50
+ "openssl_modules",
51
+ "openssl_engines",
52
+ "ssl_cert_file",
53
+ "ssl_cert_dir"
54
+ ]);
55
+ /**
56
+ * Build the environment for an openssl child process: the allowlisted
57
+ * subset of `process.env` (see {@link SAFE_ENV_PASSTHROUGH}), overlaid with
58
+ * `extra` (per-invocation values such as a passphrase for `-passin env:`).
59
+ * Never writes to `process.env`.
60
+ */
61
+ export function buildChildEnv(extra) {
62
+ const env = {};
63
+ for (const key of Object.keys(process.env)) {
64
+ if (SAFE_ENV_PASSTHROUGH.has(key.toLowerCase())) {
65
+ env[key] = process.env[key];
66
+ }
67
+ }
68
+ return { ...env, ...extra };
69
+ }
70
+ /**
71
+ * A copy of `options` safe to hand to a logger: the values of any
72
+ * per-invocation `env` are replaced by their variable names, so a passphrase
73
+ * passed for `-passin env:NAME` can never end up in debug output.
74
+ */
75
+ export function redactEnvForLog(options) {
76
+ const { env, ...rest } = options;
77
+ return env ? { ...rest, env: Object.keys(env) } : rest;
78
+ }
79
+ export const exportedEnvVars = {};
80
+ export function setEnv(varName, value) {
81
+ // istanbul ignore next
82
+ if (!g_config.silent) {
83
+ warningLog(` set ${varName}=${value}`);
84
+ }
85
+ exportedEnvVars[varName] = value;
86
+ if (["OPENSSL_CONF"].indexOf(varName) >= 0) {
87
+ process.env[varName] = value;
88
+ }
89
+ if (["RANDFILE"].indexOf(varName) >= 0) {
90
+ process.env[varName] = value;
91
+ }
92
+ }
93
+ export function hasEnv(varName) {
94
+ return Object.prototype.hasOwnProperty.call(exportedEnvVars, varName);
95
+ }
96
+ export function getEnv(varName) {
97
+ return exportedEnvVars[varName];
98
+ }
99
+ export function unsetEnv(varName) {
100
+ delete exportedEnvVars[varName];
101
+ }
102
+ export function getEnvironmentVarNames() {
103
+ return Object.keys(exportedEnvVars).map((varName) => {
104
+ return { key: varName, pattern: `\\$ENV\\:\\:${varName}` };
105
+ });
106
+ }
107
+ /**
108
+ * Build the openssl `subjectAltName` value string (`URI:..., DNS:..., IP:...`)
109
+ * from SAN parameters. The single implementation of this format — used both
110
+ * by {@link processAltNames} (which publishes it to the shared env registry)
111
+ * and by callers that pass it as an explicit per-render override — so a
112
+ * format fix cannot land in one copy only.
113
+ */
114
+ export function buildSubjectAltNameString(params) {
115
+ return [
116
+ `URI:${params.applicationUri}`,
117
+ ...(params.dns ?? []).map((d) => `DNS:${d}`),
118
+ ...(params.ip ?? []).map((d) => `IP:${d}`)
119
+ ].join(", ");
120
+ }
121
+ export function processAltNames(params) {
122
+ params.dns = params.dns || [];
123
+ params.ip = params.ip || [];
124
+ setEnv("ALTNAME", buildSubjectAltNameString(params));
125
+ }
126
+ //# sourceMappingURL=_env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_env.js","sourceRoot":"","sources":["../../../../lib/toolbox/with_openssl/_env.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IAC7D,6CAA6C;IAC7C,MAAM;IACN,MAAM;IACN,aAAa;IACb,MAAM;IACN,KAAK;IACL,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,SAAS;IACT,SAAS;IACT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CAAC;KACrD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAA4B;IACxD,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;IAC9B,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;IAC5B,MAAM,CAAC,SAAS,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { CreateCertificateSigningRequestWithConfigOptions } from "../common.js";
2
+ /**
3
+ * create a certificate signing request
4
+ */
5
+ export declare function createCertificateSigningRequestWithOpenSSL(certificateSigningRequestFilename: string, params: CreateCertificateSigningRequestWithConfigOptions): Promise<void>;
@@ -0,0 +1,72 @@
1
+ // ---------------------------------------------------------------------------------------------------------------------
2
+ // node-opcua-pki
3
+ // ---------------------------------------------------------------------------------------------------------------------
4
+ // Copyright (c) 2014-2026 - Etienne Rossignon - etienne.rossignon (at) gadz.org
5
+ // Copyright (c) 2022-2026 - Sterfive.com
6
+ // ---------------------------------------------------------------------------------------------------------------------
7
+ //
8
+ // This project is licensed under the terms of the MIT license.
9
+ //
10
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11
+ // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
12
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
13
+ // permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
16
+ // Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
+ // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ // ---------------------------------------------------------------------------------------------------------------------
23
+ import assert from "node:assert";
24
+ import fs from "node:fs";
25
+ import path from "node:path";
26
+ import { Subject } from "../../misc/subject.js";
27
+ import { makePath } from "../common2.js";
28
+ import { displaySubtitle } from "../display.js";
29
+ import { processAltNames } from "./_env.js";
30
+ import { execute_openssl } from "./execute_openssl.js";
31
+ import { cleanupStaticConfig, generateStaticConfig } from "./toolbox.js";
32
+ const n = makePath;
33
+ /**
34
+ * create a certificate signing request
35
+ */
36
+ export async function createCertificateSigningRequestWithOpenSSL(certificateSigningRequestFilename, params) {
37
+ assert(params);
38
+ assert(params.rootDir);
39
+ assert(params.configFile);
40
+ assert(params.privateKey);
41
+ assert(typeof params.privateKey === "string");
42
+ assert(fs.existsSync(params.configFile), `config file must exist ${params.configFile}`);
43
+ assert(fs.existsSync(params.privateKey), `Private key must exist${params.privateKey}`);
44
+ assert(fs.existsSync(params.rootDir), "RootDir key must exist");
45
+ assert(typeof certificateSigningRequestFilename === "string");
46
+ // note : this openssl command requires a config file
47
+ processAltNames(params);
48
+ const configFile = generateStaticConfig(params.configFile, { cwd: params.rootDir });
49
+ try {
50
+ const options = { cwd: params.rootDir, openssl_conf: path.relative(params.rootDir, configFile) };
51
+ const subject = params.subject ? new Subject(params.subject).toString() : undefined;
52
+ displaySubtitle("- Creating a Certificate Signing Request with openssl");
53
+ await execute_openssl([
54
+ "req",
55
+ "-new",
56
+ "-sha256",
57
+ "-batch",
58
+ "-text",
59
+ "-config",
60
+ n(configFile),
61
+ "-key",
62
+ n(params.privateKey),
63
+ ...(subject ? ["-subj", subject] : []),
64
+ "-out",
65
+ n(certificateSigningRequestFilename)
66
+ ], options);
67
+ }
68
+ finally {
69
+ await cleanupStaticConfig(configFile, { cwd: params.rootDir });
70
+ }
71
+ }
72
+ //# sourceMappingURL=create_certificate_signing_request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_certificate_signing_request.js","sourceRoot":"","sources":["../../../../lib/toolbox/with_openssl/create_certificate_signing_request.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AACxH,gFAAgF;AAChF,yCAAyC;AACzC,wHAAwH;AACxH,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,+GAA+G;AAC/G,sHAAsH;AACtH,kHAAkH;AAClH,mGAAmG;AACnG,EAAE;AACF,uHAAuH;AACvH,YAAY;AACZ,EAAE;AACF,uHAAuH;AACvH,wHAAwH;AACxH,mHAAmH;AACnH,mHAAmH;AACnH,wHAAwH;AAExH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,CAAC,GAAG,QAAQ,CAAC;AAEnB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAC5D,iCAAyC,EACzC,MAAwD;IAExD,MAAM,CAAC,MAAM,CAAC,CAAC;IACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC1B,MAAM,CAAC,MAAM,CAAC,UAAU,CA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AC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,MAAM;YACN,CAAC,CAAC,iCAAiC,CAAC;SACvC,EACD,OAAO,CACV,CAAC;IACN,CAAC;YAAS,CAAC;QACP,MAAM,mBAAmB,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { KeyLength } from "../common.js";
2
+ /**
3
+ * create a RSA PRIVATE KEY
4
+ *
5
+ */ export declare function createPrivateKeyOld(privateKeyFilename: string, keyLength: KeyLength): Promise<void>;
@@ -0,0 +1,92 @@
1
+ // ---------------------------------------------------------------------------------------------------------------------
2
+ // node-opcua-pki
3
+ // ---------------------------------------------------------------------------------------------------------------------
4
+ // Copyright (c) 2014-2026 - Etienne Rossignon - etienne.rossignon (at) gadz.org
5
+ // Copyright (c) 2022-2026 - Sterfive.com
6
+ // ---------------------------------------------------------------------------------------------------------------------
7
+ //
8
+ // This project is licensed under the terms of the MIT license.
9
+ //
10
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11
+ // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
12
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
13
+ // permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
16
+ // Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
+ // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ // ---------------------------------------------------------------------------------------------------------------------
23
+ import assert from "node:assert";
24
+ import { makePath } from "../common2.js";
25
+ import { createRandomFileIfNotExist, useRandFile } from "./_create_random_file.js";
26
+ import { getEnv, hasEnv } from "./_env.js";
27
+ import { execute_openssl } from "./execute_openssl.js";
28
+ const n = makePath;
29
+ /**
30
+ * create a RSA PRIVATE KEY
31
+ *
32
+ */ export async function createPrivateKeyOld(privateKeyFilename, keyLength) {
33
+ // istanbul ignore next
34
+ if (useRandFile()) {
35
+ assert(hasEnv("RANDFILE"));
36
+ }
37
+ assert([1024, 2048, 3072, 4096].indexOf(keyLength) >= 0);
38
+ const randomFile = hasEnv("RANDFILE") ? n(getEnv("RANDFILE")) : "random.rnd";
39
+ await createRandomFileIfNotExist(randomFile, {});
40
+ // Note OpenSSL1 generates a -----BEGIN RSA PRIVATE KEY---- whereas
41
+ // OpenSSL3 generates a -----BEGIN PRIVATE KEY----- unless the new -traditional option is used
42
+ //
43
+ // a BEGIN PRIVATE KEY structure is
44
+ //
45
+ // SEQUENCE (3 elem)
46
+ // INTEGER 0
47
+ // SEQUENCE (2 elem)
48
+ // OBJECT IDENTIFIER 1.2.840.113549.1.1.1 rsaEncryption (PKCS #1)
49
+ // NULL
50
+ // OCTET STRING (609 byte) 3082025D02010002818100C5B53231183906122A5E3778736B05C095C75F1BB80D48B
51
+ // SEQUENCE (9 elem)
52
+ //
53
+ // a BEGIN RSA PRIVATE KEY structure is just
54
+ // SEQUENCE (9 elem)
55
+ //
56
+ // ------------
57
+ // SEQUENCE (3 elem)
58
+ // INTEGER 0
59
+ // SEQUENCE (2 elem)
60
+ // OBJECT IDENTIFIER 1.2.840.113549.1.1.1 rsaEncryption (PKCS #1)
61
+ // NULL
62
+ // OCTET STRING (610 byte) 3082025E02010002818100B2AA439E27C3BA098C2702AA3198EB84A7DCBD5EE89C960…
63
+ // SEQUENCE (9 elem)
64
+ // INTEGER 0
65
+ // INTEGER (1024 bit) 125462895859728341123584977638642589270771742121547332287445289226366…
66
+ // INTEGER 65537
67
+ // INTEGER (1023 bit) 774731515410736871832760190435666409081718972781314217974674368631736…
68
+ // INTEGER (512 bit) 1180764843612672431114081004978719388013129627283808550504107596576487…
69
+ // INTEGER (512 bit) 1062556160427859677755725246352892525259232894278841408942283814742302…
70
+ // INTEGER (512 bit) 8949288388532991287104785339472809167552401673320618630794823159001369…
71
+ // INTEGER (512 bit) 7748065421164683482653822084922773530923521184169484732585074266859925…
72
+ // INTEGER (512 bit) 1095294121686521689461230080512147243032904766384703204256065545245002…
73
+ // SEQUENCE (3 elem)
74
+ // INTEGER 0
75
+ // SEQUENCE (2 elem)
76
+ // OBJECT IDENTIFIER 1.2.840.113549.1.1.1 rsaEncryption (PKCS #1)
77
+ // NULL
78
+ // OCTET STRING (1190 byte) 308204A202010002820101008D57525CF578A09A540144C58BC1E0A22014261C2756…
79
+ // SEQUENCE (9 elem)
80
+ // INTEGER 0
81
+ // INTEGER (2048 bit) 178426609506070188409882662408448396194020805872625675714062746989511…
82
+ // INTEGER 65537
83
+ // INTEGER (2046 bit) 479410740008299120757682500320485803222685257276205124379958025502892…
84
+ // INTEGER (1024 bit) 137695219737286994055132178347232356287024706246418361355523203552368…
85
+ // INTEGER (1024 bit) 129580830653740837008469816238439062404066917510657577819175199112208…
86
+ // INTEGER (1023 bit) 609718979626175834639964572018353446060920850095527846336769056729744…
87
+ // INTEGER (1022 bit) 376719039084139366697037613682496827133479863181189073376679596057938…
88
+ // INTEGER (1021 bit) 162921471472202227976749871246879611058257361785053516568268141902018…
89
+ // */
90
+ await execute_openssl(["genrsa", "-out", n(privateKeyFilename), ...(useRandFile() ? ["-rand", randomFile] : []), String(keyLength)], {});
91
+ }
92
+ //# sourceMappingURL=create_private_key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_private_key.js","sourceRoot":"","sources":["../../../../lib/toolbox/with_open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B;IACpB,cAAc;IACd,sBAAsB;IACtB,qEAAqE;IACrE,WAAW;IACX,kGAAkG;IAClG,yBAAyB;IACzB,EAAE;IACF,4CAA4C;IAC5C,sBAAsB;IACtB,EAAE;IACF,eAAe;IACf,oBAAoB;IACpB,cAAc;IACd,sBAAsB;IACtB,qEAAqE;IACrE,WAAW;IACX,mGAAmG;IACnG,wBAAwB;IACxB,kBAAkB;IAClB,kGAAkG;IAClG,sBAAsB;IACtB,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAElG,oBAAoB;IACpB,cAAc;IACd,sBAAsB;IACtB,qEAAqE;IACrE,WAAW;IACX,mGAAmG;IACnG,wBAAwB;IACxB,kBAAkB;IAClB,kGAAkG;IAClG,sBAAsB;IACtB,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,kGAAkG;IAClG,KAAK;IACL,MAAM,eAAe,CACjB,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,EAC7G,EAAE,CACL,CAAC;AACN,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type CreateSelfSignCertificateWithConfigParam } from "../common.js";
2
+ /**
3
+ * @param certificate: the filename of the certificate to create
4
+ */
5
+ export declare function createSelfSignedCertificate(certificate: string, params: CreateSelfSignCertificateWithConfigParam): Promise<void>;
@@ -0,0 +1,135 @@
1
+ // ---------------------------------------------------------------------------------------------------------------------
2
+ // node-opcua-pki
3
+ // ---------------------------------------------------------------------------------------------------------------------
4
+ // Copyright (c) 2014-2026 - Etienne Rossignon - etienne.rossignon (at) gadz.org
5
+ // Copyright (c) 2022-2026 - Sterfive.com
6
+ // ---------------------------------------------------------------------------------------------------------------------
7
+ //
8
+ // This project is licensed under the terms of the MIT license.
9
+ //
10
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11
+ // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
12
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
13
+ // permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
16
+ // Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
+ // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ // ---------------------------------------------------------------------------------------------------------------------
23
+ import assert from "node:assert";
24
+ import fs from "node:fs";
25
+ import { CertificatePurpose } from "node-opcua-crypto";
26
+ import { Subject } from "../../misc/subject.js";
27
+ import { adjustDate } from "../common.js";
28
+ import { makePath } from "../common2.js";
29
+ import { displayTitle } from "../display.js";
30
+ import { processAltNames } from "./_env.js";
31
+ import { ensure_openssl_installed, execute_openssl } from "./execute_openssl.js";
32
+ import { cleanupStaticConfig, generateStaticConfig } from "./toolbox.js";
33
+ const n = makePath;
34
+ /**
35
+ * @param certificate: the filename of the certificate to create
36
+ */
37
+ export async function createSelfSignedCertificate(certificate, params) {
38
+ await ensure_openssl_installed();
39
+ params.purpose = params.purpose || CertificatePurpose.ForApplication;
40
+ assert(params.purpose, "Please provide a Certificate Purpose");
41
+ /**
42
+ * note: due to a limitation of openssl ,
43
+ * it is not possible to control the startDate of the certificate validity
44
+ * to achieve this the certificateAuthority tool shall be used.
45
+ */
46
+ assert(fs.existsSync(params.configFile));
47
+ assert(fs.existsSync(params.rootDir));
48
+ if (typeof params.privateKey !== "string") {
49
+ // This openssl-CLI-based path can only pass a private key to
50
+ // openssl as a file path (`-key <path>`); it has no way to hand it
51
+ // an in-memory key without writing the decrypted key back out to
52
+ // disk, defeating the purpose of a passphrase-protected key. Use
53
+ // CertificateManager's own createSelfSignedCertificate (the
54
+ // WebCrypto-based, without_openssl path) instead, which does
55
+ // support an in-memory PrivateKey.
56
+ throw new Error("createSelfSignedCertificate (openssl-CLI path): an in-memory PrivateKey is not supported here; provide a filename.");
57
+ }
58
+ const privateKeyFilename = params.privateKey;
59
+ assert(fs.existsSync(privateKeyFilename));
60
+ if (!params.subject) {
61
+ throw new Error("Missing subject");
62
+ }
63
+ assert(typeof params.applicationUri === "string");
64
+ assert(Array.isArray(params.dns));
65
+ // xx no key size in self-signed assert(params.keySize == 2048 || params.keySize == 4096);
66
+ processAltNames(params);
67
+ adjustDate(params);
68
+ assert(Object.prototype.hasOwnProperty.call(params, "validity"));
69
+ let subject = new Subject(params.subject);
70
+ subject = subject.toString();
71
+ const certificateRequestFilename = `${certificate}.csr`;
72
+ const configFile = generateStaticConfig(params.configFile);
73
+ try {
74
+ const configOption = ["-config", n(configFile)];
75
+ let extension;
76
+ switch (params.purpose) {
77
+ case CertificatePurpose.ForApplication:
78
+ extension = "v3_selfsigned";
79
+ break;
80
+ case CertificatePurpose.ForCertificateAuthority:
81
+ extension = "v3_ca";
82
+ break;
83
+ default:
84
+ extension = "v3_selfsigned";
85
+ }
86
+ displayTitle("Generate a certificate request");
87
+ // Once the private key is generated a Certificate Signing Request can be generated.
88
+ // The CSR is then used in one of two ways. Ideally, the CSR will be sent to a Certificate Authority, such as
89
+ // Thawte or Verisign who will verify the identity of the requestor and issue a signed certificate.
90
+ // The second option is to self-sign the CSR, which will be demonstrated in the next section
91
+ await execute_openssl([
92
+ "req",
93
+ "-new",
94
+ "-sha256",
95
+ "-text",
96
+ "-extensions",
97
+ extension,
98
+ ...configOption,
99
+ "-key",
100
+ n(privateKeyFilename),
101
+ "-out",
102
+ n(certificateRequestFilename),
103
+ "-subj",
104
+ subject
105
+ ], {});
106
+ // Xx // Step 3: Remove Passphrase from Key
107
+ // Xx execute("cp private/cakey.pem private/cakey.pem.org");
108
+ // Xx execute(openssl_path + " rsa -in private/cakey.pem.org
109
+ // Xx -out private/cakey.pem -passin pass:"+paraphrase);
110
+ displayTitle("Generate Certificate (self-signed)");
111
+ await execute_openssl([
112
+ "x509",
113
+ "-req",
114
+ "-days",
115
+ String(params.validity),
116
+ "-extensions",
117
+ extension,
118
+ "-extfile",
119
+ n(configFile),
120
+ "-in",
121
+ n(certificateRequestFilename),
122
+ "-signkey",
123
+ n(privateKeyFilename),
124
+ "-text",
125
+ "-out",
126
+ certificate
127
+ ], {});
128
+ // remove unnecessary certificate request file
129
+ await fs.promises.unlink(certificateRequestFilename);
130
+ }
131
+ finally {
132
+ await cleanupStaticConfig(configFile);
133
+ }
134
+ }
135
+ //# sourceMappingURL=create_self_signed_certificate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_self_signed_certificate.js","sourceRoot":"","sources":["../../../../lib/toolbox/with_openssl/create_self_signed_certificate.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AACxH,gFAAgF;AAChF,yCAAyC;AACzC,wHAAwH;AACxH,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,+GAA+G;AAC/G,sHAAsH;AACtH,kHAAkH;AAClH,mGAAmG;AACnG,EAAE;AACF,uHAAuH;AACvH,YAAY;AACZ,EAAE;AACF,uHAAuH;AACvH,wHAAwH;AACxH,mHAAmH;AACnH,mHAAmH;AACnH,wHAAwH;AAExH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,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YACT,OAAO;YACP,aAAa;YACb,SAAS;YACT,GAAG,YAAY;YACf,MAAM;YACN,CAAC,CAAC,kBAAkB,CAAC;YACrB,MAAM;YACN,CAAC,CAAC,0BAA0B,CAAC;YAC7B,OAAO;YACP,OAAO;SACV,EACD,EAAE,CACL,CAAC;QAEF,2CAA2C;QAC3C,4DAA4D;QAC5D,4DAA4D;QAC5D,wDAAwD;QAExD,YAAY,CAAC,oCAAoC,CAAC,CAAC;QACnD,MAAM,eAAe,CACjB;YACI,MAAM;YACN,MAAM;YACN,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;YACvB,aAAa;YACb,SAAS;YACT,UAAU;YACV,CAAC,CAAC,UAAU,CAAC;YACb,KAAK;YACL,CAAC,CAAC,0BAA0B,CAAC;YAC7B,UAAU;YACV,CAAC,CAAC,kBAAkB,CAAC;YACrB,OAAO;YACP,MAAM;YACN,WAAW;SACd,EACD,EAAE,CACL,CAAC;QACF,8CAA8C;QAE9C,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;IACzD,CAAC;YAAS,CAAC;QACP,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;AACL,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Arguments for one openssl invocation, one array element per argv entry,
3
+ * e.g. `["x509", "-in", certificateFile, "-noout"]`. Values are handed to
4
+ * the openssl process as-is: no shell is involved, so no quoting or escaping
5
+ * is needed and no value can be interpreted as a shell metacharacter.
6
+ */
7
+ export type OpensslArgs = readonly string[];
8
+ export interface ExecuteOptions {
9
+ cwd?: string;
10
+ hideErrorMessage?: boolean;
11
+ /**
12
+ * Extra environment variables for this invocation only. Merged with a
13
+ * curated, minimal passthrough of the current process environment (see
14
+ * `SAFE_ENV_PASSTHROUGH` in `_env.ts`) for the spawned child — never the
15
+ * full parent environment, and never written to `process.env`, so
16
+ * concurrent invocations cannot see or clobber each other's values and
17
+ * unrelated secrets sitting in the host application's environment are
18
+ * never handed to the openssl child.
19
+ *
20
+ * Use this together with openssl's `-passin env:NAME` / `-passout
21
+ * env:NAME` syntax to pass a secret without ever placing it in argv: an
22
+ * argv value is visible to other processes via the process list. See
23
+ * {@link passinArg} / {@link passoutArg}.
24
+ */
25
+ env?: NodeJS.ProcessEnv;
26
+ }
27
+ /** openssl argv entries plus the env they need; merge `env` into `ExecuteOptions.env`. */
28
+ export interface OpensslPassArg {
29
+ args: string[];
30
+ env: NodeJS.ProcessEnv;
31
+ }
32
+ /**
33
+ * `-passin env:...` for a source passphrase (an input key or PFX bundle).
34
+ *
35
+ * Always emit this — with `""` when there is no passphrase — for any command
36
+ * that reads a private key which *might* be encrypted: without a `-passin`,
37
+ * openssl prompts on the controlling terminal for an encrypted key. An empty
38
+ * `-passin` on a plaintext key is a no-op; on an encrypted key it fails fast
39
+ * with `bad decrypt` instead.
40
+ */
41
+ export declare function passinArg(passphrase?: string): OpensslPassArg;
42
+ /** `-passout env:...` for an output passphrase (a PFX bundle being written). */
43
+ export declare function passoutArg(passphrase?: string): OpensslPassArg;
44
+ /**
45
+ * Run `file` with `args` directly (no shell): each element of `args` reaches
46
+ * the child as one argv entry, so a value can never be reinterpreted as a
47
+ * shell metacharacter, a redirection, or a second command. stdin is
48
+ * `/dev/null`: OpenSSL's app UI opens the console before honouring
49
+ * `-passin` and calls tcgetattr on stdin when there is no controlling TTY;
50
+ * a socket (Node's default child stdin) yields ENOTTY on Linux but
51
+ * EOPNOTSUPP on macOS, which OpenSSL rejects and the key load fails even
52
+ * with the right passphrase; /dev/null yields ENOTTY everywhere. It also
53
+ * removes any way for openssl to block reading a password from stdin.
54
+ */
55
+ export declare function execute(file: string, args: OpensslArgs, options: ExecuteOptions): Promise<string>;
56
+ export declare function find_openssl(): Promise<string>;
57
+ export declare function ensure_openssl_installed(): Promise<void>;
58
+ export declare function executeOpensslAsync(args: OpensslArgs, options: ExecuteOpenSSLOptions): Promise<string>;
59
+ export declare function execute_openssl_no_failure(args: OpensslArgs, options: ExecuteOpenSSLOptions): Promise<string | undefined>;
60
+ export interface ExecuteOpenSSLOptions extends ExecuteOptions {
61
+ openssl_conf?: string;
62
+ }
63
+ /**
64
+ * Run `openssl` with `args` (see {@link OpensslArgs}): no shell, one argv
65
+ * entry per element, curated environment, /dev/null stdin.
66
+ */
67
+ export declare function execute_openssl(args: OpensslArgs, options: ExecuteOpenSSLOptions): Promise<string>;