node-opcua-crypto 1.12.0 → 2.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/dist/source/asn1.d.ts +1 -1
- package/dist/source/buffer_utils.d.ts +1 -0
- package/dist/source/certificate_matches_private_key.d.ts +2 -0
- package/dist/source/certificate_matches_private_key.js +22 -0
- package/dist/source/certificate_matches_private_key.js.map +1 -0
- package/dist/source/common.d.ts +11 -11
- package/dist/source/crypto_utils.d.ts +8 -6
- package/dist/source/crypto_utils.js +51 -19
- package/dist/source/crypto_utils.js.map +1 -1
- package/dist/source/derived_keys.d.ts +1 -1
- package/dist/source/explore_certificate.d.ts +1 -1
- package/dist/source/explore_certificate_revocation_list.d.ts +4 -4
- package/dist/source/explore_private_key.js +5 -5
- package/dist/source/explore_private_key.js.map +1 -1
- package/dist/source/public_private_match.d.ts +2 -2
- package/dist/source/public_private_match.js +24 -3
- package/dist/source/public_private_match.js.map +1 -1
- package/dist/source/verify_certificate_signature.d.ts +1 -1
- package/dist/source_nodejs/read.js +2 -2
- package/dist/source_nodejs/read.js.map +1 -1
- package/dist/source_nodejs/read_certificate_signing_request.d.ts +1 -1
- package/package.json +10 -10
- package/source/crypto_utils.ts +57 -19
- package/source/explore_private_key.ts +5 -5
- package/source/public_private_match.ts +27 -4
- package/source_nodejs/read.ts +2 -2
package/dist/source/asn1.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function _readObjectIdentifier(buffer: Buffer, block: BlockInfo):
|
|
|
51
51
|
};
|
|
52
52
|
export declare function _readAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
|
|
53
53
|
export declare function _readECCAlgorithmIdentifier(buffer: Buffer, block: BlockInfo): AlgorithmIdentifier;
|
|
54
|
-
export
|
|
54
|
+
export type SignatureValue = string;
|
|
55
55
|
export declare function _readSignatureValueBin(buffer: Buffer, block: BlockInfo): Buffer;
|
|
56
56
|
export declare function _readSignatureValue(buffer: Buffer, block: BlockInfo): SignatureValue;
|
|
57
57
|
export declare function _readLongIntegerValue(buffer: Buffer, block: BlockInfo): Buffer;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.certificateMatchesPrivateKey = void 0;
|
|
4
|
+
const crypto_utils_1 = require("./crypto_utils");
|
|
5
|
+
/**
|
|
6
|
+
* check that the given certificate matches the given private key
|
|
7
|
+
* @param certificate
|
|
8
|
+
* @param privateKey
|
|
9
|
+
*/
|
|
10
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey) {
|
|
11
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
12
|
+
const encryptedBuffer = (0, crypto_utils_1.publicEncrypt_long)(initialBuffer, certificate, 256, 11);
|
|
13
|
+
const decryptedBuffer = (0, crypto_utils_1.privateDecrypt_long)(encryptedBuffer, privateKey, 256);
|
|
14
|
+
return initialBuffer.toString("utf-8") === decryptedBuffer.toString("utf-8");
|
|
15
|
+
}
|
|
16
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
17
|
+
const certificatePEM = (0, crypto_utils_1.toPem)(certificate, "CERTIFICATE");
|
|
18
|
+
const privateKeyPEM = (0, crypto_utils_1.toPem)(privateKey, "RSA PRIVATE KEY");
|
|
19
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKeyPEM);
|
|
20
|
+
}
|
|
21
|
+
exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
|
|
22
|
+
//# sourceMappingURL=certificate_matches_private_key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate_matches_private_key.js","sourceRoot":"","sources":["../../source/certificate_matches_private_key.ts"],"names":[],"mappings":";;;AACA,iDAAgF;AAEhF;;;;GAIG;AACH,SAAS,+BAA+B,CAAC,WAA2B,EAAE,UAAyB;IAC3F,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,IAAA,iCAAkB,EAAC,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,IAAA,kCAAmB,EAAC,eAAe,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC9E,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,4BAA4B,CAAC,WAAwB,EAAE,UAAsB;IACzF,MAAM,cAAc,GAAG,IAAA,oBAAK,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,OAAO,+BAA+B,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAC1E,CAAC;AAJD,oEAIC"}
|
package/dist/source/common.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
2
|
+
export type Nonce = Buffer;
|
|
3
|
+
export type PEM = string;
|
|
4
|
+
export type DER = Buffer;
|
|
5
|
+
export type Certificate = DER;
|
|
6
|
+
export type CertificatePEM = PEM;
|
|
7
|
+
export type PrivateKey = DER;
|
|
8
|
+
export type PrivateKeyPEM = PEM;
|
|
9
|
+
export type PublicKey = DER;
|
|
10
|
+
export type PublicKeyPEM = PEM;
|
|
11
|
+
export type Signature = Buffer;
|
|
12
|
+
export type CertificateRevocationList = Buffer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Certificate, CertificatePEM, DER, PEM, PrivateKeyPEM, PublicKey, PublicKeyPEM, Signature } from "./common";
|
|
2
|
+
import { Certificate, CertificatePEM, DER, PEM, PrivateKey, PrivateKeyPEM, PublicKey, PublicKeyPEM, Signature } from "./common";
|
|
3
3
|
export declare function identifyPemType(rawKey: Buffer | string): undefined | string;
|
|
4
4
|
export declare function convertPEMtoDER(raw_key: PEM): DER;
|
|
5
5
|
/**
|
|
@@ -58,17 +58,19 @@ export declare function publicEncrypt_native(buffer: Buffer, publicKey: PublicKe
|
|
|
58
58
|
export declare function privateDecrypt_native(buffer: Buffer, privateKey: PrivateKeyPEM, algorithm?: PaddingAlgorithm): Buffer;
|
|
59
59
|
export declare const publicEncrypt: typeof publicEncrypt_native;
|
|
60
60
|
export declare const privateDecrypt: typeof privateDecrypt_native;
|
|
61
|
-
export declare function publicEncrypt_long(buffer: Buffer, publicKey: PublicKeyPEM, blockSize: number, padding: number,
|
|
62
|
-
export declare function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKeyPEM, blockSize: number,
|
|
61
|
+
export declare function publicEncrypt_long(buffer: Buffer, publicKey: PublicKeyPEM, blockSize: number, padding: number, paddingAlgorithm?: PaddingAlgorithm): Buffer;
|
|
62
|
+
export declare function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKeyPEM, blockSize: number, paddingAlgorithm?: number): Buffer;
|
|
63
63
|
export declare function coerceCertificatePem(certificate: Certificate | CertificatePEM): CertificatePEM;
|
|
64
64
|
export declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
|
|
65
|
+
export declare function coercePrivateKeyPem(privateKey: PrivateKey | PrivateKeyPEM): PrivateKeyPEM;
|
|
65
66
|
/***
|
|
66
|
-
* @method
|
|
67
|
+
* @method rsaLengthPrivateKey
|
|
67
68
|
* A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
|
|
68
69
|
* @param key a PEM public key or a PEM rsa private key
|
|
69
|
-
* @return
|
|
70
|
+
* @return the key length in bytes.
|
|
70
71
|
*/
|
|
71
|
-
export declare function
|
|
72
|
+
export declare function rsaLengthPrivateKey(key: PrivateKeyPEM | PrivateKey): number;
|
|
73
|
+
export declare function rsaLengthPublicKey(key: PublicKeyPEM): number;
|
|
72
74
|
export declare function extractPublicKeyFromCertificateSync(certificate: Certificate | CertificatePEM): PublicKeyPEM;
|
|
73
75
|
/**
|
|
74
76
|
* extract the publickey from a certificate
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractPublicKeyFromCertificate = exports.extractPublicKeyFromCertificateSync = exports.
|
|
3
|
+
exports.extractPublicKeyFromCertificate = exports.extractPublicKeyFromCertificateSync = exports.rsaLengthPublicKey = exports.rsaLengthPrivateKey = exports.coercePrivateKeyPem = exports.coercePublicKeyPem = exports.coerceCertificatePem = exports.privateDecrypt_long = exports.publicEncrypt_long = exports.privateDecrypt = exports.publicEncrypt = exports.privateDecrypt_native = exports.publicEncrypt_native = exports.PaddingAlgorithm = exports.RSA_PKCS1_PADDING = exports.RSA_PKCS1_OAEP_PADDING = exports.makeSHA1Thumbprint = exports.verifyMessageChunkSignature = exports.makeMessageChunkSignature = exports.hexDump = exports.toPem = exports.convertPEMtoDER = exports.identifyPemType = void 0;
|
|
4
4
|
// tslint:disabled:no-var-requires
|
|
5
5
|
/**
|
|
6
6
|
* @module node_opcua_crypto
|
|
@@ -81,7 +81,7 @@ function hexDump(buffer, width) {
|
|
|
81
81
|
}
|
|
82
82
|
width = width || 32;
|
|
83
83
|
if (buffer.length > 1024) {
|
|
84
|
-
return (0, hexy_1.hexy)(buffer.
|
|
84
|
+
return (0, hexy_1.hexy)(buffer.subarray(0, 1024), { width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
return (0, hexy_1.hexy)(buffer, { width, format: "twos" });
|
|
@@ -189,36 +189,42 @@ function privateDecrypt_native(buffer, privateKey, algorithm) {
|
|
|
189
189
|
exports.privateDecrypt_native = privateDecrypt_native;
|
|
190
190
|
exports.publicEncrypt = publicEncrypt_native;
|
|
191
191
|
exports.privateDecrypt = privateDecrypt_native;
|
|
192
|
-
function publicEncrypt_long(buffer, publicKey, blockSize, padding,
|
|
193
|
-
if (
|
|
194
|
-
|
|
192
|
+
function publicEncrypt_long(buffer, publicKey, blockSize, padding, paddingAlgorithm) {
|
|
193
|
+
if (paddingAlgorithm === undefined) {
|
|
194
|
+
paddingAlgorithm = PaddingAlgorithm.RSA_PKCS1_PADDING;
|
|
195
|
+
}
|
|
196
|
+
if (paddingAlgorithm !== exports.RSA_PKCS1_PADDING && paddingAlgorithm !== exports.RSA_PKCS1_OAEP_PADDING) {
|
|
197
|
+
throw new Error("Invalid padding algorithm " + paddingAlgorithm);
|
|
195
198
|
}
|
|
196
|
-
assert(algorithm === exports.RSA_PKCS1_PADDING || algorithm === exports.RSA_PKCS1_OAEP_PADDING);
|
|
197
199
|
const chunk_size = blockSize - padding;
|
|
198
200
|
const nbBlocks = Math.ceil(buffer.length / chunk_size);
|
|
199
201
|
const outputBuffer = (0, buffer_utils_1.createFastUninitializedBuffer)(nbBlocks * blockSize);
|
|
200
202
|
for (let i = 0; i < nbBlocks; i++) {
|
|
201
|
-
const currentBlock = buffer.
|
|
202
|
-
const encrypted_chunk = (0, exports.publicEncrypt)(currentBlock, publicKey,
|
|
203
|
-
|
|
203
|
+
const currentBlock = buffer.subarray(chunk_size * i, chunk_size * (i + 1));
|
|
204
|
+
const encrypted_chunk = (0, exports.publicEncrypt)(currentBlock, publicKey, paddingAlgorithm);
|
|
205
|
+
if (encrypted_chunk.length !== blockSize) {
|
|
206
|
+
throw new Error(`publicEncrypt_long unexpected chunk length ${encrypted_chunk.length} expecting ${blockSize}`);
|
|
207
|
+
}
|
|
204
208
|
encrypted_chunk.copy(outputBuffer, i * blockSize);
|
|
205
209
|
}
|
|
206
210
|
return outputBuffer;
|
|
207
211
|
}
|
|
208
212
|
exports.publicEncrypt_long = publicEncrypt_long;
|
|
209
|
-
function privateDecrypt_long(buffer, privateKey, blockSize,
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
function privateDecrypt_long(buffer, privateKey, blockSize, paddingAlgorithm) {
|
|
214
|
+
paddingAlgorithm = paddingAlgorithm || exports.RSA_PKCS1_PADDING;
|
|
215
|
+
if (paddingAlgorithm !== exports.RSA_PKCS1_PADDING && paddingAlgorithm !== exports.RSA_PKCS1_OAEP_PADDING) {
|
|
216
|
+
throw new Error("Invalid padding algorithm " + paddingAlgorithm);
|
|
217
|
+
}
|
|
212
218
|
const nbBlocks = Math.ceil(buffer.length / blockSize);
|
|
213
219
|
const outputBuffer = (0, buffer_utils_1.createFastUninitializedBuffer)(nbBlocks * blockSize);
|
|
214
220
|
let total_length = 0;
|
|
215
221
|
for (let i = 0; i < nbBlocks; i++) {
|
|
216
|
-
const currentBlock = buffer.
|
|
217
|
-
const decrypted_buf = (0, exports.privateDecrypt)(currentBlock, privateKey,
|
|
222
|
+
const currentBlock = buffer.subarray(blockSize * i, Math.min(blockSize * (i + 1), buffer.length));
|
|
223
|
+
const decrypted_buf = (0, exports.privateDecrypt)(currentBlock, privateKey, paddingAlgorithm);
|
|
218
224
|
decrypted_buf.copy(outputBuffer, total_length);
|
|
219
225
|
total_length += decrypted_buf.length;
|
|
220
226
|
}
|
|
221
|
-
return outputBuffer.
|
|
227
|
+
return outputBuffer.subarray(0, total_length);
|
|
222
228
|
}
|
|
223
229
|
exports.privateDecrypt_long = privateDecrypt_long;
|
|
224
230
|
function coerceCertificatePem(certificate) {
|
|
@@ -237,19 +243,45 @@ function coercePublicKeyPem(publicKey) {
|
|
|
237
243
|
return publicKey;
|
|
238
244
|
}
|
|
239
245
|
exports.coercePublicKeyPem = coercePublicKeyPem;
|
|
246
|
+
function coercePrivateKeyPem(privateKey) {
|
|
247
|
+
if (privateKey instanceof Buffer) {
|
|
248
|
+
const o = crypto.createPrivateKey({ key: privateKey, format: "der", type: "pkcs1" });
|
|
249
|
+
const e = o.export({ format: "der", type: "pkcs1" });
|
|
250
|
+
privateKey = toPem(e, "RSA PRIVATE KEY");
|
|
251
|
+
}
|
|
252
|
+
assert(typeof privateKey === "string");
|
|
253
|
+
return privateKey;
|
|
254
|
+
}
|
|
255
|
+
exports.coercePrivateKeyPem = coercePrivateKeyPem;
|
|
240
256
|
/***
|
|
241
|
-
* @method
|
|
257
|
+
* @method rsaLengthPrivateKey
|
|
242
258
|
* A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
|
|
243
259
|
* @param key a PEM public key or a PEM rsa private key
|
|
244
|
-
* @return
|
|
260
|
+
* @return the key length in bytes.
|
|
245
261
|
*/
|
|
246
|
-
function
|
|
262
|
+
function rsaLengthPrivateKey(key) {
|
|
263
|
+
key = coercePrivateKeyPem(key);
|
|
264
|
+
assert(typeof key === "string");
|
|
265
|
+
if (/PRIVATE/.test(key)) {
|
|
266
|
+
const o = crypto.createPrivateKey(key);
|
|
267
|
+
// in node 16 and above :
|
|
268
|
+
// return o.asymmetricKeyDetails.modulusLength/8
|
|
269
|
+
// in node <16 :
|
|
270
|
+
const key2 = o.export({ type: "pkcs1", format: "pem" });
|
|
271
|
+
const a = jsrsasign.KEYUTIL.getKey(key2);
|
|
272
|
+
return a.n.toString(16).length / 2;
|
|
273
|
+
}
|
|
274
|
+
const a = jsrsasign.KEYUTIL.getKey(key);
|
|
275
|
+
return a.n.toString(16).length / 2;
|
|
276
|
+
}
|
|
277
|
+
exports.rsaLengthPrivateKey = rsaLengthPrivateKey;
|
|
278
|
+
function rsaLengthPublicKey(key) {
|
|
247
279
|
key = coercePublicKeyPem(key);
|
|
248
280
|
assert(typeof key === "string");
|
|
249
281
|
const a = jsrsasign.KEYUTIL.getKey(key);
|
|
250
282
|
return a.n.toString(16).length / 2;
|
|
251
283
|
}
|
|
252
|
-
exports.
|
|
284
|
+
exports.rsaLengthPublicKey = rsaLengthPublicKey;
|
|
253
285
|
function extractPublicKeyFromCertificateSync(certificate) {
|
|
254
286
|
certificate = coerceCertificatePem(certificate);
|
|
255
287
|
const key = jsrsasign.KEYUTIL.getKey(certificate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto_utils.js","sourceRoot":"","sources":["../../source/crypto_utils.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC;;GAEG;AACH,uCAAuC;AACvC,iCAAiC;AACjC,iDAA+D;AAE/D,6EAA2D;AAC3D,iCAAiC;AACjC,+BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEvC,MAAM,SAAS,GAAG,gFAAgF,CAAC;AAEnG,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,0CAA0C;AAC1C,kBAAkB;AAElB;;;;GAIG;AACH,SAAgB,eAAe,CAAC,MAAuB;IACnD,IAAI,MAAM,YAAY,MAAM,EAAE;QAC1B,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACpC;IACD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAND,0CAMC;AAED,SAAgB,eAAe,CAAC,OAAY;IACxC,IAAI,KAAU,CAAC;IACf,IAAI,OAAO,CAAC;IACZ,IAAI,SAAS,CAAC;IAEd,MAAM,KAAK,GAAU,EAAE,CAAC;IAExB,SAAS,CAAC,SAAS,GAAG,CAAC,CAAC;IACxB,qDAAqD;IACrD,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE;QAC/C,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,+EAA+E;QAC/E,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACr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AAgB,+BAA+B,CAC3C,WAAyC,EACzC,QAAkE;IAElE,IAAI,IAAI,GAAQ,IAAI,CAAC;IACrB,IAAI,MAAoB,CAAC;IACzB,IAAI;QACA,MAAM,GAAG,mCAAmC,CAAC,WAAW,CAAC,CAAC;KAC7D;IAAC,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,GAAG,CAAC;KACd;IACD,YAAY,CAAC,GAAG,EAAE;QACd,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,0EAcC"}
|
|
@@ -35,7 +35,7 @@ export declare function reduceLength(buffer: Buffer, byteToRemove: number): Buff
|
|
|
35
35
|
* @return buffer with padding removed
|
|
36
36
|
*/
|
|
37
37
|
export declare function removePadding(buffer: Buffer): Buffer;
|
|
38
|
-
export
|
|
38
|
+
export type VerifyChunkSignatureOptions = VerifyMessageChunkSignatureOptions;
|
|
39
39
|
/**
|
|
40
40
|
* @method verifyChunkSignature
|
|
41
41
|
*
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Certificate, CertificatePEM } from "./common";
|
|
5
5
|
import { SubjectPublicKey } from "./crypto_explore_certificate";
|
|
6
6
|
import { DirectoryName } from "./asn1";
|
|
7
|
-
export
|
|
7
|
+
export type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
|
|
8
8
|
/**
|
|
9
9
|
* A structure exposing useful information about a certificate
|
|
10
10
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AlgorithmIdentifier, BlockInfo, DirectoryName } from "./asn1";
|
|
3
3
|
import { CertificateRevocationList } from "./common";
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
4
|
+
export type Version = string;
|
|
5
|
+
export type Name = string;
|
|
6
|
+
export type CertificateSerialNumber = string;
|
|
7
|
+
export type Extensions = Record<string, unknown>;
|
|
8
8
|
export interface RevokedCertificate {
|
|
9
9
|
userCertificate: CertificateSerialNumber;
|
|
10
10
|
revocationDate: Date;
|
|
@@ -4,7 +4,7 @@ exports.explorePrivateKey = void 0;
|
|
|
4
4
|
const assert = require("assert");
|
|
5
5
|
const asn1_1 = require("./asn1");
|
|
6
6
|
function f(buffer, b) {
|
|
7
|
-
return buffer.
|
|
7
|
+
return buffer.subarray(b.position + 1, b.position + b.length);
|
|
8
8
|
}
|
|
9
9
|
const doDebug = !!process.env.DEBUG;
|
|
10
10
|
/**
|
|
@@ -50,18 +50,18 @@ function explorePrivateKey(privateKey) {
|
|
|
50
50
|
/* istanbul ignore next */
|
|
51
51
|
if (doDebug) {
|
|
52
52
|
// tslint:disable:no-console
|
|
53
|
-
console.log("--------------------");
|
|
53
|
+
console.log("-------------------- private key:");
|
|
54
54
|
console.log(block_info);
|
|
55
55
|
// tslint:disable:no-console
|
|
56
56
|
console.log(blocks.map((b) => ({
|
|
57
57
|
tag: asn1_1.TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
58
58
|
l: b.length,
|
|
59
59
|
p: b.position,
|
|
60
|
-
buff: privateKey.
|
|
60
|
+
buff: privateKey.subarray(b.position, b.position + b.length).toString("hex"),
|
|
61
61
|
})));
|
|
62
62
|
}
|
|
63
63
|
const b = blocks[2];
|
|
64
|
-
const bb = privateKey.
|
|
64
|
+
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
65
65
|
const block_info1 = (0, asn1_1.readTag)(bb, 0);
|
|
66
66
|
const blocks1 = (0, asn1_1._readStruct)(bb, block_info1);
|
|
67
67
|
/* istanbul ignore next */
|
|
@@ -71,7 +71,7 @@ function explorePrivateKey(privateKey) {
|
|
|
71
71
|
tag: asn1_1.TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
72
72
|
l: b.length,
|
|
73
73
|
p: b.position,
|
|
74
|
-
buff: bb.
|
|
74
|
+
buff: bb.subarray(b.position, b.position + b.length).toString("hex"),
|
|
75
75
|
})));
|
|
76
76
|
}
|
|
77
77
|
const version = f(bb, blocks1[0]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explore_private_key.js","sourceRoot":"","sources":["../../source/explore_private_key.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,iCAA4F;AAiB5F,SAAS,CAAC,CAAC,MAAc,EAAE,CAAY;IACnC,OAAO,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"explore_private_key.js","sourceRoot":"","sources":["../../source/explore_private_key.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,iCAA4F;AAiB5F,SAAS,CAAC,CAAC,MAAc,EAAE,CAAY;IACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;AAC/D,CAAC;AACD,MAAM,OAAO,GAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;AACnC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAAC,UAAsB;IACpD,MAAM,CAAC,UAAU,YAAY,MAAM,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,IAAA,cAAO,EAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAA,kBAAW,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEnD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,YAAY;QACZ,MAAM,OAAO,GAAG,CAAC,CAAC,UAAU,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,oDAAoD;QAC5F,MAAM,OAAO,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,cAAc,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,eAAe,GAAG,CAAC,CAAC,U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CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,SAAS,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAGpC,OAAO;QACH,OAAO;QACP,OAAO;QACP,cAAc;QACd,eAAe;QACf,MAAM;QACN,MAAM;QACN,SAAS;QACT,SAAS;KACZ,CAAC;AACN,CAAC;AAnFD,8CAmFC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Certificate } from "./common";
|
|
2
|
-
import { PrivateKey } from "./common";
|
|
1
|
+
import { Certificate, PrivateKey } from "./common";
|
|
3
2
|
export declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
3
|
+
export declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
4
|
-
const _1 = require(".");
|
|
3
|
+
exports.certificateMatchesPrivateKey = exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
5
4
|
const explore_private_key_1 = require("./explore_private_key");
|
|
5
|
+
const crypto_utils_1 = require("./crypto_utils");
|
|
6
|
+
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
6
7
|
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
7
|
-
const i = (0,
|
|
8
|
+
const i = (0, crypto_explore_certificate_1.exploreCertificate)(certificate);
|
|
8
9
|
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
9
10
|
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
10
11
|
const modulus2 = j.modulus;
|
|
@@ -14,4 +15,24 @@ function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
|
14
15
|
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
15
16
|
}
|
|
16
17
|
exports.publicKeyAndPrivateKeyMatches = publicKeyAndPrivateKeyMatches;
|
|
18
|
+
/**
|
|
19
|
+
* check that the given certificate matches the given private key
|
|
20
|
+
* @param certificate
|
|
21
|
+
* @param privateKey
|
|
22
|
+
*/
|
|
23
|
+
function certificateMatchesPrivateKeyPEM(certificate, privateKey, blockSize) {
|
|
24
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
25
|
+
const encryptedBuffer = (0, crypto_utils_1.publicEncrypt_long)(initialBuffer, certificate, blockSize, 11);
|
|
26
|
+
const decryptedBuffer = (0, crypto_utils_1.privateDecrypt_long)(encryptedBuffer, privateKey, blockSize);
|
|
27
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
28
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
29
|
+
}
|
|
30
|
+
function certificateMatchesPrivateKey(certificate, privateKey) {
|
|
31
|
+
const e = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
32
|
+
const blockSize = e.modulus.length;
|
|
33
|
+
const certificatePEM = (0, crypto_utils_1.toPem)(certificate, "CERTIFICATE");
|
|
34
|
+
const privateKeyPEM = (0, crypto_utils_1.toPem)(privateKey, "RSA PRIVATE KEY");
|
|
35
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKeyPEM, blockSize);
|
|
36
|
+
}
|
|
37
|
+
exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
|
|
17
38
|
//# sourceMappingURL=public_private_match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_private_match.js","sourceRoot":"","sources":["../../source/public_private_match.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"public_private_match.js","sourceRoot":"","sources":["../../source/public_private_match.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,iDAAgF;AAChF,6E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,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,OAAO,+BAA+B,CAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AACrF,CAAC;AAND,oEAMC"}
|
|
@@ -3,7 +3,7 @@ import { Certificate } from "./common";
|
|
|
3
3
|
export declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
4
4
|
export declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
5
5
|
export declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
6
|
-
export
|
|
6
|
+
export type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
7
7
|
export declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
8
8
|
status: _VerifyStatus;
|
|
9
9
|
reason: string;
|
|
@@ -69,7 +69,7 @@ function setCertificateStore(store) {
|
|
|
69
69
|
}
|
|
70
70
|
exports.setCertificateStore = setCertificateStore;
|
|
71
71
|
function read_sshkey_as_pem(filename) {
|
|
72
|
-
if (filename.
|
|
72
|
+
if (filename.substring(0, 1) !== ".") {
|
|
73
73
|
filename = __certificate_store + filename;
|
|
74
74
|
}
|
|
75
75
|
const key = fs.readFileSync(filename, "ascii");
|
|
@@ -82,7 +82,7 @@ exports.read_sshkey_as_pem = read_sshkey_as_pem;
|
|
|
82
82
|
* @param filename
|
|
83
83
|
*/
|
|
84
84
|
function readPrivateRsaKey(filename) {
|
|
85
|
-
if (filename.
|
|
85
|
+
if (filename.substring(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
86
86
|
filename = __certificate_store + filename;
|
|
87
87
|
}
|
|
88
88
|
return fs.readFileSync(filename, "ascii");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","s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AAgB,kBAAkB,CAAC,QAAgB;IAC/C,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;QAClC,QAAQ,GAAG,mBAAmB,GAAG,QAAQ,CAAC;KAC7C;IACD,MAAM,GAAG,GAAW,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAE1C,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAQ,CAAC;AAC3C,CAAC;AARD,gDAQC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,QAAgB;IAC9C,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC9D,QAAQ,GAAG,mBAAmB,GAAG,QAAQ,CAAC;KAC7C;IACD,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAW,CAAC;AACxD,CAAC;AALD,8CAKC;AAED,SAAgB,gBAAgB,CAAC,QAAgB;IAC7C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC;AAFD,4CAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-crypto",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Crypto tools for Node-OPCUA",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -28,27 +28,27 @@
|
|
|
28
28
|
"author": "Etienne Rossignon",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/mocha": "^10.0.
|
|
32
|
-
"@types/node": "^18.11.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
34
|
-
"@typescript-eslint/parser": "^5.
|
|
35
|
-
"eslint": "^8.
|
|
31
|
+
"@types/mocha": "^10.0.1",
|
|
32
|
+
"@types/node": "^18.11.15",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
34
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
35
|
+
"eslint": "^8.29.0",
|
|
36
36
|
"eslint-config-prettier": "^8.5.0",
|
|
37
37
|
"eslint-plugin-prettier": "^4.2.1",
|
|
38
38
|
"lorem-ipsum": "^2.0.8",
|
|
39
|
-
"mocha": "^10.
|
|
40
|
-
"prettier": "^2.
|
|
39
|
+
"mocha": "^10.2.0",
|
|
40
|
+
"prettier": "^2.8.1",
|
|
41
41
|
"should": "^13.2.3",
|
|
42
42
|
"source-map": "^0.7.4",
|
|
43
43
|
"source-map-support": "^0.5.21",
|
|
44
44
|
"ts-node": "^10.9.1",
|
|
45
|
-
"typescript": "^4.
|
|
45
|
+
"typescript": "^4.9.4"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"better-assert": "^1.0.2",
|
|
49
49
|
"chalk": "^4.1.2",
|
|
50
50
|
"hexy": "0.3.4",
|
|
51
|
-
"jsrsasign": "^10.
|
|
51
|
+
"jsrsasign": "^10.6.1",
|
|
52
52
|
"sshpk": "^1.17.0"
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
package/source/crypto_utils.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function toPem(raw_key: Buffer | string, pem: string): string {
|
|
|
61
61
|
assert(typeof pem === "string");
|
|
62
62
|
let pemType = identifyPemType(raw_key);
|
|
63
63
|
if (pemType) {
|
|
64
|
-
return raw_key instanceof Buffer ?
|
|
64
|
+
return raw_key instanceof Buffer ? raw_key.toString("utf8") : raw_key;
|
|
65
65
|
} else {
|
|
66
66
|
pemType = pem;
|
|
67
67
|
assert(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
|
|
@@ -84,7 +84,7 @@ export function hexDump(buffer: Buffer, width?: number): string {
|
|
|
84
84
|
}
|
|
85
85
|
width = width || 32;
|
|
86
86
|
if (buffer.length > 1024) {
|
|
87
|
-
return hexy(buffer.
|
|
87
|
+
return hexy(buffer.subarray(0, 1024), { width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
|
|
88
88
|
} else {
|
|
89
89
|
return hexy(buffer, { width, format: "twos" });
|
|
90
90
|
}
|
|
@@ -106,7 +106,7 @@ interface MakeMessageChunkSignatureOptions {
|
|
|
106
106
|
* @return - the signature
|
|
107
107
|
*/
|
|
108
108
|
export function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChunkSignatureOptions): Buffer {
|
|
109
|
-
assert(Object.prototype.hasOwnProperty.call(options,"algorithm"));
|
|
109
|
+
assert(Object.prototype.hasOwnProperty.call(options, "algorithm"));
|
|
110
110
|
assert(chunk instanceof Buffer);
|
|
111
111
|
assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(options.privateKey) as string) >= 0);
|
|
112
112
|
// signature length = 128 bytes
|
|
@@ -223,29 +223,40 @@ export function publicEncrypt_long(
|
|
|
223
223
|
publicKey: PublicKeyPEM,
|
|
224
224
|
blockSize: number,
|
|
225
225
|
padding: number,
|
|
226
|
-
|
|
226
|
+
paddingAlgorithm?: PaddingAlgorithm
|
|
227
227
|
): Buffer {
|
|
228
|
-
if (
|
|
229
|
-
|
|
228
|
+
if (paddingAlgorithm === undefined) {
|
|
229
|
+
paddingAlgorithm = PaddingAlgorithm.RSA_PKCS1_PADDING;
|
|
230
|
+
}
|
|
231
|
+
if (paddingAlgorithm !== RSA_PKCS1_PADDING && paddingAlgorithm !== RSA_PKCS1_OAEP_PADDING) {
|
|
232
|
+
throw new Error("Invalid padding algorithm " + paddingAlgorithm);
|
|
230
233
|
}
|
|
231
|
-
assert(algorithm === RSA_PKCS1_PADDING || algorithm === RSA_PKCS1_OAEP_PADDING);
|
|
232
234
|
|
|
233
235
|
const chunk_size = blockSize - padding;
|
|
234
236
|
const nbBlocks = Math.ceil(buffer.length / chunk_size);
|
|
235
237
|
|
|
236
238
|
const outputBuffer = createFastUninitializedBuffer(nbBlocks * blockSize);
|
|
237
239
|
for (let i = 0; i < nbBlocks; i++) {
|
|
238
|
-
const currentBlock = buffer.
|
|
239
|
-
const encrypted_chunk = publicEncrypt(currentBlock, publicKey,
|
|
240
|
-
|
|
240
|
+
const currentBlock = buffer.subarray(chunk_size * i, chunk_size * (i + 1));
|
|
241
|
+
const encrypted_chunk = publicEncrypt(currentBlock, publicKey, paddingAlgorithm);
|
|
242
|
+
if (encrypted_chunk.length !== blockSize) {
|
|
243
|
+
throw new Error(`publicEncrypt_long unexpected chunk length ${encrypted_chunk.length} expecting ${blockSize}`);
|
|
244
|
+
}
|
|
241
245
|
encrypted_chunk.copy(outputBuffer, i * blockSize);
|
|
242
246
|
}
|
|
243
247
|
return outputBuffer;
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
export function privateDecrypt_long(
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
export function privateDecrypt_long(
|
|
251
|
+
buffer: Buffer,
|
|
252
|
+
privateKey: PrivateKeyPEM,
|
|
253
|
+
blockSize: number,
|
|
254
|
+
paddingAlgorithm?: number
|
|
255
|
+
): Buffer {
|
|
256
|
+
paddingAlgorithm = paddingAlgorithm || RSA_PKCS1_PADDING;
|
|
257
|
+
if (paddingAlgorithm !== RSA_PKCS1_PADDING && paddingAlgorithm !== RSA_PKCS1_OAEP_PADDING) {
|
|
258
|
+
throw new Error("Invalid padding algorithm " + paddingAlgorithm);
|
|
259
|
+
}
|
|
249
260
|
|
|
250
261
|
const nbBlocks = Math.ceil(buffer.length / blockSize);
|
|
251
262
|
|
|
@@ -253,12 +264,12 @@ export function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKeyPEM, b
|
|
|
253
264
|
|
|
254
265
|
let total_length = 0;
|
|
255
266
|
for (let i = 0; i < nbBlocks; i++) {
|
|
256
|
-
const currentBlock = buffer.
|
|
257
|
-
const decrypted_buf = privateDecrypt(currentBlock, privateKey,
|
|
267
|
+
const currentBlock = buffer.subarray(blockSize * i, Math.min(blockSize * (i + 1), buffer.length));
|
|
268
|
+
const decrypted_buf = privateDecrypt(currentBlock, privateKey, paddingAlgorithm);
|
|
258
269
|
decrypted_buf.copy(outputBuffer, total_length);
|
|
259
270
|
total_length += decrypted_buf.length;
|
|
260
271
|
}
|
|
261
|
-
return outputBuffer.
|
|
272
|
+
return outputBuffer.subarray(0, total_length);
|
|
262
273
|
}
|
|
263
274
|
|
|
264
275
|
export function coerceCertificatePem(certificate: Certificate | CertificatePEM): CertificatePEM {
|
|
@@ -276,14 +287,41 @@ export function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicK
|
|
|
276
287
|
assert(typeof publicKey === "string");
|
|
277
288
|
return publicKey;
|
|
278
289
|
}
|
|
290
|
+
export function coercePrivateKeyPem(privateKey: PrivateKey | PrivateKeyPEM): PrivateKeyPEM {
|
|
291
|
+
if (privateKey instanceof Buffer) {
|
|
292
|
+
|
|
293
|
+
const o = crypto.createPrivateKey({ key: privateKey, format: "der", type: "pkcs1"});
|
|
294
|
+
|
|
295
|
+
const e = o.export({format: "der", type: "pkcs1"});
|
|
296
|
+
privateKey = toPem(e, "RSA PRIVATE KEY");
|
|
297
|
+
}
|
|
298
|
+
assert(typeof privateKey === "string");
|
|
299
|
+
return privateKey;
|
|
300
|
+
}
|
|
279
301
|
|
|
280
302
|
/***
|
|
281
|
-
* @method
|
|
303
|
+
* @method rsaLengthPrivateKey
|
|
282
304
|
* A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
|
|
283
305
|
* @param key a PEM public key or a PEM rsa private key
|
|
284
|
-
* @return
|
|
306
|
+
* @return the key length in bytes.
|
|
285
307
|
*/
|
|
286
|
-
export function
|
|
308
|
+
export function rsaLengthPrivateKey(key: PrivateKeyPEM | PrivateKey): number {
|
|
309
|
+
key = coercePrivateKeyPem(key);
|
|
310
|
+
assert(typeof key === "string");
|
|
311
|
+
if (/PRIVATE/.test(key)) {
|
|
312
|
+
const o = crypto.createPrivateKey(key);
|
|
313
|
+
// in node 16 and above :
|
|
314
|
+
// return o.asymmetricKeyDetails.modulusLength/8
|
|
315
|
+
// in node <16 :
|
|
316
|
+
const key2 = o.export({ type: "pkcs1", format: "pem" });
|
|
317
|
+
const a = jsrsasign.KEYUTIL.getKey(key2);
|
|
318
|
+
return a.n.toString(16).length / 2;
|
|
319
|
+
}
|
|
320
|
+
const a = jsrsasign.KEYUTIL.getKey(key);
|
|
321
|
+
return a.n.toString(16).length / 2;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function rsaLengthPublicKey(key: PublicKeyPEM): number {
|
|
287
325
|
key = coercePublicKeyPem(key);
|
|
288
326
|
assert(typeof key === "string");
|
|
289
327
|
const a = jsrsasign.KEYUTIL.getKey(key);
|
|
@@ -17,7 +17,7 @@ export interface PrivateKeyInternals {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function f(buffer: Buffer, b: BlockInfo) {
|
|
20
|
-
return buffer.
|
|
20
|
+
return buffer.subarray(b.position+1, b.position + b.length)
|
|
21
21
|
}
|
|
22
22
|
const doDebug= !!process.env.DEBUG;
|
|
23
23
|
/**
|
|
@@ -66,7 +66,7 @@ export function explorePrivateKey(privateKey: PrivateKey): PrivateKeyInternals {
|
|
|
66
66
|
/* istanbul ignore next */
|
|
67
67
|
if (doDebug) {
|
|
68
68
|
// tslint:disable:no-console
|
|
69
|
-
console.log("--------------------")
|
|
69
|
+
console.log("-------------------- private key:")
|
|
70
70
|
console.log(block_info);
|
|
71
71
|
|
|
72
72
|
// tslint:disable:no-console
|
|
@@ -75,13 +75,13 @@ export function explorePrivateKey(privateKey: PrivateKey): PrivateKeyInternals {
|
|
|
75
75
|
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
76
76
|
l: b.length,
|
|
77
77
|
p: b.position,
|
|
78
|
-
buff: privateKey.
|
|
78
|
+
buff: privateKey.subarray(b.position, b.position + b.length).toString("hex"),
|
|
79
79
|
}))
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const b = blocks[2];
|
|
84
|
-
const bb = privateKey.
|
|
84
|
+
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
85
85
|
const block_info1 = readTag(bb, 0);
|
|
86
86
|
const blocks1 = _readStruct(bb, block_info1);
|
|
87
87
|
|
|
@@ -93,7 +93,7 @@ export function explorePrivateKey(privateKey: PrivateKey): PrivateKeyInternals {
|
|
|
93
93
|
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
94
94
|
l: b.length,
|
|
95
95
|
p: b.position,
|
|
96
|
-
buff: bb.
|
|
96
|
+
buff: bb.subarray(b.position, b.position + b.length).toString("hex"),
|
|
97
97
|
}))
|
|
98
98
|
);
|
|
99
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { exploreCertificate } from ".";
|
|
2
|
-
import { Certificate } from "./common";
|
|
3
|
-
import { PrivateKey } from "./common";
|
|
4
1
|
import { explorePrivateKey } from "./explore_private_key";
|
|
2
|
+
import { Certificate, CertificatePEM, PrivateKey, PrivateKeyPEM } from "./common";
|
|
3
|
+
import { privateDecrypt_long, publicEncrypt_long, toPem } from "./crypto_utils";
|
|
4
|
+
import { exploreCertificate } from "./crypto_explore_certificate";
|
|
5
5
|
|
|
6
6
|
export function publicKeyAndPrivateKeyMatches(certificate: Certificate,privateKey: PrivateKey): boolean {
|
|
7
7
|
|
|
@@ -15,4 +15,27 @@ export function publicKeyAndPrivateKeyMatches(certificate: Certificate,privateK
|
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
17
|
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* check that the given certificate matches the given private key
|
|
24
|
+
* @param certificate
|
|
25
|
+
* @param privateKey
|
|
26
|
+
*/
|
|
27
|
+
function certificateMatchesPrivateKeyPEM(certificate: CertificatePEM, privateKey: PrivateKeyPEM, blockSize: number): boolean {
|
|
28
|
+
const initialBuffer = Buffer.from("Lorem Ipsum");
|
|
29
|
+
const encryptedBuffer = publicEncrypt_long(initialBuffer, certificate, blockSize, 11);
|
|
30
|
+
const decryptedBuffer = privateDecrypt_long(encryptedBuffer, privateKey, blockSize);
|
|
31
|
+
const finalString = decryptedBuffer.toString("utf-8");
|
|
32
|
+
return initialBuffer.toString("utf-8") === finalString;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean {
|
|
36
|
+
const e = explorePrivateKey(privateKey);
|
|
37
|
+
const blockSize = e.modulus.length;
|
|
38
|
+
const certificatePEM = toPem(certificate, "CERTIFICATE");
|
|
39
|
+
const privateKeyPEM = toPem(privateKey, "RSA PRIVATE KEY");
|
|
40
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKeyPEM, blockSize);
|
|
41
|
+
}
|
package/source_nodejs/read.ts
CHANGED
|
@@ -70,7 +70,7 @@ export function setCertificateStore(store: string): string {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export function read_sshkey_as_pem(filename: string): PublicKeyPEM {
|
|
73
|
-
if (filename.
|
|
73
|
+
if (filename.substring(0, 1) !== ".") {
|
|
74
74
|
filename = __certificate_store + filename;
|
|
75
75
|
}
|
|
76
76
|
const key: string = fs.readFileSync(filename, "ascii");
|
|
@@ -84,7 +84,7 @@ export function read_sshkey_as_pem(filename: string): PublicKeyPEM {
|
|
|
84
84
|
* @param filename
|
|
85
85
|
*/
|
|
86
86
|
export function readPrivateRsaKey(filename: string): PrivateKeyPEM {
|
|
87
|
-
if (filename.
|
|
87
|
+
if (filename.substring(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
88
88
|
filename = __certificate_store + filename;
|
|
89
89
|
}
|
|
90
90
|
return fs.readFileSync(filename, "ascii") as string;
|