node-opcua-crypto 4.1.0 → 4.3.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 +1 -1
- package/README.md +1 -1
- package/dist/chunk-5NV4OKIV.mjs +1 -0
- package/dist/chunk-KPKFYTZJ.mjs +173 -0
- package/dist/chunk-QSSIRHMR.mjs +6243 -0
- package/dist/index.js +6521 -0
- package/dist/index.mjs +224 -0
- package/dist/source/index.js +6346 -0
- package/dist/source/index.mjs +192 -0
- package/dist/source/index_web.js +6346 -0
- package/dist/source/index_web.mjs +191 -0
- package/dist/source_nodejs/index.js +4170 -0
- package/dist/source_nodejs/index.mjs +37 -0
- package/dist-types/index.d.ts +2 -0
- package/dist-types/source/common.d.ts +21 -1
- package/dist-types/source/crypto_utils2.d.ts +2 -3
- package/dist-types/source/make_private_key_from_pem.d.ts +1 -1
- package/dist-types/source/x509/_crypto.d.ts +2 -2
- package/dist-types/source/x509/coerce_private_key.d.ts +5 -3
- package/dist-types/source/x509/create_key_pair.d.ts +6 -0
- package/dist-types/source/x509/create_self_signed_certificate.d.ts +4 -0
- package/dist-types/source_nodejs/generate_private_key_filename.d.ts +6 -0
- package/dist-types/source_nodejs/read.d.ts +1 -0
- package/doc/.nojekyll +1 -0
- package/doc/assets/highlight.css +71 -0
- package/doc/assets/main.js +58 -0
- package/doc/assets/search.js +1 -0
- package/doc/assets/style.css +1379 -0
- package/doc/classes/Subject.html +76 -0
- package/doc/functions/combine_der.html +80 -0
- package/doc/functions/createPrivateKeyFromNodeJSCrypto.html +81 -0
- package/doc/functions/createSelfSignedCertificate.html +76 -0
- package/doc/functions/exploreCertificate.html +77 -0
- package/doc/functions/exploreCertificateInfo.html +80 -0
- package/doc/functions/explorePrivateKey.html +74 -0
- package/doc/functions/extractPublicKeyFromCertificate.html +92 -0
- package/doc/functions/generatePrivateKey.html +76 -0
- package/doc/functions/generatePrivateKeyFileAlternate.html +79 -0
- package/doc/functions/makeMessageChunkSignatureWithDerivedKeys.html +78 -0
- package/doc/functions/privateKeyToPEM.html +76 -0
- package/doc/functions/readCertificate.html +76 -0
- package/doc/functions/readPrivateKey.html +76 -0
- package/doc/functions/readPrivateKeyPEM.html +75 -0
- package/doc/functions/readPrivateRsaKey.html +74 -0
- package/doc/functions/readPublicKey.html +76 -0
- package/doc/functions/reduceLength.html +79 -0
- package/doc/functions/removePadding.html +77 -0
- package/doc/functions/rsaLengthPrivateKey.html +80 -0
- package/doc/functions/split_der.html +80 -0
- package/doc/functions/toPem2.html +80 -0
- package/doc/functions/verifyChunkSignature.html +82 -0
- package/doc/functions/verifyChunkSignatureWithDerivedKeys.html +78 -0
- package/doc/functions/verifyMessageChunkSignature.html +83 -0
- package/doc/index.html +128 -0
- package/doc/interfaces/CertificateInfo.html +135 -0
- package/doc/modules.html +96 -0
- package/node-opcua-crypto-4.2.0.tgz +0 -0
- package/package.json +84 -90
- package/dist-cjs/source/asn1.js +0 -304
- package/dist-cjs/source/asn1.js.map +0 -1
- package/dist-cjs/source/buffer_utils.js +0 -9
- package/dist-cjs/source/buffer_utils.js.map +0 -1
- package/dist-cjs/source/common.js +0 -11
- package/dist-cjs/source/common.js.map +0 -1
- package/dist-cjs/source/crypto_explore_certificate.js +0 -367
- package/dist-cjs/source/crypto_explore_certificate.js.map +0 -1
- package/dist-cjs/source/crypto_utils.js +0 -200
- package/dist-cjs/source/crypto_utils.js.map +0 -1
- package/dist-cjs/source/crypto_utils2.js +0 -71
- package/dist-cjs/source/crypto_utils2.js.map +0 -1
- package/dist-cjs/source/derived_keys.js +0 -133
- package/dist-cjs/source/derived_keys.js.map +0 -1
- package/dist-cjs/source/explore_certificate.js +0 -37
- package/dist-cjs/source/explore_certificate.js.map +0 -1
- package/dist-cjs/source/explore_certificate_revocation_list.js +0 -69
- package/dist-cjs/source/explore_certificate_revocation_list.js.map +0 -1
- package/dist-cjs/source/explore_certificate_signing_request.js +0 -45
- package/dist-cjs/source/explore_certificate_signing_request.js.map +0 -1
- package/dist-cjs/source/explore_private_key.js +0 -77
- package/dist-cjs/source/explore_private_key.js.map +0 -1
- package/dist-cjs/source/index.js +0 -38
- package/dist-cjs/source/index.js.map +0 -1
- package/dist-cjs/source/make_private_key_from_pem.js +0 -8
- package/dist-cjs/source/make_private_key_from_pem.js.map +0 -1
- package/dist-cjs/source/oid_map.js +0 -300
- package/dist-cjs/source/oid_map.js.map +0 -1
- package/dist-cjs/source/public_private_match.js +0 -32
- package/dist-cjs/source/public_private_match.js.map +0 -1
- package/dist-cjs/source/subject.js +0 -92
- package/dist-cjs/source/subject.js.map +0 -1
- package/dist-cjs/source/verify_certificate_signature.js +0 -117
- package/dist-cjs/source/verify_certificate_signature.js.map +0 -1
- package/dist-cjs/source/x509/_build_public_key.js +0 -69
- package/dist-cjs/source/x509/_build_public_key.js.map +0 -1
- package/dist-cjs/source/x509/_crypto.js +0 -50
- package/dist-cjs/source/x509/_crypto.js.map +0 -1
- package/dist-cjs/source/x509/_get_attributes.js +0 -39
- package/dist-cjs/source/x509/_get_attributes.js.map +0 -1
- package/dist-cjs/source/x509/coerce_private_key.js +0 -90
- package/dist-cjs/source/x509/coerce_private_key.js.map +0 -1
- package/dist-cjs/source/x509/create_certificate_signing_request.js +0 -92
- package/dist-cjs/source/x509/create_certificate_signing_request.js.map +0 -1
- package/dist-cjs/source/x509/create_key_pair.js +0 -123
- package/dist-cjs/source/x509/create_key_pair.js.map +0 -1
- package/dist-cjs/source/x509/create_self_signed_certificate.js +0 -102
- package/dist-cjs/source/x509/create_self_signed_certificate.js.map +0 -1
- package/dist-cjs/source_nodejs/generate_private_key_filename.js +0 -67
- package/dist-cjs/source_nodejs/generate_private_key_filename.js.map +0 -1
- package/dist-cjs/source_nodejs/index.js +0 -21
- package/dist-cjs/source_nodejs/index.js.map +0 -1
- package/dist-cjs/source_nodejs/read.js +0 -115
- package/dist-cjs/source_nodejs/read.js.map +0 -1
- package/dist-cjs/source_nodejs/read_certificate_revocation_list.js +0 -64
- package/dist-cjs/source_nodejs/read_certificate_revocation_list.js.map +0 -1
- package/dist-cjs/source_nodejs/read_certificate_signing_request.js +0 -64
- package/dist-cjs/source_nodejs/read_certificate_signing_request.js.map +0 -1
- package/dist-esm/source/asn1.js +0 -275
- package/dist-esm/source/asn1.js.map +0 -1
- package/dist-esm/source/buffer_utils.js +0 -6
- package/dist-esm/source/buffer_utils.js.map +0 -1
- package/dist-esm/source/common.js +0 -8
- package/dist-esm/source/common.js.map +0 -1
- package/dist-esm/source/crypto_explore_certificate.js +0 -356
- package/dist-esm/source/crypto_explore_certificate.js.map +0 -1
- package/dist-esm/source/crypto_utils.js +0 -179
- package/dist-esm/source/crypto_utils.js.map +0 -1
- package/dist-esm/source/crypto_utils2.js +0 -58
- package/dist-esm/source/crypto_utils2.js.map +0 -1
- package/dist-esm/source/derived_keys.js +0 -117
- package/dist-esm/source/derived_keys.js.map +0 -1
- package/dist-esm/source/explore_certificate.js +0 -29
- package/dist-esm/source/explore_certificate.js.map +0 -1
- package/dist-esm/source/explore_certificate_revocation_list.js +0 -64
- package/dist-esm/source/explore_certificate_revocation_list.js.map +0 -1
- package/dist-esm/source/explore_certificate_signing_request.js +0 -40
- package/dist-esm/source/explore_certificate_signing_request.js.map +0 -1
- package/dist-esm/source/explore_private_key.js +0 -73
- package/dist-esm/source/explore_private_key.js.map +0 -1
- package/dist-esm/source/index.js +0 -19
- package/dist-esm/source/index.js.map +0 -1
- package/dist-esm/source/make_private_key_from_pem.js +0 -4
- package/dist-esm/source/make_private_key_from_pem.js.map +0 -1
- package/dist-esm/source/oid_map.js +0 -297
- package/dist-esm/source/oid_map.js.map +0 -1
- package/dist-esm/source/public_private_match.js +0 -27
- package/dist-esm/source/public_private_match.js.map +0 -1
- package/dist-esm/source/subject.js +0 -89
- package/dist-esm/source/subject.js.map +0 -1
- package/dist-esm/source/verify_certificate_signature.js +0 -110
- package/dist-esm/source/verify_certificate_signature.js.map +0 -1
- package/dist-esm/source/x509/_build_public_key.js +0 -65
- package/dist-esm/source/x509/_build_public_key.js.map +0 -1
- package/dist-esm/source/x509/_crypto.js +0 -23
- package/dist-esm/source/x509/_crypto.js.map +0 -1
- package/dist-esm/source/x509/_get_attributes.js +0 -35
- package/dist-esm/source/x509/_get_attributes.js.map +0 -1
- package/dist-esm/source/x509/coerce_private_key.js +0 -85
- package/dist-esm/source/x509/coerce_private_key.js.map +0 -1
- package/dist-esm/source/x509/create_certificate_signing_request.js +0 -88
- package/dist-esm/source/x509/create_certificate_signing_request.js.map +0 -1
- package/dist-esm/source/x509/create_key_pair.js +0 -115
- package/dist-esm/source/x509/create_key_pair.js.map +0 -1
- package/dist-esm/source/x509/create_self_signed_certificate.js +0 -98
- package/dist-esm/source/x509/create_self_signed_certificate.js.map +0 -1
- package/dist-esm/source_nodejs/generate_private_key_filename.js +0 -60
- package/dist-esm/source_nodejs/generate_private_key_filename.js.map +0 -1
- package/dist-esm/source_nodejs/index.js +0 -5
- package/dist-esm/source_nodejs/index.js.map +0 -1
- package/dist-esm/source_nodejs/read.js +0 -99
- package/dist-esm/source_nodejs/read.js.map +0 -1
- package/dist-esm/source_nodejs/read_certificate_revocation_list.js +0 -57
- package/dist-esm/source_nodejs/read_certificate_revocation_list.js.map +0 -1
- package/dist-esm/source_nodejs/read_certificate_signing_request.js +0 -57
- package/dist-esm/source_nodejs/read_certificate_signing_request.js.map +0 -1
- package/index.d.ts +0 -2
- package/index.js +0 -4
- package/index_web.d.ts +0 -1
- package/index_web.js +0 -3
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) Etienne Rossignon 2015-2022
|
|
4
|
-
Copyright (c) Sterfive.com 2022
|
|
4
|
+
Copyright (c) Sterfive.com 2022-2023
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npm install nodeopcua-crypto
|
|
|
32
32
|
|
|
33
33
|
``` bash
|
|
34
34
|
|
|
35
|
-
import { generatePrivateKey, privateKeyToPEM, CertificatePurpose, createSelfSignedCertificate } from "node-opcua-crypto";
|
|
35
|
+
import { generatePrivateKey, privateKeyToPEM, CertificatePurpose, createSelfSignedCertificate } from "./node-opcua-crypto.js";
|
|
36
36
|
|
|
37
37
|
async function demonstratePrivateKeyAndSelfSignedCertificateCreation() {
|
|
38
38
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-5NV4OKIV.mjs.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__dirname,
|
|
3
|
+
convertPEMtoDER,
|
|
4
|
+
generateKeyPair,
|
|
5
|
+
identifyPemType,
|
|
6
|
+
privateKeyToPEM,
|
|
7
|
+
removeTrailingLF,
|
|
8
|
+
toPem
|
|
9
|
+
} from "./chunk-QSSIRHMR.mjs";
|
|
10
|
+
|
|
11
|
+
// source_nodejs/read.ts
|
|
12
|
+
import assert from "assert";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { createPrivateKey, createPublicKey } from "crypto";
|
|
16
|
+
import sshpk from "sshpk";
|
|
17
|
+
function _readPemFile(filename) {
|
|
18
|
+
assert(typeof filename === "string");
|
|
19
|
+
return removeTrailingLF(fs.readFileSync(filename, "utf-8"));
|
|
20
|
+
}
|
|
21
|
+
function _readPemOrDerFileAsDER(filename) {
|
|
22
|
+
if (filename.match(/.*\.der/)) {
|
|
23
|
+
return fs.readFileSync(filename);
|
|
24
|
+
}
|
|
25
|
+
const raw_key = _readPemFile(filename);
|
|
26
|
+
return convertPEMtoDER(raw_key);
|
|
27
|
+
}
|
|
28
|
+
function readCertificate(filename) {
|
|
29
|
+
return _readPemOrDerFileAsDER(filename);
|
|
30
|
+
}
|
|
31
|
+
function readPublicKey(filename) {
|
|
32
|
+
if (filename.match(/.*\.der/)) {
|
|
33
|
+
const der = fs.readFileSync(filename);
|
|
34
|
+
return createPublicKey(der);
|
|
35
|
+
} else {
|
|
36
|
+
const raw_key = _readPemFile(filename);
|
|
37
|
+
return createPublicKey(raw_key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function myCreatePrivateKey(rawKey) {
|
|
41
|
+
if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
|
|
42
|
+
if (rawKey instanceof Buffer) {
|
|
43
|
+
const pemKey = toPem(rawKey, "PRIVATE KEY");
|
|
44
|
+
assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
|
|
45
|
+
return { hidden: pemKey };
|
|
46
|
+
}
|
|
47
|
+
return { hidden: ensureTrailingLF(rawKey) };
|
|
48
|
+
}
|
|
49
|
+
const backup = process.env.OPENSSL_CONF;
|
|
50
|
+
process.env.OPENSSL_CONF = "/dev/null";
|
|
51
|
+
const retValue = createPrivateKey(rawKey);
|
|
52
|
+
process.env.OPENSSL_CONF = backup;
|
|
53
|
+
return { hidden: retValue };
|
|
54
|
+
}
|
|
55
|
+
function makePrivateKeyThumbPrint(privateKey) {
|
|
56
|
+
return Buffer.alloc(0);
|
|
57
|
+
}
|
|
58
|
+
function ensureTrailingLF(str) {
|
|
59
|
+
return str.match(/\n$/) ? str : str + "\n";
|
|
60
|
+
}
|
|
61
|
+
function readPrivateKey(filename) {
|
|
62
|
+
if (filename.match(/.*\.der/)) {
|
|
63
|
+
const der = fs.readFileSync(filename);
|
|
64
|
+
return myCreatePrivateKey(der);
|
|
65
|
+
} else {
|
|
66
|
+
const raw_key = _readPemFile(filename);
|
|
67
|
+
return myCreatePrivateKey(raw_key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function readCertificatePEM(filename) {
|
|
71
|
+
return _readPemFile(filename);
|
|
72
|
+
}
|
|
73
|
+
function readPublicKeyPEM(filename) {
|
|
74
|
+
return _readPemFile(filename);
|
|
75
|
+
}
|
|
76
|
+
function readPrivateKeyPEM(filename) {
|
|
77
|
+
return _readPemFile(filename);
|
|
78
|
+
}
|
|
79
|
+
var _g_certificate_store = "";
|
|
80
|
+
function setCertificateStore(store) {
|
|
81
|
+
const old_store = _g_certificate_store;
|
|
82
|
+
_g_certificate_store = store;
|
|
83
|
+
return old_store;
|
|
84
|
+
}
|
|
85
|
+
function getCertificateStore() {
|
|
86
|
+
if (!_g_certificate_store) {
|
|
87
|
+
_g_certificate_store = path.join(__dirname, "../../certificates/");
|
|
88
|
+
}
|
|
89
|
+
return _g_certificate_store;
|
|
90
|
+
}
|
|
91
|
+
function readPrivateRsaKey(filename) {
|
|
92
|
+
if (!createPrivateKey) {
|
|
93
|
+
throw new Error("createPrivateKey is not supported in this environment");
|
|
94
|
+
}
|
|
95
|
+
if (filename.substring(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
96
|
+
filename = path.join(getCertificateStore(), filename);
|
|
97
|
+
}
|
|
98
|
+
const content = fs.readFileSync(filename, "utf8");
|
|
99
|
+
const sshKey = sshpk.parsePrivateKey(content, "auto");
|
|
100
|
+
const key = sshKey.toString("pkcs1");
|
|
101
|
+
const hidden = createPrivateKey({ format: "pem", type: "pkcs1", key });
|
|
102
|
+
return { hidden };
|
|
103
|
+
}
|
|
104
|
+
function readPublicRsaKey(filename) {
|
|
105
|
+
if (filename.substring(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
106
|
+
filename = path.join(getCertificateStore(), filename);
|
|
107
|
+
}
|
|
108
|
+
const content = fs.readFileSync(filename, "utf-8");
|
|
109
|
+
const sshKey = sshpk.parseKey(content, "ssh");
|
|
110
|
+
const key = sshKey.toString("pkcs1");
|
|
111
|
+
return createPublicKey({ format: "pem", type: "pkcs1", key });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// source_nodejs/read_certificate_revocation_list.ts
|
|
115
|
+
import fs2 from "fs";
|
|
116
|
+
import { promisify } from "util";
|
|
117
|
+
async function readCertificateRevocationList(filename) {
|
|
118
|
+
const crl = await promisify(fs2.readFile)(filename);
|
|
119
|
+
if (crl[0] === 48 && crl[1] === 130) {
|
|
120
|
+
return crl;
|
|
121
|
+
}
|
|
122
|
+
const raw_crl = crl.toString();
|
|
123
|
+
return convertPEMtoDER(raw_crl);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// source_nodejs/read_certificate_signing_request.ts
|
|
127
|
+
import fs3 from "fs";
|
|
128
|
+
import { promisify as promisify2 } from "util";
|
|
129
|
+
async function readCertificateSigningRequest(filename) {
|
|
130
|
+
const csr = await promisify2(fs3.readFile)(filename);
|
|
131
|
+
if (csr[0] === 48 && csr[1] === 130) {
|
|
132
|
+
return csr;
|
|
133
|
+
}
|
|
134
|
+
const raw_crl = csr.toString();
|
|
135
|
+
return convertPEMtoDER(raw_crl);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// source_nodejs/generate_private_key_filename.ts
|
|
139
|
+
import fs4 from "fs";
|
|
140
|
+
import jsrsasign from "jsrsasign";
|
|
141
|
+
async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
|
|
142
|
+
const keys = await generateKeyPair(modulusLength);
|
|
143
|
+
const privateKeyPem = await privateKeyToPEM(keys.privateKey);
|
|
144
|
+
await fs4.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
|
|
145
|
+
privateKeyPem.privPem = "";
|
|
146
|
+
privateKeyPem.privDer = new Uint8Array(0);
|
|
147
|
+
}
|
|
148
|
+
async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
|
|
149
|
+
const kp = jsrsasign.KEYUTIL.generateKeypair("RSA", modulusLength);
|
|
150
|
+
const prv = kp.prvKeyObj;
|
|
151
|
+
const pub = kp.pubKeyObj;
|
|
152
|
+
const prvpem = jsrsasign.KEYUTIL.getPEM(prv, "PKCS8PRV");
|
|
153
|
+
await fs4.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
readCertificate,
|
|
158
|
+
readPublicKey,
|
|
159
|
+
makePrivateKeyThumbPrint,
|
|
160
|
+
readPrivateKey,
|
|
161
|
+
readCertificatePEM,
|
|
162
|
+
readPublicKeyPEM,
|
|
163
|
+
readPrivateKeyPEM,
|
|
164
|
+
setCertificateStore,
|
|
165
|
+
getCertificateStore,
|
|
166
|
+
readPrivateRsaKey,
|
|
167
|
+
readPublicRsaKey,
|
|
168
|
+
readCertificateRevocationList,
|
|
169
|
+
readCertificateSigningRequest,
|
|
170
|
+
generatePrivateKeyFile,
|
|
171
|
+
generatePrivateKeyFileAlternate
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=chunk-KPKFYTZJ.mjs.map
|