node-opcua-crypto 5.3.0 → 5.3.2

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/source_nodejs/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,u4CAAC","file":"/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/source_nodejs/index.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/source_nodejs/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,q+DAAC","file":"/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/source_nodejs/index.cjs"}
@@ -11,13 +11,40 @@ declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLengt
11
11
  declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
12
12
 
13
13
  /**
14
- * read a DER or PEM certificate from file
14
+ * Read a DER or PEM certificate from file.
15
+ *
16
+ * **Note:** If the PEM file contains multiple certificate blocks
17
+ * (e.g. a leaf cert + CA chain), only the **first** certificate
18
+ * is returned. Use {@link readCertificateChain} to read all
19
+ * certificates individually.
20
+ *
21
+ * @deprecated Use {@link readCertificateChain} instead, which
22
+ * returns each certificate as a separate DER buffer.
15
23
  */
16
24
  declare function readCertificate(filename: string): Certificate;
25
+ /**
26
+ * Read a PEM or DER certificate file that may contain multiple
27
+ * certificates (e.g. a leaf cert + CA issuer chain) and return
28
+ * each certificate as a separate DER `Buffer`.
29
+ *
30
+ * - For a DER file, returns a single-element array.
31
+ * - For a PEM file with N certificate blocks, returns N elements
32
+ * in the same order they appear in the file (leaf first).
33
+ */
34
+ declare function readCertificateChain(filename: string): Certificate[];
35
+ /**
36
+ * Async version of {@link readCertificateChain}.
37
+ */
38
+ declare function readCertificateChainAsync(filename: string): Promise<Certificate[]>;
17
39
  /**
18
40
  * Async version of {@link readCertificate}.
19
41
  * Uses `fs.promises.readFile` so the event loop is not blocked
20
42
  * during I/O.
43
+ *
44
+ * **Note:** If the PEM file contains multiple certificate blocks,
45
+ * only the first is returned. Use {@link readCertificateChainAsync}.
46
+ *
47
+ * @deprecated Use {@link readCertificateChainAsync} instead.
21
48
  */
22
49
  declare function readCertificateAsync(filename: string): Promise<Certificate>;
23
50
  /**
@@ -70,4 +97,42 @@ declare function readCertificateRevocationList(filename: string): Promise<Certif
70
97
  type CertificateSigningRequest = Buffer;
71
98
  declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
72
99
 
73
- export { type CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificateAsync, readCertificatePEM, readCertificatePEMAsync, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyAsync, readPrivateKeyPEM, readPrivateKeyPEMAsync, readPrivateRsaKey, readPublicKey, readPublicKeyAsync, readPublicKeyPEM, readPublicKeyPEMAsync, readPublicRsaKey, setCertificateStore };
100
+ /**
101
+ * Convert one or more DER certificates to a PEM string.
102
+ *
103
+ * Accepts a single `Certificate` (DER buffer) or an array.
104
+ * Returns a multi-block PEM string with each certificate
105
+ * separated by a newline.
106
+ */
107
+ declare function certificatesToPem(certificates: Certificate | Certificate[]): string;
108
+ /**
109
+ * Write one or more DER certificates to a PEM file.
110
+ *
111
+ * Each certificate is written as a separate PEM block in the
112
+ * order provided (typically leaf first, then issuer chain).
113
+ */
114
+ declare function writeCertificateChain(filename: string, certificates: Certificate | Certificate[]): void;
115
+ /**
116
+ * Async version of {@link writeCertificateChain}.
117
+ */
118
+ declare function writeCertificateChainAsync(filename: string, certificates: Certificate | Certificate[]): Promise<void>;
119
+ /**
120
+ * Convert one or more DER certificates to a single concatenated
121
+ * DER buffer (OPC UA certificate chain format).
122
+ *
123
+ * Accepts a single `Certificate` (DER buffer) or an array.
124
+ */
125
+ declare function certificatesToDer(certificates: Certificate | Certificate[]): Certificate;
126
+ /**
127
+ * Write one or more DER certificates to a `.der` file as a
128
+ * concatenated DER chain (OPC UA binary chain format).
129
+ *
130
+ * Order should be leaf first, then issuer chain.
131
+ */
132
+ declare function writeCertificateChainDer(filename: string, certificates: Certificate | Certificate[]): void;
133
+ /**
134
+ * Async version of {@link writeCertificateChainDer}.
135
+ */
136
+ declare function writeCertificateChainDerAsync(filename: string, certificates: Certificate | Certificate[]): Promise<void>;
137
+
138
+ export { type CertificateSigningRequest, certificatesToDer, certificatesToPem, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificateAsync, readCertificateChain, readCertificateChainAsync, readCertificatePEM, readCertificatePEMAsync, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyAsync, readPrivateKeyPEM, readPrivateKeyPEMAsync, readPrivateRsaKey, readPublicKey, readPublicKeyAsync, readPublicKeyPEM, readPublicKeyPEMAsync, readPublicRsaKey, setCertificateStore, writeCertificateChain, writeCertificateChainAsync, writeCertificateChainDer, writeCertificateChainDerAsync };
@@ -11,13 +11,40 @@ declare function generatePrivateKeyFile(privateKeyFilename: string, modulusLengt
11
11
  declare function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096): Promise<void>;
12
12
 
13
13
  /**
14
- * read a DER or PEM certificate from file
14
+ * Read a DER or PEM certificate from file.
15
+ *
16
+ * **Note:** If the PEM file contains multiple certificate blocks
17
+ * (e.g. a leaf cert + CA chain), only the **first** certificate
18
+ * is returned. Use {@link readCertificateChain} to read all
19
+ * certificates individually.
20
+ *
21
+ * @deprecated Use {@link readCertificateChain} instead, which
22
+ * returns each certificate as a separate DER buffer.
15
23
  */
16
24
  declare function readCertificate(filename: string): Certificate;
25
+ /**
26
+ * Read a PEM or DER certificate file that may contain multiple
27
+ * certificates (e.g. a leaf cert + CA issuer chain) and return
28
+ * each certificate as a separate DER `Buffer`.
29
+ *
30
+ * - For a DER file, returns a single-element array.
31
+ * - For a PEM file with N certificate blocks, returns N elements
32
+ * in the same order they appear in the file (leaf first).
33
+ */
34
+ declare function readCertificateChain(filename: string): Certificate[];
35
+ /**
36
+ * Async version of {@link readCertificateChain}.
37
+ */
38
+ declare function readCertificateChainAsync(filename: string): Promise<Certificate[]>;
17
39
  /**
18
40
  * Async version of {@link readCertificate}.
19
41
  * Uses `fs.promises.readFile` so the event loop is not blocked
20
42
  * during I/O.
43
+ *
44
+ * **Note:** If the PEM file contains multiple certificate blocks,
45
+ * only the first is returned. Use {@link readCertificateChainAsync}.
46
+ *
47
+ * @deprecated Use {@link readCertificateChainAsync} instead.
21
48
  */
22
49
  declare function readCertificateAsync(filename: string): Promise<Certificate>;
23
50
  /**
@@ -70,4 +97,42 @@ declare function readCertificateRevocationList(filename: string): Promise<Certif
70
97
  type CertificateSigningRequest = Buffer;
71
98
  declare function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest>;
72
99
 
73
- export { type CertificateSigningRequest, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificateAsync, readCertificatePEM, readCertificatePEMAsync, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyAsync, readPrivateKeyPEM, readPrivateKeyPEMAsync, readPrivateRsaKey, readPublicKey, readPublicKeyAsync, readPublicKeyPEM, readPublicKeyPEMAsync, readPublicRsaKey, setCertificateStore };
100
+ /**
101
+ * Convert one or more DER certificates to a PEM string.
102
+ *
103
+ * Accepts a single `Certificate` (DER buffer) or an array.
104
+ * Returns a multi-block PEM string with each certificate
105
+ * separated by a newline.
106
+ */
107
+ declare function certificatesToPem(certificates: Certificate | Certificate[]): string;
108
+ /**
109
+ * Write one or more DER certificates to a PEM file.
110
+ *
111
+ * Each certificate is written as a separate PEM block in the
112
+ * order provided (typically leaf first, then issuer chain).
113
+ */
114
+ declare function writeCertificateChain(filename: string, certificates: Certificate | Certificate[]): void;
115
+ /**
116
+ * Async version of {@link writeCertificateChain}.
117
+ */
118
+ declare function writeCertificateChainAsync(filename: string, certificates: Certificate | Certificate[]): Promise<void>;
119
+ /**
120
+ * Convert one or more DER certificates to a single concatenated
121
+ * DER buffer (OPC UA certificate chain format).
122
+ *
123
+ * Accepts a single `Certificate` (DER buffer) or an array.
124
+ */
125
+ declare function certificatesToDer(certificates: Certificate | Certificate[]): Certificate;
126
+ /**
127
+ * Write one or more DER certificates to a `.der` file as a
128
+ * concatenated DER chain (OPC UA binary chain format).
129
+ *
130
+ * Order should be leaf first, then issuer chain.
131
+ */
132
+ declare function writeCertificateChainDer(filename: string, certificates: Certificate | Certificate[]): void;
133
+ /**
134
+ * Async version of {@link writeCertificateChainDer}.
135
+ */
136
+ declare function writeCertificateChainDerAsync(filename: string, certificates: Certificate | Certificate[]): Promise<void>;
137
+
138
+ export { type CertificateSigningRequest, certificatesToDer, certificatesToPem, generatePrivateKeyFile, generatePrivateKeyFileAlternate, getCertificateStore, readCertificate, readCertificateAsync, readCertificateChain, readCertificateChainAsync, readCertificatePEM, readCertificatePEMAsync, readCertificateRevocationList, readCertificateSigningRequest, readPrivateKey, readPrivateKeyAsync, readPrivateKeyPEM, readPrivateKeyPEMAsync, readPrivateRsaKey, readPublicKey, readPublicKeyAsync, readPublicKeyPEM, readPublicKeyPEMAsync, readPublicRsaKey, setCertificateStore, writeCertificateChain, writeCertificateChainAsync, writeCertificateChainDer, writeCertificateChainDerAsync };
@@ -1,9 +1,13 @@
1
1
  import {
2
+ certificatesToDer,
3
+ certificatesToPem,
2
4
  generatePrivateKeyFile,
3
5
  generatePrivateKeyFileAlternate,
4
6
  getCertificateStore,
5
7
  readCertificate,
6
8
  readCertificateAsync,
9
+ readCertificateChain,
10
+ readCertificateChainAsync,
7
11
  readCertificatePEM,
8
12
  readCertificatePEMAsync,
9
13
  readCertificateRevocationList,
@@ -18,15 +22,23 @@ import {
18
22
  readPublicKeyPEM,
19
23
  readPublicKeyPEMAsync,
20
24
  readPublicRsaKey,
21
- setCertificateStore
22
- } from "../chunk-QGNXSXUU.js";
23
- import "../chunk-KCVNMSLI.js";
25
+ setCertificateStore,
26
+ writeCertificateChain,
27
+ writeCertificateChainAsync,
28
+ writeCertificateChainDer,
29
+ writeCertificateChainDerAsync
30
+ } from "../chunk-UEEZA3YS.js";
31
+ import "../chunk-ODR4HUB7.js";
24
32
  export {
33
+ certificatesToDer,
34
+ certificatesToPem,
25
35
  generatePrivateKeyFile,
26
36
  generatePrivateKeyFileAlternate,
27
37
  getCertificateStore,
28
38
  readCertificate,
29
39
  readCertificateAsync,
40
+ readCertificateChain,
41
+ readCertificateChainAsync,
30
42
  readCertificatePEM,
31
43
  readCertificatePEMAsync,
32
44
  readCertificateRevocationList,
@@ -41,6 +53,10 @@ export {
41
53
  readPublicKeyPEM,
42
54
  readPublicKeyPEMAsync,
43
55
  readPublicRsaKey,
44
- setCertificateStore
56
+ setCertificateStore,
57
+ writeCertificateChain,
58
+ writeCertificateChainAsync,
59
+ writeCertificateChainDer,
60
+ writeCertificateChainDerAsync
45
61
  };
46
62
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-crypto",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "type": "module",
5
5
  "description": "Crypto tools for Node-OPCUA",
6
6
  "types": "./dist/index.d.ts",
@@ -57,7 +57,7 @@
57
57
  "node": ">=18.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@types/node": "^24.10.1",
60
+ "@types/node": "^24.12.0",
61
61
  "@types/sshpk": "^1.17.4",
62
62
  "assert": "^2.1.0",
63
63
  "buffer": "^6.0.3",
@@ -65,13 +65,13 @@
65
65
  "crypto-browserify": "^3.12.1",
66
66
  "events": "^3.3.0",
67
67
  "stream-browserify": "^3.0.0",
68
- "string_decoder": "^1.1.1",
68
+ "string_decoder": "^1.3.0",
69
69
  "util": "^0.12.5",
70
70
  "vm-browserify": "^1.1.2"
71
71
  },
72
72
  "dependencies": {
73
73
  "@peculiar/webcrypto": "^1.5.0",
74
- "@peculiar/x509": "^1.14.2",
74
+ "@peculiar/x509": "^2.0.0",
75
75
  "sshpk": "^1.18.0"
76
76
  },
77
77
  "repository": {
@@ -86,5 +86,5 @@
86
86
  "LICENSE",
87
87
  "README.md"
88
88
  ],
89
- "gitHead": "8660de787a060bca52573588214fd7f715e637a4"
89
+ "gitHead": "ddf7780fd57e6babfd9df320c8d50a8d2f9a8a6a"
90
90
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/chunk-7GWSCCWS.cjs","../source_nodejs/generate_private_key_filename.ts","../source_nodejs/read.ts","../source_nodejs/read_certificate_revocation_list.ts","../source_nodejs/read_certificate_signing_request.ts"],"names":["fs"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACcA,gCAAoC;AACpC,gEAAe;AAEf,MAAA,SAAsB,sBAAA,CAAuB,kBAAA,EAA4B,aAAA,EA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ChC;AAMsB;AACY,EAAA;AACH,EAAA;AAC/B;AAEmC;AAEC;AACd,EAAA;AACK,EAAA;AAChB,EAAA;AACX;AAC8C;AACf,EAAA;AACK,IAAA;AAChC,EAAA;AACO,EAAA;AACX;AAKkC;AACP,EAAA;AACH,IAAA;AACpB,EAAA;AACiC,EAAA;AACR,IAAA;AACzB,EAAA;AACgC,EAAA;AACX,EAAA;AACO,EAAA;AACI,EAAA;AAChB,EAAA;AACpB;AAEiC;AACI,EAAA;AACR,IAAA;AACzB,EAAA;AACgC,EAAA;AACF,EAAA;AACF,EAAA;AACK,EAAA;AACrC;AF/DmC;AACA;AG5IpB;AAIO;AACY,EAAA;AACI,EAAA;AAEvB,IAAA;AACX,EAAA;AAC6B,EAAA;AACC,EAAA;AAClC;AH0ImC;AACA;AIvJpB;AAMO;AACY,EAAA;AACI,EAAA;AAEvB,IAAA;AACX,EAAA;AAC6B,EAAA;AACC,EAAA;AAClC;AJmJmC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/node-opcua-crypto/node-opcua-crypto/packages/node-opcua-crypto/dist/chunk-7GWSCCWS.cjs","sourcesContent":[null,"// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport { generateKeyPairSync } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { generateKeyPair, privateKeyToPEM } from \"../source/index.js\";\nexport async function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096) {\n const keys = await generateKeyPair(modulusLength);\n const privateKeyPem = await privateKeyToPEM(keys.privateKey);\n await fs.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, \"utf-8\");\n privateKeyPem.privPem = \"\";\n privateKeyPem.privDer = new ArrayBuffer(0);\n}\n\n/**\n * alternate function to generate PrivateKeyFile, using native\n * node:crypto.\n *\n * This function is slower than generatePrivateKeyFile\n */\nexport async function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096) {\n const { privateKey } = generateKeyPairSync(\"rsa\", {\n modulusLength,\n privateKeyEncoding: { type: \"pkcs8\", format: \"pem\" },\n publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n });\n await fs.promises.writeFile(privateKeyFilename, privateKey, \"utf-8\");\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport assert from \"node:assert\";\nimport { createPrivateKey, createPublicKey } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport sshpk from \"sshpk\";\nimport type {\n Certificate,\n CertificatePEM,\n DER,\n KeyObject,\n PEM,\n PrivateKey,\n PrivateKeyPEM,\n PublicKey,\n PublicKeyPEM,\n} from \"../source/common.js\";\nimport { convertPEMtoDER, identifyPemType, removeTrailingLF, toPem } from \"../source/crypto_utils.js\";\n\nfunction _readPemFile(filename: string): PEM {\n assert(typeof filename === \"string\");\n return removeTrailingLF(fs.readFileSync(filename, \"utf-8\"));\n}\n\nfunction _readPemOrDerFileAsDER(filename: string): DER {\n if (filename.match(/.*\\.der/)) {\n return fs.readFileSync(filename) as Buffer;\n }\n const raw_key: string = _readPemFile(filename);\n return convertPEMtoDER(raw_key);\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readCertificate(filename: string): Certificate {\n return _readPemOrDerFileAsDER(filename) as Certificate;\n}\n\n/**\n * Async version of {@link readCertificate}.\n * Uses `fs.promises.readFile` so the event loop is not blocked\n * during I/O.\n */\nexport async function readCertificateAsync(filename: string): Promise<Certificate> {\n const buf = await fs.promises.readFile(filename);\n if (filename.match(/.*\\.der/)) {\n return buf as Certificate;\n }\n const raw_key = removeTrailingLF(buf.toString(\"utf-8\"));\n return convertPEMtoDER(raw_key) as Certificate;\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPublicKey(filename: string): KeyObject {\n if (filename.match(/.*\\.der/)) {\n const der = fs.readFileSync(filename) as Buffer;\n return createPublicKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return createPublicKey(raw_key);\n }\n}\n\n/**\n * Async version of {@link readPublicKey}.\n */\nexport async function readPublicKeyAsync(filename: string): Promise<KeyObject> {\n const buf = await fs.promises.readFile(filename);\n if (filename.match(/.*\\.der/)) {\n return createPublicKey(buf);\n }\n return createPublicKey(removeTrailingLF(buf.toString(\"utf-8\")));\n}\n\n// console.log(\"createPrivateKey\", (crypto as any).createPrivateKey, process.env.NO_CREATE_PRIVATEKEY);\n\nfunction myCreatePrivateKey(rawKey: string | Buffer): PrivateKey {\n if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {\n // we are not running nodejs or createPrivateKey is not supported in the environment\n if (Buffer.isBuffer(rawKey)) {\n const pemKey = toPem(rawKey, \"PRIVATE KEY\");\n assert([\"RSA PRIVATE KEY\", \"PRIVATE KEY\"].indexOf(identifyPemType(pemKey) as string) >= 0);\n return { hidden: pemKey };\n }\n return { hidden: ensureTrailingLF(rawKey as string) };\n }\n // see https://askubuntu.com/questions/1409458/openssl-config-cuases-error-in-node-js-crypto-how-should-the-config-be-updated\n const backup = process.env.OPENSSL_CONF;\n process.env.OPENSSL_CONF = \"/dev/null\";\n const retValue = createPrivateKey(rawKey);\n process.env.OPENSSL_CONF = backup;\n return { hidden: retValue };\n}\n\nfunction ensureTrailingLF(str: string): string {\n return str.match(/\\n$/) ? str : `${str}\\n`;\n}\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPrivateKey(filename: string): PrivateKey {\n if (filename.match(/.*\\.der/)) {\n const der: Buffer = fs.readFileSync(filename);\n return myCreatePrivateKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return myCreatePrivateKey(raw_key);\n }\n}\n\n/**\n * Async version of {@link readPrivateKey}.\n */\nexport async function readPrivateKeyAsync(filename: string): Promise<PrivateKey> {\n const buf = await fs.promises.readFile(filename);\n if (filename.match(/.*\\.der/)) {\n return myCreatePrivateKey(buf);\n }\n return myCreatePrivateKey(removeTrailingLF(buf.toString(\"utf-8\")));\n}\n\nexport function readCertificatePEM(filename: string): CertificatePEM {\n return _readPemFile(filename);\n}\n\n/**\n * Async version of {@link readCertificatePEM}.\n */\nexport async function readCertificatePEMAsync(filename: string): Promise<CertificatePEM> {\n const buf = await fs.promises.readFile(filename, \"utf-8\");\n return removeTrailingLF(buf);\n}\n\nexport function readPublicKeyPEM(filename: string): PublicKeyPEM {\n return _readPemFile(filename);\n}\n\n/**\n * Async version of {@link readPublicKeyPEM}.\n */\nexport async function readPublicKeyPEMAsync(filename: string): Promise<PublicKeyPEM> {\n const buf = await fs.promises.readFile(filename, \"utf-8\");\n return removeTrailingLF(buf);\n}\n/**\n *\n * @deprecated\n */\nexport function readPrivateKeyPEM(filename: string): PrivateKeyPEM {\n return _readPemFile(filename);\n}\n\n/**\n * Async version of {@link readPrivateKeyPEM}.\n * @deprecated\n */\nexport async function readPrivateKeyPEMAsync(filename: string): Promise<PrivateKeyPEM> {\n const buf = await fs.promises.readFile(filename, \"utf-8\");\n return removeTrailingLF(buf);\n}\n\nlet _g_certificate_store: string = \"\";\n\nexport function setCertificateStore(store: string): string {\n const old_store = _g_certificate_store;\n _g_certificate_store = store;\n return old_store;\n}\nexport function getCertificateStore(): string {\n if (!_g_certificate_store) {\n _g_certificate_store = path.join(__dirname, \"../../certificates/\");\n }\n return _g_certificate_store;\n}\n/**\n *\n * @param filename\n */\nexport function readPrivateRsaKey(filename: string): PrivateKey {\n if (!createPrivateKey) {\n throw new Error(\"createPrivateKey is not supported in this environment\");\n }\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf8\");\n const sshKey = sshpk.parsePrivateKey(content, \"auto\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n const hidden = createPrivateKey({ format: \"pem\", type: \"pkcs1\", key });\n return { hidden };\n}\n\nexport function readPublicRsaKey(filename: string): PublicKey {\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf-8\");\n const sshKey = sshpk.parseKey(content, \"ssh\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n return createPublicKey({ format: \"pem\", type: \"pkcs1\", key });\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport type { CertificateRevocationList } from \"../source/common.js\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\n\nexport async function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList> {\n const crl = await fs.promises.readFile(filename);\n if (crl[0] === 0x30 && crl[1] === 0x82) {\n // der format\n return crl as CertificateRevocationList;\n }\n const raw_crl = crl.toString();\n return convertPEMtoDER(raw_crl);\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2026 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport type { CertificateRevocationList } from \"../source/common.js\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\n\nexport type CertificateSigningRequest = Buffer;\n\nexport async function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest> {\n const csr = await fs.promises.readFile(filename);\n if (csr[0] === 0x30 && csr[1] === 0x82) {\n // der format\n return csr as CertificateRevocationList;\n }\n const raw_crl = csr.toString();\n return convertPEMtoDER(raw_crl);\n}\n"]}