node-opcua-crypto 4.16.1 → 5.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.
- package/LICENSE +23 -23
- package/README.md +1 -1
- package/dist/{chunk-MGQCHN54.mjs → chunk-BIS3W2GR.mjs} +507 -458
- package/dist/chunk-BIS3W2GR.mjs.map +1 -0
- package/dist/{chunk-JDT2M2NN.mjs → chunk-ISIVVQGT.mjs} +39 -38
- package/dist/chunk-ISIVVQGT.mjs.map +1 -0
- package/dist/{common-CFr95Map.d.mts → common-DxHkx4Pv.d.mts} +2 -2
- package/dist/{common-CFr95Map.d.ts → common-DxHkx4Pv.d.ts} +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +573 -517
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/source/index.d.mts +3 -3
- package/dist/source/index.d.ts +3 -3
- package/dist/source/index.js +549 -494
- package/dist/source/index.js.map +1 -1
- package/dist/source/index.mjs +1 -1
- package/dist/source/index_web.d.mts +24 -18
- package/dist/source/index_web.d.ts +24 -18
- package/dist/source/index_web.js +549 -494
- package/dist/source/index_web.js.map +1 -1
- package/dist/source/index_web.mjs +1 -1
- package/dist/source_nodejs/index.d.mts +11 -11
- package/dist/source_nodejs/index.d.ts +11 -11
- package/dist/source_nodejs/index.js +199 -193
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/index.mjs +2 -2
- package/package.json +3 -4
- package/dist/chunk-JDT2M2NN.mjs.map +0 -1
- package/dist/chunk-MGQCHN54.mjs.map +0 -1
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { C as Certificate,
|
|
2
|
-
import 'crypto';
|
|
1
|
+
import { C as Certificate, K as KeyObject, P as PrivateKey, d as CertificatePEM, f as PublicKeyPEM, e as PrivateKeyPEM, a as PublicKey, g as CertificateRevocationList } from '../common-DxHkx4Pv.mjs';
|
|
2
|
+
import 'node:crypto';
|
|
3
|
+
|
|
4
|
+
declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* alternate function to generate PrivateKeyFile, using jsrsasign.
|
|
7
|
+
*
|
|
8
|
+
* This function is slower than generatePrivateKeyFile
|
|
9
|
+
*/
|
|
10
|
+
declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* read a DER or PEM certificate from file
|
|
@@ -8,7 +16,7 @@ declare function readCertificate(filename: string): Certificate;
|
|
|
8
16
|
/**
|
|
9
17
|
* read a DER or PEM certificate from file
|
|
10
18
|
*/
|
|
11
|
-
declare function readPublicKey(filename: string):
|
|
19
|
+
declare function readPublicKey(filename: string): KeyObject;
|
|
12
20
|
/**
|
|
13
21
|
* read a DER or PEM certificate from file
|
|
14
22
|
*/
|
|
@@ -34,12 +42,4 @@ declare function readCertificateRevocationList(filename: string): Promise<Certif
|
|
|
34
42
|
type CertificateSigningRequest = Buffer;
|
|
35
43
|
declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
|
|
36
44
|
|
|
37
|
-
declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* alternate function to generate PrivateKeyFile, using jsrsasign.
|
|
40
|
-
*
|
|
41
|
-
* This function is slower than generatePrivateKeyFile
|
|
42
|
-
*/
|
|
43
|
-
declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
|
|
44
|
-
|
|
45
45
|
export { type CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificatePEM, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyPEM, readPrivateRsaKey, readPublicKey, readPublicKeyPEM, readPublicRsaKey, setCertificateStore };
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { C as Certificate,
|
|
2
|
-
import 'crypto';
|
|
1
|
+
import { C as Certificate, K as KeyObject, P as PrivateKey, d as CertificatePEM, f as PublicKeyPEM, e as PrivateKeyPEM, a as PublicKey, g as CertificateRevocationList } from '../common-DxHkx4Pv.js';
|
|
2
|
+
import 'node:crypto';
|
|
3
|
+
|
|
4
|
+
declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* alternate function to generate PrivateKeyFile, using jsrsasign.
|
|
7
|
+
*
|
|
8
|
+
* This function is slower than generatePrivateKeyFile
|
|
9
|
+
*/
|
|
10
|
+
declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* read a DER or PEM certificate from file
|
|
@@ -8,7 +16,7 @@ declare function readCertificate(filename: string): Certificate;
|
|
|
8
16
|
/**
|
|
9
17
|
* read a DER or PEM certificate from file
|
|
10
18
|
*/
|
|
11
|
-
declare function readPublicKey(filename: string):
|
|
19
|
+
declare function readPublicKey(filename: string): KeyObject;
|
|
12
20
|
/**
|
|
13
21
|
* read a DER or PEM certificate from file
|
|
14
22
|
*/
|
|
@@ -34,12 +42,4 @@ declare function readCertificateRevocationList(filename: string): Promise<Certif
|
|
|
34
42
|
type CertificateSigningRequest = Buffer;
|
|
35
43
|
declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
|
|
36
44
|
|
|
37
|
-
declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* alternate function to generate PrivateKeyFile, using jsrsasign.
|
|
40
|
-
*
|
|
41
|
-
* This function is slower than generatePrivateKeyFile
|
|
42
|
-
*/
|
|
43
|
-
declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
|
|
44
|
-
|
|
45
45
|
export { type CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificatePEM, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyPEM, readPrivateRsaKey, readPublicKey, readPublicKeyPEM, readPublicRsaKey, setCertificateStore };
|
|
@@ -47,31 +47,24 @@ __export(source_nodejs_exports, {
|
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(source_nodejs_exports);
|
|
49
49
|
|
|
50
|
-
// source_nodejs/
|
|
51
|
-
var import_assert5 = __toESM(require("assert"));
|
|
50
|
+
// source_nodejs/generate_private_key_filename.ts
|
|
52
51
|
var import_node_fs = __toESM(require("fs"));
|
|
53
|
-
var
|
|
54
|
-
var import_crypto = require("crypto");
|
|
55
|
-
|
|
56
|
-
// source/crypto_utils.ts
|
|
57
|
-
var import_constants = __toESM(require("constants"));
|
|
58
|
-
var import_assert4 = __toESM(require("assert"));
|
|
59
|
-
var import_hexy = __toESM(require("hexy"));
|
|
52
|
+
var import_jsrsasign3 = __toESM(require("jsrsasign"));
|
|
60
53
|
|
|
61
|
-
// source/
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
};
|
|
54
|
+
// source/common.ts
|
|
55
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
56
|
+
var KeyObjectOrig = import_node_crypto.default.KeyObject;
|
|
57
|
+
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_node_crypto.default;
|
|
65
58
|
|
|
66
59
|
// source/crypto_explore_certificate.ts
|
|
67
|
-
var
|
|
60
|
+
var import_node_assert4 = __toESM(require("assert"));
|
|
68
61
|
|
|
69
62
|
// source/asn1.ts
|
|
70
|
-
var
|
|
63
|
+
var import_node_assert = __toESM(require("assert"));
|
|
71
64
|
function readTag(buf, pos) {
|
|
72
65
|
const start = pos;
|
|
73
66
|
if (buf.length <= pos) {
|
|
74
|
-
throw new Error(
|
|
67
|
+
throw new Error(`Invalid position : buf.length=${buf.length} pos=${pos}`);
|
|
75
68
|
}
|
|
76
69
|
const tag = buf.readUInt8(pos);
|
|
77
70
|
pos += 1;
|
|
@@ -88,38 +81,18 @@ function readTag(buf, pos) {
|
|
|
88
81
|
return { start, tag, position: pos, length };
|
|
89
82
|
}
|
|
90
83
|
|
|
91
|
-
// source/
|
|
92
|
-
var
|
|
84
|
+
// source/crypto_utils.ts
|
|
85
|
+
var import_node_assert2 = __toESM(require("assert"));
|
|
86
|
+
var import_node_constants = __toESM(require("constants"));
|
|
87
|
+
var import_node_crypto2 = require("crypto");
|
|
88
|
+
var import_jsrsasign = __toESM(require("jsrsasign"));
|
|
93
89
|
|
|
94
|
-
// source/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const block_info = readTag(certificateChain, 0);
|
|
99
|
-
const length = block_info.position + block_info.length;
|
|
100
|
-
const der_certificate = certificateChain.subarray(0, length);
|
|
101
|
-
certificate_chain.push(der_certificate);
|
|
102
|
-
certificateChain = certificateChain.subarray(length);
|
|
103
|
-
} while (certificateChain.length > 0);
|
|
104
|
-
return certificate_chain;
|
|
105
|
-
}
|
|
106
|
-
function combine_der(certificates) {
|
|
107
|
-
for (const cert of certificates) {
|
|
108
|
-
const b = split_der(cert);
|
|
109
|
-
let sum = 0;
|
|
110
|
-
b.forEach((block) => {
|
|
111
|
-
const block_info = readTag(block, 0);
|
|
112
|
-
(0, import_assert3.default)(block_info.position + block_info.length === block.length);
|
|
113
|
-
sum += block.length;
|
|
114
|
-
});
|
|
115
|
-
(0, import_assert3.default)(sum === cert.length);
|
|
116
|
-
}
|
|
117
|
-
return Buffer.concat(certificates);
|
|
118
|
-
}
|
|
90
|
+
// source/buffer_utils.ts
|
|
91
|
+
var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
|
|
92
|
+
return new Buffer(size);
|
|
93
|
+
};
|
|
119
94
|
|
|
120
95
|
// source/crypto_utils.ts
|
|
121
|
-
var import_jsrsasign = __toESM(require("jsrsasign"));
|
|
122
|
-
var { hexy } = import_hexy.default;
|
|
123
96
|
var PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n?)/gm;
|
|
124
97
|
var PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
|
|
125
98
|
function identifyPemType(rawKey) {
|
|
@@ -134,192 +107,103 @@ function removeTrailingLF(str) {
|
|
|
134
107
|
return tmp;
|
|
135
108
|
}
|
|
136
109
|
function toPem(raw_key, pem) {
|
|
137
|
-
(0,
|
|
138
|
-
(0,
|
|
110
|
+
(0, import_node_assert2.default)(raw_key, "expecting a key");
|
|
111
|
+
(0, import_node_assert2.default)(typeof pem === "string");
|
|
139
112
|
let pemType = identifyPemType(raw_key);
|
|
140
113
|
if (pemType) {
|
|
141
114
|
return Buffer.isBuffer(raw_key) ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
|
|
142
115
|
} else {
|
|
143
116
|
pemType = pem;
|
|
144
|
-
(0,
|
|
117
|
+
(0, import_node_assert2.default)(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
|
|
145
118
|
let b = raw_key.toString("base64");
|
|
146
|
-
let str =
|
|
119
|
+
let str = `-----BEGIN ${pemType}-----
|
|
120
|
+
`;
|
|
147
121
|
while (b.length) {
|
|
148
|
-
str += b.substring(0, 64)
|
|
122
|
+
str += `${b.substring(0, 64)}
|
|
123
|
+
`;
|
|
149
124
|
b = b.substring(64);
|
|
150
125
|
}
|
|
151
|
-
str +=
|
|
126
|
+
str += `-----END ${pemType}-----`;
|
|
152
127
|
return str;
|
|
153
128
|
}
|
|
154
129
|
}
|
|
155
130
|
function convertPEMtoDER(raw_key) {
|
|
156
131
|
let match;
|
|
157
|
-
let
|
|
132
|
+
let _pemType;
|
|
158
133
|
let base64str;
|
|
159
134
|
const parts = [];
|
|
160
135
|
PEM_REGEX.lastIndex = 0;
|
|
161
|
-
|
|
162
|
-
|
|
136
|
+
match = PEM_REGEX.exec(raw_key);
|
|
137
|
+
while (match !== null) {
|
|
138
|
+
_pemType = match[2];
|
|
163
139
|
base64str = match[3];
|
|
164
140
|
base64str = base64str.replace(/\r?\n/g, "");
|
|
165
141
|
parts.push(Buffer.from(base64str, "base64"));
|
|
142
|
+
match = PEM_REGEX.exec(raw_key);
|
|
166
143
|
}
|
|
167
144
|
return combine_der(parts);
|
|
168
145
|
}
|
|
169
|
-
var RSA_PKCS1_OAEP_PADDING =
|
|
170
|
-
var RSA_PKCS1_PADDING =
|
|
171
|
-
(0,
|
|
172
|
-
(0,
|
|
146
|
+
var RSA_PKCS1_OAEP_PADDING = import_node_constants.default.RSA_PKCS1_OAEP_PADDING;
|
|
147
|
+
var RSA_PKCS1_PADDING = import_node_constants.default.RSA_PKCS1_PADDING;
|
|
148
|
+
(0, import_node_assert2.default)(4 /* RSA_PKCS1_OAEP_PADDING */ === import_node_constants.default.RSA_PKCS1_OAEP_PADDING);
|
|
149
|
+
(0, import_node_assert2.default)(1 /* RSA_PKCS1_PADDING */ === import_node_constants.default.RSA_PKCS1_PADDING);
|
|
173
150
|
|
|
174
|
-
//
|
|
175
|
-
var
|
|
176
|
-
function _readPemFile(filename) {
|
|
177
|
-
(0, import_assert5.default)(typeof filename === "string");
|
|
178
|
-
return removeTrailingLF(import_node_fs.default.readFileSync(filename, "utf-8"));
|
|
179
|
-
}
|
|
180
|
-
function _readPemOrDerFileAsDER(filename) {
|
|
181
|
-
if (filename.match(/.*\.der/)) {
|
|
182
|
-
return import_node_fs.default.readFileSync(filename);
|
|
183
|
-
}
|
|
184
|
-
const raw_key = _readPemFile(filename);
|
|
185
|
-
return convertPEMtoDER(raw_key);
|
|
186
|
-
}
|
|
187
|
-
function readCertificate(filename) {
|
|
188
|
-
return _readPemOrDerFileAsDER(filename);
|
|
189
|
-
}
|
|
190
|
-
function readPublicKey(filename) {
|
|
191
|
-
if (filename.match(/.*\.der/)) {
|
|
192
|
-
const der = import_node_fs.default.readFileSync(filename);
|
|
193
|
-
return (0, import_crypto.createPublicKey)(der);
|
|
194
|
-
} else {
|
|
195
|
-
const raw_key = _readPemFile(filename);
|
|
196
|
-
return (0, import_crypto.createPublicKey)(raw_key);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function myCreatePrivateKey(rawKey) {
|
|
200
|
-
if (!import_crypto.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
|
|
201
|
-
if (Buffer.isBuffer(rawKey)) {
|
|
202
|
-
const pemKey = toPem(rawKey, "PRIVATE KEY");
|
|
203
|
-
(0, import_assert5.default)(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
|
|
204
|
-
return { hidden: pemKey };
|
|
205
|
-
}
|
|
206
|
-
return { hidden: ensureTrailingLF(rawKey) };
|
|
207
|
-
}
|
|
208
|
-
const backup = process.env.OPENSSL_CONF;
|
|
209
|
-
process.env.OPENSSL_CONF = "/dev/null";
|
|
210
|
-
const retValue = (0, import_crypto.createPrivateKey)(rawKey);
|
|
211
|
-
process.env.OPENSSL_CONF = backup;
|
|
212
|
-
return { hidden: retValue };
|
|
213
|
-
}
|
|
214
|
-
function ensureTrailingLF(str) {
|
|
215
|
-
return str.match(/\n$/) ? str : str + "\n";
|
|
216
|
-
}
|
|
217
|
-
function readPrivateKey(filename) {
|
|
218
|
-
if (filename.match(/.*\.der/)) {
|
|
219
|
-
const der = import_node_fs.default.readFileSync(filename);
|
|
220
|
-
return myCreatePrivateKey(der);
|
|
221
|
-
} else {
|
|
222
|
-
const raw_key = _readPemFile(filename);
|
|
223
|
-
return myCreatePrivateKey(raw_key);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function readCertificatePEM(filename) {
|
|
227
|
-
return _readPemFile(filename);
|
|
228
|
-
}
|
|
229
|
-
function readPublicKeyPEM(filename) {
|
|
230
|
-
return _readPemFile(filename);
|
|
231
|
-
}
|
|
232
|
-
function readPrivateKeyPEM(filename) {
|
|
233
|
-
return _readPemFile(filename);
|
|
234
|
-
}
|
|
235
|
-
var _g_certificate_store = "";
|
|
236
|
-
function setCertificateStore(store) {
|
|
237
|
-
const old_store = _g_certificate_store;
|
|
238
|
-
_g_certificate_store = store;
|
|
239
|
-
return old_store;
|
|
240
|
-
}
|
|
241
|
-
function getCertificateStore() {
|
|
242
|
-
if (!_g_certificate_store) {
|
|
243
|
-
_g_certificate_store = import_node_path.default.join(__dirname, "../../certificates/");
|
|
244
|
-
}
|
|
245
|
-
return _g_certificate_store;
|
|
246
|
-
}
|
|
247
|
-
function readPrivateRsaKey(filename) {
|
|
248
|
-
if (!import_crypto.createPrivateKey) {
|
|
249
|
-
throw new Error("createPrivateKey is not supported in this environment");
|
|
250
|
-
}
|
|
251
|
-
if (filename.substring(0, 1) !== "." && !import_node_fs.default.existsSync(filename)) {
|
|
252
|
-
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
253
|
-
}
|
|
254
|
-
const content = import_node_fs.default.readFileSync(filename, "utf8");
|
|
255
|
-
const sshKey = import_sshpk.default.parsePrivateKey(content, "auto");
|
|
256
|
-
const key = sshKey.toString("pkcs1");
|
|
257
|
-
const hidden = (0, import_crypto.createPrivateKey)({ format: "pem", type: "pkcs1", key });
|
|
258
|
-
return { hidden };
|
|
259
|
-
}
|
|
260
|
-
function readPublicRsaKey(filename) {
|
|
261
|
-
if (filename.substring(0, 1) !== "." && !import_node_fs.default.existsSync(filename)) {
|
|
262
|
-
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
263
|
-
}
|
|
264
|
-
const content = import_node_fs.default.readFileSync(filename, "utf-8");
|
|
265
|
-
const sshKey = import_sshpk.default.parseKey(content, "ssh");
|
|
266
|
-
const key = sshKey.toString("pkcs1");
|
|
267
|
-
return (0, import_crypto.createPublicKey)({ format: "pem", type: "pkcs1", key });
|
|
268
|
-
}
|
|
151
|
+
// source/directory_name.ts
|
|
152
|
+
var import_node_assert3 = __toESM(require("assert"));
|
|
269
153
|
|
|
270
|
-
//
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
154
|
+
// source/crypto_explore_certificate.ts
|
|
155
|
+
function split_der(certificateChain) {
|
|
156
|
+
const certificate_chain = [];
|
|
157
|
+
do {
|
|
158
|
+
const block_info = readTag(certificateChain, 0);
|
|
159
|
+
const length = block_info.position + block_info.length;
|
|
160
|
+
const der_certificate = certificateChain.subarray(0, length);
|
|
161
|
+
certificate_chain.push(der_certificate);
|
|
162
|
+
certificateChain = certificateChain.subarray(length);
|
|
163
|
+
} while (certificateChain.length > 0);
|
|
164
|
+
return certificate_chain;
|
|
279
165
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
166
|
+
function combine_der(certificates) {
|
|
167
|
+
for (const cert of certificates) {
|
|
168
|
+
const b = split_der(cert);
|
|
169
|
+
let sum = 0;
|
|
170
|
+
b.forEach((block) => {
|
|
171
|
+
const block_info = readTag(block, 0);
|
|
172
|
+
(0, import_node_assert4.default)(block_info.position + block_info.length === block.length);
|
|
173
|
+
sum += block.length;
|
|
174
|
+
});
|
|
175
|
+
(0, import_node_assert4.default)(sum === cert.length);
|
|
287
176
|
}
|
|
288
|
-
|
|
289
|
-
return convertPEMtoDER(raw_crl);
|
|
177
|
+
return Buffer.concat(certificates);
|
|
290
178
|
}
|
|
291
179
|
|
|
292
|
-
// source_nodejs/generate_private_key_filename.ts
|
|
293
|
-
var import_node_fs4 = __toESM(require("fs"));
|
|
294
|
-
|
|
295
|
-
// source/explore_private_key.ts
|
|
296
|
-
var doDebug = !!process.env.DEBUG;
|
|
297
|
-
|
|
298
|
-
// source/common.ts
|
|
299
|
-
var import_crypto2 = __toESM(require("crypto"));
|
|
300
|
-
var KeyObjectOrig = import_crypto2.default.KeyObject;
|
|
301
|
-
var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto2.default;
|
|
302
|
-
|
|
303
180
|
// source/crypto_utils2.ts
|
|
304
|
-
var
|
|
181
|
+
var import_node_assert5 = __toESM(require("assert"));
|
|
305
182
|
var import_jsrsasign2 = __toESM(require("jsrsasign"));
|
|
306
183
|
|
|
307
184
|
// source/derived_keys.ts
|
|
308
|
-
var
|
|
185
|
+
var import_node_assert7 = __toESM(require("assert"));
|
|
186
|
+
var import_node_crypto3 = require("crypto");
|
|
309
187
|
|
|
310
188
|
// source/explore_certificate.ts
|
|
311
|
-
var
|
|
189
|
+
var import_node_assert6 = __toESM(require("assert"));
|
|
190
|
+
|
|
191
|
+
// source/explore_private_key.ts
|
|
192
|
+
var doDebug = !!process.env.DEBUG;
|
|
193
|
+
|
|
194
|
+
// source/verify_certificate_signature.ts
|
|
195
|
+
var import_node_crypto4 = require("crypto");
|
|
312
196
|
|
|
313
197
|
// source/x509/_crypto.ts
|
|
314
|
-
var
|
|
198
|
+
var import_node_crypto5 = __toESM(require("crypto"));
|
|
315
199
|
var import_webcrypto = require("@peculiar/webcrypto");
|
|
316
|
-
var
|
|
200
|
+
var x509 = __toESM(require("@peculiar/x509"));
|
|
317
201
|
var x5092 = __toESM(require("@peculiar/x509"));
|
|
318
202
|
var doDebug2 = false;
|
|
319
203
|
var _crypto;
|
|
320
204
|
var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
|
|
321
205
|
if (typeof window === "undefined") {
|
|
322
|
-
_crypto =
|
|
206
|
+
_crypto = import_node_crypto5.default;
|
|
323
207
|
if (!_crypto?.subtle || ignoreCrypto) {
|
|
324
208
|
_crypto = new import_webcrypto.Crypto();
|
|
325
209
|
doDebug2 && console.warn("using @peculiar/webcrypto");
|
|
@@ -333,7 +217,7 @@ if (typeof window === "undefined") {
|
|
|
333
217
|
x509.cryptoProvider.set(crypto);
|
|
334
218
|
}
|
|
335
219
|
function getCrypto() {
|
|
336
|
-
return _crypto || crypto ||
|
|
220
|
+
return _crypto || crypto || import_node_crypto5.default;
|
|
337
221
|
}
|
|
338
222
|
|
|
339
223
|
// source/x509/create_key_pair.ts
|
|
@@ -4047,20 +3931,142 @@ var AsnSchemaStorage = class {
|
|
|
4047
3931
|
var schemaStorage = new AsnSchemaStorage();
|
|
4048
3932
|
|
|
4049
3933
|
// source_nodejs/generate_private_key_filename.ts
|
|
4050
|
-
var import_jsrsasign3 = __toESM(require("jsrsasign"));
|
|
4051
3934
|
async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
|
|
4052
3935
|
const keys = await generateKeyPair(modulusLength);
|
|
4053
3936
|
const privateKeyPem = await privateKeyToPEM(keys.privateKey);
|
|
4054
|
-
await
|
|
3937
|
+
await import_node_fs.default.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
|
|
4055
3938
|
privateKeyPem.privPem = "";
|
|
4056
3939
|
privateKeyPem.privDer = new ArrayBuffer(0);
|
|
4057
3940
|
}
|
|
4058
3941
|
async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
|
|
4059
3942
|
const kp = import_jsrsasign3.default.KEYUTIL.generateKeypair("RSA", modulusLength);
|
|
4060
3943
|
const prv = kp.prvKeyObj;
|
|
4061
|
-
const
|
|
3944
|
+
const _pub = kp.pubKeyObj;
|
|
4062
3945
|
const prvpem = import_jsrsasign3.default.KEYUTIL.getPEM(prv, "PKCS8PRV");
|
|
4063
|
-
await
|
|
3946
|
+
await import_node_fs.default.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
|
|
3947
|
+
}
|
|
3948
|
+
|
|
3949
|
+
// source_nodejs/read.ts
|
|
3950
|
+
var import_node_assert8 = __toESM(require("assert"));
|
|
3951
|
+
var import_node_crypto6 = require("crypto");
|
|
3952
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
3953
|
+
var import_node_path = __toESM(require("path"));
|
|
3954
|
+
var import_sshpk = __toESM(require("sshpk"));
|
|
3955
|
+
function _readPemFile(filename) {
|
|
3956
|
+
(0, import_node_assert8.default)(typeof filename === "string");
|
|
3957
|
+
return removeTrailingLF(import_node_fs2.default.readFileSync(filename, "utf-8"));
|
|
3958
|
+
}
|
|
3959
|
+
function _readPemOrDerFileAsDER(filename) {
|
|
3960
|
+
if (filename.match(/.*\.der/)) {
|
|
3961
|
+
return import_node_fs2.default.readFileSync(filename);
|
|
3962
|
+
}
|
|
3963
|
+
const raw_key = _readPemFile(filename);
|
|
3964
|
+
return convertPEMtoDER(raw_key);
|
|
3965
|
+
}
|
|
3966
|
+
function readCertificate(filename) {
|
|
3967
|
+
return _readPemOrDerFileAsDER(filename);
|
|
3968
|
+
}
|
|
3969
|
+
function readPublicKey(filename) {
|
|
3970
|
+
if (filename.match(/.*\.der/)) {
|
|
3971
|
+
const der = import_node_fs2.default.readFileSync(filename);
|
|
3972
|
+
return (0, import_node_crypto6.createPublicKey)(der);
|
|
3973
|
+
} else {
|
|
3974
|
+
const raw_key = _readPemFile(filename);
|
|
3975
|
+
return (0, import_node_crypto6.createPublicKey)(raw_key);
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
function myCreatePrivateKey(rawKey) {
|
|
3979
|
+
if (!import_node_crypto6.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
|
|
3980
|
+
if (Buffer.isBuffer(rawKey)) {
|
|
3981
|
+
const pemKey = toPem(rawKey, "PRIVATE KEY");
|
|
3982
|
+
(0, import_node_assert8.default)(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
|
|
3983
|
+
return { hidden: pemKey };
|
|
3984
|
+
}
|
|
3985
|
+
return { hidden: ensureTrailingLF(rawKey) };
|
|
3986
|
+
}
|
|
3987
|
+
const backup = process.env.OPENSSL_CONF;
|
|
3988
|
+
process.env.OPENSSL_CONF = "/dev/null";
|
|
3989
|
+
const retValue = (0, import_node_crypto6.createPrivateKey)(rawKey);
|
|
3990
|
+
process.env.OPENSSL_CONF = backup;
|
|
3991
|
+
return { hidden: retValue };
|
|
3992
|
+
}
|
|
3993
|
+
function ensureTrailingLF(str) {
|
|
3994
|
+
return str.match(/\n$/) ? str : `${str}
|
|
3995
|
+
`;
|
|
3996
|
+
}
|
|
3997
|
+
function readPrivateKey(filename) {
|
|
3998
|
+
if (filename.match(/.*\.der/)) {
|
|
3999
|
+
const der = import_node_fs2.default.readFileSync(filename);
|
|
4000
|
+
return myCreatePrivateKey(der);
|
|
4001
|
+
} else {
|
|
4002
|
+
const raw_key = _readPemFile(filename);
|
|
4003
|
+
return myCreatePrivateKey(raw_key);
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
function readCertificatePEM(filename) {
|
|
4007
|
+
return _readPemFile(filename);
|
|
4008
|
+
}
|
|
4009
|
+
function readPublicKeyPEM(filename) {
|
|
4010
|
+
return _readPemFile(filename);
|
|
4011
|
+
}
|
|
4012
|
+
function readPrivateKeyPEM(filename) {
|
|
4013
|
+
return _readPemFile(filename);
|
|
4014
|
+
}
|
|
4015
|
+
var _g_certificate_store = "";
|
|
4016
|
+
function setCertificateStore(store) {
|
|
4017
|
+
const old_store = _g_certificate_store;
|
|
4018
|
+
_g_certificate_store = store;
|
|
4019
|
+
return old_store;
|
|
4020
|
+
}
|
|
4021
|
+
function getCertificateStore() {
|
|
4022
|
+
if (!_g_certificate_store) {
|
|
4023
|
+
_g_certificate_store = import_node_path.default.join(__dirname, "../../certificates/");
|
|
4024
|
+
}
|
|
4025
|
+
return _g_certificate_store;
|
|
4026
|
+
}
|
|
4027
|
+
function readPrivateRsaKey(filename) {
|
|
4028
|
+
if (!import_node_crypto6.createPrivateKey) {
|
|
4029
|
+
throw new Error("createPrivateKey is not supported in this environment");
|
|
4030
|
+
}
|
|
4031
|
+
if (filename.substring(0, 1) !== "." && !import_node_fs2.default.existsSync(filename)) {
|
|
4032
|
+
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
4033
|
+
}
|
|
4034
|
+
const content = import_node_fs2.default.readFileSync(filename, "utf8");
|
|
4035
|
+
const sshKey = import_sshpk.default.parsePrivateKey(content, "auto");
|
|
4036
|
+
const key = sshKey.toString("pkcs1");
|
|
4037
|
+
const hidden = (0, import_node_crypto6.createPrivateKey)({ format: "pem", type: "pkcs1", key });
|
|
4038
|
+
return { hidden };
|
|
4039
|
+
}
|
|
4040
|
+
function readPublicRsaKey(filename) {
|
|
4041
|
+
if (filename.substring(0, 1) !== "." && !import_node_fs2.default.existsSync(filename)) {
|
|
4042
|
+
filename = import_node_path.default.join(getCertificateStore(), filename);
|
|
4043
|
+
}
|
|
4044
|
+
const content = import_node_fs2.default.readFileSync(filename, "utf-8");
|
|
4045
|
+
const sshKey = import_sshpk.default.parseKey(content, "ssh");
|
|
4046
|
+
const key = sshKey.toString("pkcs1");
|
|
4047
|
+
return (0, import_node_crypto6.createPublicKey)({ format: "pem", type: "pkcs1", key });
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
// source_nodejs/read_certificate_revocation_list.ts
|
|
4051
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
4052
|
+
async function readCertificateRevocationList(filename) {
|
|
4053
|
+
const crl = await import_node_fs3.default.promises.readFile(filename);
|
|
4054
|
+
if (crl[0] === 48 && crl[1] === 130) {
|
|
4055
|
+
return crl;
|
|
4056
|
+
}
|
|
4057
|
+
const raw_crl = crl.toString();
|
|
4058
|
+
return convertPEMtoDER(raw_crl);
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
// source_nodejs/read_certificate_signing_request.ts
|
|
4062
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
4063
|
+
async function readCertificateSigningRequest(filename) {
|
|
4064
|
+
const csr = await import_node_fs4.default.promises.readFile(filename);
|
|
4065
|
+
if (csr[0] === 48 && csr[1] === 130) {
|
|
4066
|
+
return csr;
|
|
4067
|
+
}
|
|
4068
|
+
const raw_crl = csr.toString();
|
|
4069
|
+
return convertPEMtoDER(raw_crl);
|
|
4064
4070
|
}
|
|
4065
4071
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4066
4072
|
0 && (module.exports = {
|