node-opcua-crypto 1.11.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/.fossa.yml +18 -18
- package/.github/FUNDING.yml +12 -12
- package/.github/workflows/main.yml +32 -32
- package/.prettierrc.js +6 -6
- package/LICENSE +23 -22
- package/README.md +14 -14
- package/dist/source/asn1.d.ts +73 -73
- package/dist/source/asn1.js +359 -359
- package/dist/source/buffer_utils.d.ts +6 -6
- package/dist/source/buffer_utils.js +21 -21
- 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 +12 -12
- package/dist/source/common.js +2 -2
- package/dist/source/crypto_explore_certificate.d.ts +107 -107
- package/dist/source/crypto_explore_certificate.js +601 -600
- package/dist/source/crypto_explore_certificate.js.map +1 -1
- package/dist/source/crypto_utils.d.ts +80 -78
- package/dist/source/crypto_utils.js +312 -280
- package/dist/source/crypto_utils.js.map +1 -1
- package/dist/source/derived_keys.d.ts +72 -72
- package/dist/source/derived_keys.js +248 -248
- package/dist/source/explore_certificate.d.ts +30 -30
- package/dist/source/explore_certificate.js +43 -43
- package/dist/source/explore_certificate_revocation_list.d.ts +28 -28
- package/dist/source/explore_certificate_revocation_list.js +69 -69
- package/dist/source/explore_certificate_signing_request.d.ts +13 -13
- package/dist/source/explore_certificate_signing_request.js +44 -44
- package/dist/source/explore_private_key.d.ts +29 -29
- package/dist/source/explore_private_key.js +96 -96
- package/dist/source/explore_private_key.js.map +1 -1
- package/dist/source/index.d.ts +13 -13
- package/dist/source/index.js +29 -29
- package/dist/source/oid_map.d.ts +7 -7
- package/dist/source/oid_map.js +303 -303
- package/dist/source/public_private_match.d.ts +3 -3
- package/dist/source/public_private_match.js +37 -16
- package/dist/source/public_private_match.js.map +1 -1
- package/dist/source/verify_certificate_signature.d.ts +10 -10
- package/dist/source/verify_certificate_signature.js +101 -101
- package/dist/source_nodejs/index.d.ts +3 -3
- package/dist/source_nodejs/index.js +19 -19
- package/dist/source_nodejs/read.d.ts +29 -29
- package/dist/source_nodejs/read.js +94 -94
- package/dist/source_nodejs/read.js.map +1 -1
- package/dist/source_nodejs/read_certificate_revocation_list.d.ts +2 -2
- package/dist/source_nodejs/read_certificate_revocation_list.js +27 -27
- package/dist/source_nodejs/read_certificate_signing_request.d.ts +3 -3
- package/dist/source_nodejs/read_certificate_signing_request.js +27 -27
- package/index.d.ts +2 -2
- package/index.js +4 -4
- package/index_web.js +3 -3
- package/package.json +12 -12
- package/source/asn1.ts +404 -404
- package/source/buffer_utils.ts +18 -18
- package/source/common.ts +13 -13
- package/source/crypto_explore_certificate.ts +764 -763
- package/source/crypto_utils.ts +359 -321
- package/source/derived_keys.ts +287 -287
- package/source/explore_certificate.ts +66 -66
- package/source/explore_certificate_revocation_list.ts +122 -122
- package/source/explore_certificate_signing_request.ts +58 -58
- package/source/explore_private_key.ts +121 -121
- package/source/index.ts +13 -13
- package/source/oid_map.ts +310 -310
- package/source/public_private_match.ts +41 -18
- package/source/verify_certificate_signature.ts +105 -105
- package/source_nodejs/index.ts +2 -2
- package/source_nodejs/read.ts +95 -95
- package/source_nodejs/read_certificate_revocation_list.ts +14 -14
- package/source_nodejs/read_certificate_signing_request.ts +17 -17
- package/test_certificate.ts +34 -34
- package/tsconfig.json +18 -18
- package/tslint.json +34 -34
- package/dist/asn1.d.ts +0 -69
- package/dist/asn1.js +0 -349
- package/dist/asn1.js.map +0 -1
- package/dist/buffer_utils.d.ts +0 -6
- package/dist/buffer_utils.js +0 -22
- package/dist/buffer_utils.js.map +0 -1
- package/dist/common.d.ts +0 -11
- package/dist/common.js +0 -3
- package/dist/common.js.map +0 -1
- package/dist/crypto_explore_certificate.d.ts +0 -95
- package/dist/crypto_explore_certificate.js +0 -547
- package/dist/crypto_explore_certificate.js.map +0 -1
- package/dist/crypto_utils.d.ts +0 -106
- package/dist/crypto_utils.js +0 -370
- package/dist/crypto_utils.js.map +0 -1
- package/dist/derived_keys.d.ts +0 -72
- package/dist/derived_keys.js +0 -247
- package/dist/derived_keys.js.map +0 -1
- package/dist/explore_certificate.d.ts +0 -30
- package/dist/explore_certificate.js +0 -44
- package/dist/explore_certificate.js.map +0 -1
- package/dist/explore_certificate_revocation_list.d.ts +0 -30
- package/dist/explore_certificate_revocation_list.js +0 -67
- package/dist/explore_certificate_revocation_list.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/oid_map.d.ts +0 -7
- package/dist/oid_map.js +0 -262
- package/dist/oid_map.js.map +0 -1
- package/dist/verify_cerficate_signature.d.ts +0 -10
- package/dist/verify_cerficate_signature.js +0 -102
- package/dist/verify_cerficate_signature.js.map +0 -1
package/dist/crypto_utils.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Certificate, CertificatePEM, DER, PEM, PrivateKey, PrivateKeyPEM, PublicKey, PublicKeyPEM, Signature } from "./common";
|
|
3
|
-
export declare function identifyPemType(rawKey: Buffer | string): undefined | string;
|
|
4
|
-
export declare function convertPEMtoDER(raw_key: PEM): DER;
|
|
5
|
-
/**
|
|
6
|
-
* read a DER or PEM certificate from file
|
|
7
|
-
*/
|
|
8
|
-
export declare function readCertificate(filename: string): Certificate;
|
|
9
|
-
/**
|
|
10
|
-
* read a DER or PEM certificate from file
|
|
11
|
-
*/
|
|
12
|
-
export declare function readPublicKey(filename: string): PublicKey;
|
|
13
|
-
/**
|
|
14
|
-
* read a DER or PEM certificate from file
|
|
15
|
-
*/
|
|
16
|
-
export declare function readPrivateKey(filename: string): PrivateKey;
|
|
17
|
-
export declare function readCertificatePEM(filename: string): CertificatePEM;
|
|
18
|
-
export declare function readPublicKeyPEM(filename: string): PublicKeyPEM;
|
|
19
|
-
export declare function readPrivateKeyPEM(filename: string): PrivateKeyPEM;
|
|
20
|
-
/**
|
|
21
|
-
* @method readKeyPem
|
|
22
|
-
* @param filename
|
|
23
|
-
*/
|
|
24
|
-
export declare function readKeyPem(filename: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* @method toPem
|
|
27
|
-
* @param raw_key
|
|
28
|
-
* @param pem
|
|
29
|
-
* @return
|
|
30
|
-
*/
|
|
31
|
-
export declare function toPem(raw_key: Buffer | string, pem: string): string;
|
|
32
|
-
export declare function hexDump(buffer: Buffer, width?: number): string;
|
|
33
|
-
interface MakeMessageChunkSignatureOptions {
|
|
34
|
-
signatureLength: number;
|
|
35
|
-
algorithm: string;
|
|
36
|
-
privateKey: CertificatePEM;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @method makeMessageChunkSignature
|
|
40
|
-
* @param chunk
|
|
41
|
-
* @param options
|
|
42
|
-
* @param options.signatureLength
|
|
43
|
-
* @param options.algorithm for example "RSA-SHA256"
|
|
44
|
-
* @param options.privateKey
|
|
45
|
-
* @return - the signature
|
|
46
|
-
*/
|
|
47
|
-
export declare function makeMessageChunkSignature(chunk: Buffer, options: MakeMessageChunkSignatureOptions): Buffer;
|
|
48
|
-
export interface VerifyMessageChunkSignatureOptions {
|
|
49
|
-
signatureLength?: number;
|
|
50
|
-
algorithm: string;
|
|
51
|
-
publicKey: PublicKeyPEM;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @method verifyMessageChunkSignature
|
|
55
|
-
*
|
|
56
|
-
* const signer = {
|
|
57
|
-
* signatureLength : 128,
|
|
58
|
-
* algorithm : "RSA-SHA256",
|
|
59
|
-
* publicKey: "qsdqsdqsd"
|
|
60
|
-
* };
|
|
61
|
-
* @param blockToVerify
|
|
62
|
-
* @param signature
|
|
63
|
-
* @param options
|
|
64
|
-
* @param options.signatureLength
|
|
65
|
-
* @param options.algorithm for example "RSA-SHA256"
|
|
66
|
-
* @param options.publicKey
|
|
67
|
-
* @return true if the signature is valid
|
|
68
|
-
*/
|
|
69
|
-
export declare function verifyMessageChunkSignature(blockToVerify: Buffer, signature: Signature, options: VerifyMessageChunkSignatureOptions): boolean;
|
|
70
|
-
export declare function makeSHA1Thumbprint(buffer: Buffer): Signature;
|
|
71
|
-
export declare function setCertificateStore(store: string): string;
|
|
72
|
-
export declare function read_sshkey_as_pem(filename: string): PublicKeyPEM;
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @param filename
|
|
76
|
-
*/
|
|
77
|
-
export declare function readPrivateRsaKey(filename: string): PrivateKeyPEM;
|
|
78
|
-
export declare function readPublicRsaKey(filename: string): PublicKeyPEM;
|
|
79
|
-
export declare const RSA_PKCS1_OAEP_PADDING: number;
|
|
80
|
-
export declare const RSA_PKCS1_PADDING: number;
|
|
81
|
-
export declare enum PaddingAlgorithm {
|
|
82
|
-
RSA_PKCS1_OAEP_PADDING = 4,
|
|
83
|
-
RSA_PKCS1_PADDING = 1
|
|
84
|
-
}
|
|
85
|
-
export declare function publicEncrypt_native(buffer: Buffer, publicKey: PublicKeyPEM, algorithm?: PaddingAlgorithm): Buffer;
|
|
86
|
-
export declare function privateDecrypt_native(buffer: Buffer, privateKey: PrivateKeyPEM, algorithm?: PaddingAlgorithm): Buffer;
|
|
87
|
-
export declare const publicEncrypt: typeof publicEncrypt_native;
|
|
88
|
-
export declare const privateDecrypt: typeof privateDecrypt_native;
|
|
89
|
-
export declare function publicEncrypt_long(buffer: Buffer, publicKey: PublicKeyPEM, blockSize: number, padding: number, algorithm?: PaddingAlgorithm): Buffer;
|
|
90
|
-
export declare function privateDecrypt_long(buffer: Buffer, privateKey: PrivateKeyPEM, blockSize: number, algorithm?: number): Buffer;
|
|
91
|
-
export declare function coerceCertificatePem(certificate: Certificate | CertificatePEM): CertificatePEM;
|
|
92
|
-
export declare function coercePublicKeyPem(publicKey: PublicKey | PublicKeyPEM): PublicKeyPEM;
|
|
93
|
-
/***
|
|
94
|
-
* @method rsa_length
|
|
95
|
-
* A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
|
|
96
|
-
* @param key a PEM public key or a PEM rsa private key
|
|
97
|
-
* @return { the key length in bytes.
|
|
98
|
-
*/
|
|
99
|
-
export declare function rsa_length(key: PublicKeyPEM | PublicKey): number;
|
|
100
|
-
export declare function extractPublicKeyFromCertificateSync(certificate: Certificate | CertificatePEM): PublicKeyPEM;
|
|
101
|
-
/**
|
|
102
|
-
* extract the publickey from a certificate
|
|
103
|
-
* @async
|
|
104
|
-
*/
|
|
105
|
-
export declare function extractPublicKeyFromCertificate(certificate: CertificatePEM | Certificate, callback: (err: Error | null, publicKeyPEM?: PublicKeyPEM) => void): void;
|
|
106
|
-
export {};
|
package/dist/crypto_utils.js
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractPublicKeyFromCertificate = exports.extractPublicKeyFromCertificateSync = exports.rsa_length = 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.readPublicRsaKey = exports.readPrivateRsaKey = exports.read_sshkey_as_pem = exports.setCertificateStore = exports.makeSHA1Thumbprint = exports.verifyMessageChunkSignature = exports.makeMessageChunkSignature = exports.hexDump = exports.toPem = exports.readKeyPem = exports.readPrivateKeyPEM = exports.readPublicKeyPEM = exports.readCertificatePEM = exports.readPrivateKey = exports.readPublicKey = exports.readCertificate = exports.convertPEMtoDER = exports.identifyPemType = void 0;
|
|
4
|
-
// tslint:disabled:no-var-requires
|
|
5
|
-
/**
|
|
6
|
-
* @module node_opcua_crypto
|
|
7
|
-
*/
|
|
8
|
-
const constants = require("constants");
|
|
9
|
-
const crypto = require("crypto");
|
|
10
|
-
const fs = require("fs");
|
|
11
|
-
const path = require("path");
|
|
12
|
-
const buffer_utils_1 = require("./buffer_utils");
|
|
13
|
-
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
14
|
-
const assert = require("assert");
|
|
15
|
-
// tslint:disable:no-var-requires
|
|
16
|
-
const hexy = require("hexy");
|
|
17
|
-
const jsrsasign = require("jsrsasign");
|
|
18
|
-
const sshpk = require("sshpk");
|
|
19
|
-
const PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([\/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n)/gm;
|
|
20
|
-
const PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
|
|
21
|
-
// Copyright 2012 The Obvious Corporation.
|
|
22
|
-
// identifyPemType
|
|
23
|
-
/*=
|
|
24
|
-
* Extract and identify the PEM file type represented in the given
|
|
25
|
-
* buffer. Returns the extracted type string or undefined if the
|
|
26
|
-
* buffer doesn't seem to be any sort of PEM format file.
|
|
27
|
-
*/
|
|
28
|
-
function identifyPemType(rawKey) {
|
|
29
|
-
if (rawKey instanceof Buffer) {
|
|
30
|
-
rawKey = rawKey.toString("utf8");
|
|
31
|
-
}
|
|
32
|
-
const match = PEM_TYPE_REGEX.exec(rawKey);
|
|
33
|
-
return !match ? undefined : match[2];
|
|
34
|
-
}
|
|
35
|
-
exports.identifyPemType = identifyPemType;
|
|
36
|
-
function convertPEMtoDER(raw_key) {
|
|
37
|
-
let match;
|
|
38
|
-
let pemType;
|
|
39
|
-
let base64str;
|
|
40
|
-
const parts = [];
|
|
41
|
-
// tslint:disable-next-line:no-conditional-assignment
|
|
42
|
-
while ((match = PEM_REGEX.exec(raw_key)) !== null) {
|
|
43
|
-
pemType = match[2];
|
|
44
|
-
// pemType shall be "RSA PRIVATE KEY" , "PUBLIC KEY", "CERTIFICATE"
|
|
45
|
-
base64str = match[3];
|
|
46
|
-
base64str = base64str.replace(/\r?\n/g, "");
|
|
47
|
-
parts.push(Buffer.from(base64str, "base64"));
|
|
48
|
-
}
|
|
49
|
-
return crypto_explore_certificate_1.combine_der(parts);
|
|
50
|
-
}
|
|
51
|
-
exports.convertPEMtoDER = convertPEMtoDER;
|
|
52
|
-
function _readPemFile(filename) {
|
|
53
|
-
assert(typeof filename === "string");
|
|
54
|
-
return fs.readFileSync(filename, "ascii");
|
|
55
|
-
}
|
|
56
|
-
function _readPemOrDerFileAsDER(filename) {
|
|
57
|
-
if (filename.match(/.*\.der/)) {
|
|
58
|
-
return fs.readFileSync(filename);
|
|
59
|
-
}
|
|
60
|
-
const raw_key = _readPemFile(filename);
|
|
61
|
-
return convertPEMtoDER(raw_key);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* read a DER or PEM certificate from file
|
|
65
|
-
*/
|
|
66
|
-
function readCertificate(filename) {
|
|
67
|
-
return _readPemOrDerFileAsDER(filename);
|
|
68
|
-
}
|
|
69
|
-
exports.readCertificate = readCertificate;
|
|
70
|
-
/**
|
|
71
|
-
* read a DER or PEM certificate from file
|
|
72
|
-
*/
|
|
73
|
-
function readPublicKey(filename) {
|
|
74
|
-
return _readPemOrDerFileAsDER(filename);
|
|
75
|
-
}
|
|
76
|
-
exports.readPublicKey = readPublicKey;
|
|
77
|
-
/**
|
|
78
|
-
* read a DER or PEM certificate from file
|
|
79
|
-
*/
|
|
80
|
-
function readPrivateKey(filename) {
|
|
81
|
-
return _readPemOrDerFileAsDER(filename);
|
|
82
|
-
}
|
|
83
|
-
exports.readPrivateKey = readPrivateKey;
|
|
84
|
-
function readCertificatePEM(filename) {
|
|
85
|
-
return _readPemFile(filename);
|
|
86
|
-
}
|
|
87
|
-
exports.readCertificatePEM = readCertificatePEM;
|
|
88
|
-
function readPublicKeyPEM(filename) {
|
|
89
|
-
return _readPemFile(filename);
|
|
90
|
-
}
|
|
91
|
-
exports.readPublicKeyPEM = readPublicKeyPEM;
|
|
92
|
-
function readPrivateKeyPEM(filename) {
|
|
93
|
-
return _readPemFile(filename);
|
|
94
|
-
}
|
|
95
|
-
exports.readPrivateKeyPEM = readPrivateKeyPEM;
|
|
96
|
-
/**
|
|
97
|
-
* @method readKeyPem
|
|
98
|
-
* @param filename
|
|
99
|
-
*/
|
|
100
|
-
function readKeyPem(filename) {
|
|
101
|
-
const raw_key = fs.readFileSync(filename, "utf8");
|
|
102
|
-
const pemType = identifyPemType(raw_key);
|
|
103
|
-
assert(typeof pemType === "string"); // must have a valid pem type
|
|
104
|
-
return raw_key;
|
|
105
|
-
}
|
|
106
|
-
exports.readKeyPem = readKeyPem;
|
|
107
|
-
/**
|
|
108
|
-
* @method toPem
|
|
109
|
-
* @param raw_key
|
|
110
|
-
* @param pem
|
|
111
|
-
* @return
|
|
112
|
-
*/
|
|
113
|
-
function toPem(raw_key, pem) {
|
|
114
|
-
assert(raw_key, "expecting a key");
|
|
115
|
-
assert(typeof pem === "string");
|
|
116
|
-
let pemType = identifyPemType(raw_key);
|
|
117
|
-
if (pemType) {
|
|
118
|
-
return raw_key;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
pemType = pem;
|
|
122
|
-
assert(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
|
|
123
|
-
let b = raw_key.toString("base64");
|
|
124
|
-
let str = "-----BEGIN " + pemType + "-----\n";
|
|
125
|
-
while (b.length) {
|
|
126
|
-
str += b.substr(0, 64) + "\n";
|
|
127
|
-
b = b.substr(64);
|
|
128
|
-
}
|
|
129
|
-
str += "-----END " + pemType + "-----";
|
|
130
|
-
str += "\n";
|
|
131
|
-
return str;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.toPem = toPem;
|
|
135
|
-
// istanbul ignore next
|
|
136
|
-
function hexDump(buffer, width) {
|
|
137
|
-
if (!buffer) {
|
|
138
|
-
return "<>";
|
|
139
|
-
}
|
|
140
|
-
width = width || 32;
|
|
141
|
-
if (buffer.length > 1024) {
|
|
142
|
-
return hexy.hexy(buffer.slice(0, 1024), { width, format: "twos" }) + "\n .... ( " + buffer.length + ")";
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
return hexy.hexy(buffer, { width, format: "twos" });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.hexDump = hexDump;
|
|
149
|
-
/**
|
|
150
|
-
* @method makeMessageChunkSignature
|
|
151
|
-
* @param chunk
|
|
152
|
-
* @param options
|
|
153
|
-
* @param options.signatureLength
|
|
154
|
-
* @param options.algorithm for example "RSA-SHA256"
|
|
155
|
-
* @param options.privateKey
|
|
156
|
-
* @return - the signature
|
|
157
|
-
*/
|
|
158
|
-
function makeMessageChunkSignature(chunk, options) {
|
|
159
|
-
assert(options.hasOwnProperty("algorithm"));
|
|
160
|
-
assert(chunk instanceof Buffer);
|
|
161
|
-
assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(options.privateKey)) >= 0);
|
|
162
|
-
// signature length = 128 bytes
|
|
163
|
-
const signer = crypto.createSign(options.algorithm);
|
|
164
|
-
signer.update(chunk);
|
|
165
|
-
const signature = signer.sign(options.privateKey);
|
|
166
|
-
assert(!options.signatureLength || signature.length === options.signatureLength);
|
|
167
|
-
return signature; // Buffer
|
|
168
|
-
}
|
|
169
|
-
exports.makeMessageChunkSignature = makeMessageChunkSignature;
|
|
170
|
-
/**
|
|
171
|
-
* @method verifyMessageChunkSignature
|
|
172
|
-
*
|
|
173
|
-
* const signer = {
|
|
174
|
-
* signatureLength : 128,
|
|
175
|
-
* algorithm : "RSA-SHA256",
|
|
176
|
-
* publicKey: "qsdqsdqsd"
|
|
177
|
-
* };
|
|
178
|
-
* @param blockToVerify
|
|
179
|
-
* @param signature
|
|
180
|
-
* @param options
|
|
181
|
-
* @param options.signatureLength
|
|
182
|
-
* @param options.algorithm for example "RSA-SHA256"
|
|
183
|
-
* @param options.publicKey
|
|
184
|
-
* @return true if the signature is valid
|
|
185
|
-
*/
|
|
186
|
-
function verifyMessageChunkSignature(blockToVerify, signature, options) {
|
|
187
|
-
assert(blockToVerify instanceof Buffer);
|
|
188
|
-
assert(signature instanceof Buffer);
|
|
189
|
-
assert(typeof options.publicKey === "string");
|
|
190
|
-
assert(identifyPemType(options.publicKey));
|
|
191
|
-
const verify = crypto.createVerify(options.algorithm);
|
|
192
|
-
verify.update(blockToVerify);
|
|
193
|
-
return verify.verify(options.publicKey, signature);
|
|
194
|
-
}
|
|
195
|
-
exports.verifyMessageChunkSignature = verifyMessageChunkSignature;
|
|
196
|
-
function makeSHA1Thumbprint(buffer) {
|
|
197
|
-
return crypto.createHash("sha1").update(buffer).digest();
|
|
198
|
-
}
|
|
199
|
-
exports.makeSHA1Thumbprint = makeSHA1Thumbprint;
|
|
200
|
-
let __certificate_store = path.join(__dirname, "../../certificates/");
|
|
201
|
-
function setCertificateStore(store) {
|
|
202
|
-
const old_store = __certificate_store;
|
|
203
|
-
__certificate_store = store;
|
|
204
|
-
return old_store;
|
|
205
|
-
}
|
|
206
|
-
exports.setCertificateStore = setCertificateStore;
|
|
207
|
-
function read_sshkey_as_pem(filename) {
|
|
208
|
-
if (filename.substr(0, 1) !== ".") {
|
|
209
|
-
filename = __certificate_store + filename;
|
|
210
|
-
}
|
|
211
|
-
const key = fs.readFileSync(filename, "ascii");
|
|
212
|
-
const sshKey = sshpk.parseKey(key, "ssh");
|
|
213
|
-
return sshKey.toString("pkcs8");
|
|
214
|
-
}
|
|
215
|
-
exports.read_sshkey_as_pem = read_sshkey_as_pem;
|
|
216
|
-
/**
|
|
217
|
-
*
|
|
218
|
-
* @param filename
|
|
219
|
-
*/
|
|
220
|
-
function readPrivateRsaKey(filename) {
|
|
221
|
-
if (filename.substr(0, 1) !== "." && !fs.existsSync(filename)) {
|
|
222
|
-
filename = __certificate_store + filename;
|
|
223
|
-
}
|
|
224
|
-
return fs.readFileSync(filename, "ascii");
|
|
225
|
-
}
|
|
226
|
-
exports.readPrivateRsaKey = readPrivateRsaKey;
|
|
227
|
-
function readPublicRsaKey(filename) {
|
|
228
|
-
return readPrivateRsaKey(filename);
|
|
229
|
-
}
|
|
230
|
-
exports.readPublicRsaKey = readPublicRsaKey;
|
|
231
|
-
// Basically when you =encrypt something using an RSA key (whether public or private), the encrypted value must
|
|
232
|
-
// be smaller than the key (due to the maths used to do the actual encryption). So if you have a 1024-bit key,
|
|
233
|
-
// in theory you could encrypt any 1023-bit value (or a 1024-bit value smaller than the key) with that key.
|
|
234
|
-
// However, the PKCS#1 standard, which OpenSSL uses, specifies a padding scheme (so you can encrypt smaller
|
|
235
|
-
// quantities without losing security), and that padding scheme takes a minimum of 11 bytes (it will be longer
|
|
236
|
-
// if the value you're encrypting is smaller). So the highest number of bits you can encrypt with a 1024-bit
|
|
237
|
-
// key is 936 bits because of this (unless you disable the padding by adding the OPENSSL_NO_PADDING flag,
|
|
238
|
-
// in which case you can go up to 1023-1024 bits). With a 2048-bit key it's 1960 bits instead.
|
|
239
|
-
exports.RSA_PKCS1_OAEP_PADDING = constants.RSA_PKCS1_OAEP_PADDING;
|
|
240
|
-
exports.RSA_PKCS1_PADDING = constants.RSA_PKCS1_PADDING;
|
|
241
|
-
var PaddingAlgorithm;
|
|
242
|
-
(function (PaddingAlgorithm) {
|
|
243
|
-
PaddingAlgorithm[PaddingAlgorithm["RSA_PKCS1_OAEP_PADDING"] = 4] = "RSA_PKCS1_OAEP_PADDING";
|
|
244
|
-
PaddingAlgorithm[PaddingAlgorithm["RSA_PKCS1_PADDING"] = 1] = "RSA_PKCS1_PADDING";
|
|
245
|
-
})(PaddingAlgorithm = exports.PaddingAlgorithm || (exports.PaddingAlgorithm = {}));
|
|
246
|
-
assert(PaddingAlgorithm.RSA_PKCS1_OAEP_PADDING === constants.RSA_PKCS1_OAEP_PADDING);
|
|
247
|
-
assert(PaddingAlgorithm.RSA_PKCS1_PADDING === constants.RSA_PKCS1_PADDING);
|
|
248
|
-
// publicEncrypt and privateDecrypt only work with
|
|
249
|
-
// small buffer that depends of the key size.
|
|
250
|
-
function publicEncrypt_native(buffer, publicKey, algorithm) {
|
|
251
|
-
if (algorithm === undefined) {
|
|
252
|
-
algorithm = PaddingAlgorithm.RSA_PKCS1_PADDING;
|
|
253
|
-
}
|
|
254
|
-
assert(algorithm === exports.RSA_PKCS1_PADDING || algorithm === exports.RSA_PKCS1_OAEP_PADDING);
|
|
255
|
-
assert(buffer instanceof Buffer, "Expecting a buffer");
|
|
256
|
-
return crypto.publicEncrypt({
|
|
257
|
-
key: publicKey,
|
|
258
|
-
padding: algorithm,
|
|
259
|
-
}, buffer);
|
|
260
|
-
}
|
|
261
|
-
exports.publicEncrypt_native = publicEncrypt_native;
|
|
262
|
-
function privateDecrypt_native(buffer, privateKey, algorithm) {
|
|
263
|
-
if (algorithm === undefined) {
|
|
264
|
-
algorithm = PaddingAlgorithm.RSA_PKCS1_PADDING;
|
|
265
|
-
}
|
|
266
|
-
assert(algorithm === exports.RSA_PKCS1_PADDING || algorithm === exports.RSA_PKCS1_OAEP_PADDING);
|
|
267
|
-
assert(buffer instanceof Buffer, "Expecting a buffer");
|
|
268
|
-
try {
|
|
269
|
-
return crypto.privateDecrypt({
|
|
270
|
-
key: privateKey,
|
|
271
|
-
padding: algorithm,
|
|
272
|
-
}, buffer);
|
|
273
|
-
}
|
|
274
|
-
catch (err) {
|
|
275
|
-
return Buffer.alloc(1);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
exports.privateDecrypt_native = privateDecrypt_native;
|
|
279
|
-
exports.publicEncrypt = publicEncrypt_native;
|
|
280
|
-
exports.privateDecrypt = privateDecrypt_native;
|
|
281
|
-
function publicEncrypt_long(buffer, publicKey, blockSize, padding, algorithm) {
|
|
282
|
-
if (algorithm === undefined) {
|
|
283
|
-
algorithm = PaddingAlgorithm.RSA_PKCS1_PADDING;
|
|
284
|
-
}
|
|
285
|
-
assert(algorithm === exports.RSA_PKCS1_PADDING || algorithm === exports.RSA_PKCS1_OAEP_PADDING);
|
|
286
|
-
const chunk_size = blockSize - padding;
|
|
287
|
-
const nbBlocks = Math.ceil(buffer.length / chunk_size);
|
|
288
|
-
const outputBuffer = buffer_utils_1.createFastUninitializedBuffer(nbBlocks * blockSize);
|
|
289
|
-
for (let i = 0; i < nbBlocks; i++) {
|
|
290
|
-
const currentBlock = buffer.slice(chunk_size * i, chunk_size * (i + 1));
|
|
291
|
-
const encrypted_chunk = exports.publicEncrypt(currentBlock, publicKey, algorithm);
|
|
292
|
-
assert(encrypted_chunk.length === blockSize);
|
|
293
|
-
encrypted_chunk.copy(outputBuffer, i * blockSize);
|
|
294
|
-
}
|
|
295
|
-
return outputBuffer;
|
|
296
|
-
}
|
|
297
|
-
exports.publicEncrypt_long = publicEncrypt_long;
|
|
298
|
-
function privateDecrypt_long(buffer, privateKey, blockSize, algorithm) {
|
|
299
|
-
algorithm = algorithm || exports.RSA_PKCS1_PADDING;
|
|
300
|
-
assert(algorithm === exports.RSA_PKCS1_PADDING || algorithm === exports.RSA_PKCS1_OAEP_PADDING);
|
|
301
|
-
const nbBlocks = Math.ceil(buffer.length / blockSize);
|
|
302
|
-
const outputBuffer = buffer_utils_1.createFastUninitializedBuffer(nbBlocks * blockSize);
|
|
303
|
-
let total_length = 0;
|
|
304
|
-
for (let i = 0; i < nbBlocks; i++) {
|
|
305
|
-
const currentBlock = buffer.slice(blockSize * i, Math.min(blockSize * (i + 1), buffer.length));
|
|
306
|
-
const decrypted_buf = exports.privateDecrypt(currentBlock, privateKey, algorithm);
|
|
307
|
-
decrypted_buf.copy(outputBuffer, total_length);
|
|
308
|
-
total_length += decrypted_buf.length;
|
|
309
|
-
}
|
|
310
|
-
return outputBuffer.slice(0, total_length);
|
|
311
|
-
}
|
|
312
|
-
exports.privateDecrypt_long = privateDecrypt_long;
|
|
313
|
-
function coerceCertificatePem(certificate) {
|
|
314
|
-
if (certificate instanceof Buffer) {
|
|
315
|
-
certificate = toPem(certificate, "CERTIFICATE");
|
|
316
|
-
}
|
|
317
|
-
assert(typeof certificate === "string");
|
|
318
|
-
return certificate;
|
|
319
|
-
}
|
|
320
|
-
exports.coerceCertificatePem = coerceCertificatePem;
|
|
321
|
-
function coercePublicKeyPem(publicKey) {
|
|
322
|
-
if (publicKey instanceof Buffer) {
|
|
323
|
-
publicKey = toPem(publicKey, "PUBLIC KEY");
|
|
324
|
-
}
|
|
325
|
-
assert(typeof publicKey === "string");
|
|
326
|
-
return publicKey;
|
|
327
|
-
}
|
|
328
|
-
exports.coercePublicKeyPem = coercePublicKeyPem;
|
|
329
|
-
/***
|
|
330
|
-
* @method rsa_length
|
|
331
|
-
* A very expensive way to determine the rsa key length ( i.e 2048bits or 1024bits)
|
|
332
|
-
* @param key a PEM public key or a PEM rsa private key
|
|
333
|
-
* @return { the key length in bytes.
|
|
334
|
-
*/
|
|
335
|
-
function rsa_length(key) {
|
|
336
|
-
key = coercePublicKeyPem(key);
|
|
337
|
-
assert(typeof key === "string");
|
|
338
|
-
const a = jsrsasign.KEYUTIL.getKey(key);
|
|
339
|
-
return a.n.toString(16).length / 2;
|
|
340
|
-
}
|
|
341
|
-
exports.rsa_length = rsa_length;
|
|
342
|
-
function extractPublicKeyFromCertificateSync(certificate) {
|
|
343
|
-
certificate = coerceCertificatePem(certificate);
|
|
344
|
-
const key = jsrsasign.KEYUTIL.getKey(certificate);
|
|
345
|
-
const publicKeyAsPem = jsrsasign.KEYUTIL.getPEM(key);
|
|
346
|
-
assert(typeof publicKeyAsPem === "string");
|
|
347
|
-
return publicKeyAsPem;
|
|
348
|
-
}
|
|
349
|
-
exports.extractPublicKeyFromCertificateSync = extractPublicKeyFromCertificateSync;
|
|
350
|
-
// https://github.com/kjur/jsrsasign/blob/master/x509-1.1.js
|
|
351
|
-
// tool to analyse asn1 base64 blocks : http://lapo.it/asn1js
|
|
352
|
-
/**
|
|
353
|
-
* extract the publickey from a certificate
|
|
354
|
-
* @async
|
|
355
|
-
*/
|
|
356
|
-
function extractPublicKeyFromCertificate(certificate, callback) {
|
|
357
|
-
let err1 = null;
|
|
358
|
-
let keyPem;
|
|
359
|
-
try {
|
|
360
|
-
keyPem = extractPublicKeyFromCertificateSync(certificate);
|
|
361
|
-
}
|
|
362
|
-
catch (err) {
|
|
363
|
-
err1 = err;
|
|
364
|
-
}
|
|
365
|
-
setImmediate(() => {
|
|
366
|
-
callback(err1, keyPem);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
exports.extractPublicKeyFromCertificate = extractPublicKeyFromCertificate;
|
|
370
|
-
//# sourceMappingURL=crypto_utils.js.map
|
package/dist/crypto_utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto_utils.js","sourceRoot":"","sources":["../lib/crypto_utils.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC;;GAEG;AACH,uCAAuC;AACvC,iCAAiC;AACjC,yBAAyB;AACzB,6BAA6B;AAC7B,iDAA+D;AAE/D,6EAA2D;AAC3D,iCAAiC;AAEjC,iCAAiC;AACjC,6BAA8B;AAC9B,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/B,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,E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;IAC9B,MAAM,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,CAAC;AALD,gCAKC;AAED,SAAgB,mCAAmC,CAAC,WAAyC;IACzF,WAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACrD,MAAM,CAAC,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC;IAC3C,OAAO,cAAc,CAAC;AAC1B,CAAC;AAND,kFAMC;AAED,4DAA4D;AAC5D,6DAA6D;AAC7D;;;GAGG;AACH,SAAgB,+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"}
|
package/dist/derived_keys.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Nonce } from "./common";
|
|
3
|
-
import { VerifyMessageChunkSignatureOptions } from "./crypto_utils";
|
|
4
|
-
export declare function makePseudoRandomBuffer(secret: Nonce, seed: Nonce, minLength: number, sha1or256: "SHA1" | "SHA256"): Buffer;
|
|
5
|
-
export interface ComputeDerivedKeysOptions {
|
|
6
|
-
signatureLength: number;
|
|
7
|
-
signingKeyLength: number;
|
|
8
|
-
encryptingKeyLength: number;
|
|
9
|
-
encryptingBlockSize: number;
|
|
10
|
-
algorithm: string;
|
|
11
|
-
sha1or256?: "SHA1" | "SHA256";
|
|
12
|
-
}
|
|
13
|
-
export interface DerivedKeys extends ComputeDerivedKeysOptions {
|
|
14
|
-
signatureLength: number;
|
|
15
|
-
signingKeyLength: number;
|
|
16
|
-
encryptingKeyLength: number;
|
|
17
|
-
encryptingBlockSize: number;
|
|
18
|
-
algorithm: string;
|
|
19
|
-
sha1or256: "SHA1" | "SHA256";
|
|
20
|
-
signingKey: Buffer;
|
|
21
|
-
encryptingKey: Buffer;
|
|
22
|
-
initializationVector: Buffer;
|
|
23
|
-
}
|
|
24
|
-
export declare function computeDerivedKeys(secret: Nonce, seed: Nonce, options: ComputeDerivedKeysOptions): DerivedKeys;
|
|
25
|
-
/**
|
|
26
|
-
* @method reduceLength
|
|
27
|
-
* @param buffer
|
|
28
|
-
* @param byteToRemove
|
|
29
|
-
* @return buffer
|
|
30
|
-
*/
|
|
31
|
-
export declare function reduceLength(buffer: Buffer, byteToRemove: number): Buffer;
|
|
32
|
-
/**
|
|
33
|
-
* @method removePadding
|
|
34
|
-
* @param buffer
|
|
35
|
-
* @return buffer with padding removed
|
|
36
|
-
*/
|
|
37
|
-
export declare function removePadding(buffer: Buffer): Buffer;
|
|
38
|
-
export declare type VerifyChunkSignatureOptions = VerifyMessageChunkSignatureOptions;
|
|
39
|
-
/**
|
|
40
|
-
* @method verifyChunkSignature
|
|
41
|
-
*
|
|
42
|
-
* const signer = {
|
|
43
|
-
* signatureLength : 128,
|
|
44
|
-
* algorithm : "RSA-SHA256",
|
|
45
|
-
* public_key: "qsdqsdqsd"
|
|
46
|
-
* };
|
|
47
|
-
*
|
|
48
|
-
* @param chunk The message chunk to verify.
|
|
49
|
-
* @param options
|
|
50
|
-
* @param options.signatureLength
|
|
51
|
-
* @param options.algorithm the algorithm.
|
|
52
|
-
* @param options.publicKey
|
|
53
|
-
* @return {*}
|
|
54
|
-
*/
|
|
55
|
-
export declare function verifyChunkSignature(chunk: Buffer, options: VerifyChunkSignatureOptions): boolean;
|
|
56
|
-
export declare function computePaddingFooter(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
|
|
57
|
-
export declare function encryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
|
|
58
|
-
export declare function decryptBufferWithDerivedKeys(buffer: Buffer, derivedKeys: DerivedKeys): Buffer;
|
|
59
|
-
/**
|
|
60
|
-
* @method makeMessageChunkSignatureWithDerivedKeys
|
|
61
|
-
* @param message
|
|
62
|
-
* @param derivedKeys
|
|
63
|
-
* @return
|
|
64
|
-
*/
|
|
65
|
-
export declare function makeMessageChunkSignatureWithDerivedKeys(message: Buffer, derivedKeys: DerivedKeys): Buffer;
|
|
66
|
-
/**
|
|
67
|
-
* @method verifyChunkSignatureWithDerivedKeys
|
|
68
|
-
* @param chunk
|
|
69
|
-
* @param derivedKeys
|
|
70
|
-
* @return
|
|
71
|
-
*/
|
|
72
|
-
export declare function verifyChunkSignatureWithDerivedKeys(chunk: Buffer, derivedKeys: DerivedKeys): boolean;
|