node-opcua-crypto 2.1.2 → 3.0.0-beta.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 +109 -106
- package/.prettierrc.js +6 -6
- package/LICENSE +23 -23
- package/README.md +14 -14
- package/_tmp_certificate.pem +20 -0
- package/_tmp_csr.pem +17 -0
- package/_tmp_privatekey.der +0 -0
- package/_tmp_privatekey.pem +28 -0
- package/dist/source/asn1.d.ts +73 -73
- package/dist/source/asn1.js +359 -359
- package/dist/source/asn1.js.map +1 -1
- package/dist/source/buffer_utils.d.ts +5 -6
- package/dist/source/buffer_utils.js +21 -21
- package/dist/source/common.d.ts +20 -14
- package/dist/source/common.js +10 -2
- package/dist/source/common.js.map +1 -1
- package/dist/source/create_key_pair.d.ts +42 -0
- package/dist/source/create_key_pair.js +136 -0
- package/dist/source/create_key_pair.js.map +1 -0
- package/dist/source/crypto_explore_certificate.d.ts +107 -107
- package/dist/source/crypto_explore_certificate.js +601 -601
- package/dist/source/crypto_utils.d.ts +76 -76
- package/dist/source/crypto_utils.js +329 -329
- 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 +95 -97
- package/dist/source/explore_private_key.js.map +1 -1
- package/dist/source/index.d.ts +17 -13
- package/dist/source/index.js +33 -29
- package/dist/source/index.js.map +1 -1
- 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 +36 -36
- package/dist/source/subject.d.ts +27 -0
- package/dist/source/subject.js +125 -0
- package/dist/source/subject.js.map +1 -0
- package/dist/source/verify_certificate_signature.d.ts +10 -10
- package/dist/source/verify_certificate_signature.js +101 -101
- package/dist/source/x509/_build_public_key.d.ts +1 -0
- package/dist/source/x509/_build_public_key.js +36 -0
- package/dist/source/x509/_build_public_key.js.map +1 -0
- package/dist/source/x509/_crypto.d.ts +3 -0
- package/dist/source/x509/_crypto.js +9 -0
- package/dist/source/x509/_crypto.js.map +1 -0
- package/dist/source/x509/_fix.d.ts +2 -0
- package/dist/source/x509/_fix.js +74 -0
- package/dist/source/x509/_fix.js.map +1 -0
- package/dist/source/x509/_get_attributes.d.ts +8 -0
- package/dist/source/x509/_get_attributes.js +56 -0
- package/dist/source/x509/_get_attributes.js.map +1 -0
- package/dist/source/x509/_internals.d.ts +0 -0
- package/dist/source/x509/_internals.js +2 -0
- package/dist/source/x509/_internals.js.map +1 -0
- package/dist/source/x509/create_certificate_signing_request.d.ts +18 -0
- package/dist/source/x509/create_certificate_signing_request.js +53 -0
- package/dist/source/x509/create_certificate_signing_request.js.map +1 -0
- package/dist/source/x509/create_key_pair.d.ts +28 -0
- package/dist/source/x509/create_key_pair.js +62 -0
- package/dist/source/x509/create_key_pair.js.map +1 -0
- package/dist/source/x509/create_self_signed_certificate.d.ts +17 -0
- package/dist/source/x509/create_self_signed_certificate.js +71 -0
- package/dist/source/x509/create_self_signed_certificate.js.map +1 -0
- package/dist/source_nodejs/generate_private_key_filename.d.ts +1 -0
- package/dist/source_nodejs/generate_private_key_filename.js +25 -0
- package/dist/source_nodejs/generate_private_key_filename.js.map +1 -0
- package/dist/source_nodejs/index.d.ts +4 -3
- package/dist/source_nodejs/index.js +20 -19
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/read.d.ts +23 -23
- package/dist/source_nodejs/read.js +106 -106
- 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 +15 -9
- package/source/asn1.ts +404 -404
- package/source/buffer_utils.ts +18 -18
- package/source/common.ts +7 -0
- package/source/crypto_explore_certificate.ts +764 -764
- 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 +1 -2
- package/source/index.ts +17 -13
- package/source/oid_map.ts +310 -310
- package/source/subject.ts +144 -0
- package/source/verify_certificate_signature.ts +105 -105
- package/source/x509/_build_public_key.ts +25 -0
- package/source/x509/_crypto.ts +5 -0
- package/source/x509/_get_attributes.ts +60 -0
- package/source/x509/create_certificate_signing_request.ts +64 -0
- package/source/x509/create_key_pair.ts +70 -0
- package/source/x509/create_self_signed_certificate.ts +91 -0
- package/source_nodejs/generate_private_key_filename.ts +10 -0
- package/source_nodejs/index.ts +4 -3
- 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 +19 -18
- package/tslint.json +34 -34
- package/dist/source/certificate_matches_private_key.d.ts +0 -2
- package/dist/source/certificate_matches_private_key.js +0 -22
- package/dist/source/certificate_matches_private_key.js.map +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Certificate, PrivateKey } from "./common";
|
|
2
|
-
export declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
3
|
-
export declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
1
|
+
import { Certificate, PrivateKey } from "./common";
|
|
2
|
+
export declare function publicKeyAndPrivateKeyMatches(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
3
|
+
export declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.certificateMatchesPrivateKey = exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
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");
|
|
7
|
-
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
8
|
-
const i = (0, crypto_explore_certificate_1.exploreCertificate)(certificate);
|
|
9
|
-
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
10
|
-
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
11
|
-
const modulus2 = j.modulus;
|
|
12
|
-
if (modulus1.length != modulus2.length) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
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
|
-
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
35
|
-
}
|
|
36
|
-
exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.certificateMatchesPrivateKey = exports.publicKeyAndPrivateKeyMatches = void 0;
|
|
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");
|
|
7
|
+
function publicKeyAndPrivateKeyMatches(certificate, privateKey) {
|
|
8
|
+
const i = (0, crypto_explore_certificate_1.exploreCertificate)(certificate);
|
|
9
|
+
const j = (0, explore_private_key_1.explorePrivateKey)(privateKey);
|
|
10
|
+
const modulus1 = i.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.modulus;
|
|
11
|
+
const modulus2 = j.modulus;
|
|
12
|
+
if (modulus1.length != modulus2.length) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return modulus1.toString("hex") === modulus2.toString("hex");
|
|
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
|
+
return certificateMatchesPrivateKeyPEM(certificatePEM, privateKey, blockSize);
|
|
35
|
+
}
|
|
36
|
+
exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
|
|
37
37
|
//# sourceMappingURL=public_private_match.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface SubjectOptions {
|
|
2
|
+
commonName?: string;
|
|
3
|
+
organization?: string;
|
|
4
|
+
organizationalUnit?: string;
|
|
5
|
+
locality?: string;
|
|
6
|
+
state?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
domainComponent?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* subjectName The subject name to use for the Certificate.
|
|
12
|
+
* If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Subject implements SubjectOptions {
|
|
15
|
+
readonly commonName?: string;
|
|
16
|
+
readonly organization?: string;
|
|
17
|
+
readonly organizationalUnit?: string;
|
|
18
|
+
readonly locality?: string;
|
|
19
|
+
readonly state?: string;
|
|
20
|
+
readonly country?: string;
|
|
21
|
+
readonly domainComponent?: string;
|
|
22
|
+
constructor(options: SubjectOptions | string);
|
|
23
|
+
static parse(str: string): SubjectOptions;
|
|
24
|
+
toStringInternal(sep: string): string;
|
|
25
|
+
toStringForOPCUA(): string;
|
|
26
|
+
toString(): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
3
|
+
// node-opcua-pki
|
|
4
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
|
|
6
|
+
// Copyright (c) 2022 - Sterfive.com
|
|
7
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
8
|
+
//
|
|
9
|
+
// This project is licensed under the terms of the MIT license.
|
|
10
|
+
//
|
|
11
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
12
|
+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
13
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
14
|
+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
15
|
+
//
|
|
16
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
17
|
+
// Software.
|
|
18
|
+
//
|
|
19
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
20
|
+
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
21
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
22
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.Subject = void 0;
|
|
26
|
+
const _keys = {
|
|
27
|
+
C: "country",
|
|
28
|
+
CN: "commonName",
|
|
29
|
+
DC: "domainComponent",
|
|
30
|
+
L: "locality",
|
|
31
|
+
O: "organization",
|
|
32
|
+
OU: "organizationalUnit",
|
|
33
|
+
ST: "state",
|
|
34
|
+
};
|
|
35
|
+
const enquoteIfNecessary = (str) => {
|
|
36
|
+
str = str.replace(/"/g, "”");
|
|
37
|
+
return str.match(/\/|=/) ? `"${str}"` : str;
|
|
38
|
+
};
|
|
39
|
+
const unquote = (str) => str.replace(/"/gm, "");
|
|
40
|
+
const unquote2 = (str) => {
|
|
41
|
+
if (!str)
|
|
42
|
+
return str;
|
|
43
|
+
const m = str.match(/^"(.*)"$/);
|
|
44
|
+
return m ? m[1] : str;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* subjectName The subject name to use for the Certificate.
|
|
48
|
+
* If not specified the ApplicationName and/or domainNames are used to create a suitable default value.
|
|
49
|
+
*/
|
|
50
|
+
class Subject {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
if (typeof options === "string") {
|
|
53
|
+
options = Subject.parse(options);
|
|
54
|
+
}
|
|
55
|
+
this.commonName = unquote2(options.commonName);
|
|
56
|
+
this.organization = unquote2(options.organization);
|
|
57
|
+
this.organizationalUnit = unquote2(options.organizationalUnit);
|
|
58
|
+
this.locality = unquote2(options.locality);
|
|
59
|
+
this.state = unquote2(options.state);
|
|
60
|
+
this.country = unquote2(options.country);
|
|
61
|
+
this.domainComponent = unquote2(options.domainComponent);
|
|
62
|
+
}
|
|
63
|
+
static parse(str) {
|
|
64
|
+
const elements = str.split(/\/(?=[^/]*?=)/);
|
|
65
|
+
const options = {};
|
|
66
|
+
elements.forEach((element) => {
|
|
67
|
+
if (element.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const s = element.split("=");
|
|
71
|
+
if (s.length !== 2) {
|
|
72
|
+
throw new Error("invalid format for " + element);
|
|
73
|
+
}
|
|
74
|
+
const longName = _keys[s[0]];
|
|
75
|
+
if (!longName) {
|
|
76
|
+
throw new Error("Invalid field found in subject name " + s[0]);
|
|
77
|
+
}
|
|
78
|
+
const value = s[1];
|
|
79
|
+
options[longName] = unquote(Buffer.from(value, "ascii").toString("utf8"));
|
|
80
|
+
});
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
toStringInternal(sep) {
|
|
84
|
+
// https://reference.opcfoundation.org/v104/GDS/docs/7.6.4/
|
|
85
|
+
// The format of the subject name is a sequence of name value pairs separated by a ‘/’.
|
|
86
|
+
// The name shall be one of ‘CN’, ‘O’, ‘OU’, ‘DC’, ‘L’, ‘S’ or ‘C’ and
|
|
87
|
+
// shall be followed by a ‘=’ and then followed by the value.
|
|
88
|
+
// The value may be any printable character except for ‘”’.
|
|
89
|
+
// If the value contains a ‘/’ or a ‘=’ then it shall be enclosed in double quotes (‘”’).
|
|
90
|
+
const tmp = [];
|
|
91
|
+
if (this.country) {
|
|
92
|
+
tmp.push("C=" + enquoteIfNecessary(this.country));
|
|
93
|
+
}
|
|
94
|
+
if (this.state) {
|
|
95
|
+
tmp.push("ST=" + enquoteIfNecessary(this.state));
|
|
96
|
+
}
|
|
97
|
+
if (this.locality) {
|
|
98
|
+
tmp.push("L=" + enquoteIfNecessary(this.locality));
|
|
99
|
+
}
|
|
100
|
+
if (this.organization) {
|
|
101
|
+
tmp.push("O=" + enquoteIfNecessary(this.organization));
|
|
102
|
+
}
|
|
103
|
+
if (this.organizationalUnit) {
|
|
104
|
+
tmp.push("OU=" + enquoteIfNecessary(this.organizationalUnit));
|
|
105
|
+
}
|
|
106
|
+
if (this.commonName) {
|
|
107
|
+
tmp.push("CN=" + enquoteIfNecessary(this.commonName));
|
|
108
|
+
}
|
|
109
|
+
if (this.domainComponent) {
|
|
110
|
+
tmp.push("DC=" + enquoteIfNecessary(this.domainComponent));
|
|
111
|
+
}
|
|
112
|
+
return tmp.join(sep);
|
|
113
|
+
}
|
|
114
|
+
toStringForOPCUA() {
|
|
115
|
+
return this.toStringInternal("/");
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
// standard for SSL is to have a / in front of each Field
|
|
119
|
+
// see https://www.digicert.com/kb/ssl-support/openssl-quick-reference-guide.htm
|
|
120
|
+
const t = this.toStringForOPCUA();
|
|
121
|
+
return t ? "/" + t : t;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.Subject = Subject;
|
|
125
|
+
//# sourceMappingURL=subject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subject.js","sourceRoot":"","sources":["../../source/subject.ts"],"names":[],"mappings":";AAAA,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AACxH,gFAAgF;AAChF,oCAAoC;AACpC,wHAAwH;AACxH,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,+GAA+G;AAC/G,sHAAsH;AACtH,kHAAkH;AAClH,mGAAmG;AACnG,EAAE;AACF,uHAAuH;AACvH,YAAY;AACZ,EAAE;AACF,uHAAuH;AACvH,wHAAwH;AACxH,mHAAmH;AACnH,mHAAmH;AACnH,wHAAwH;;;AAYxH,MAAM,KAAK,GAAG;IACV,CAAC,EAAE,SAAS;IACZ,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,iBAAiB;IACrB,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,cAAc;IACjB,EAAE,EAAE,oBAAoB;IACxB,EAAE,EAAE,OAAO;CACd,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE;IACvC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAChD,CAAC,CAAC;AACF,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,C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;YACnB,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;SAC1D;QACD,IAAI,IAAI,CAAC,kBAAkB,EAAE;YACzB,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;SACjE;QACD,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;SACzD;QACD,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;SAC9D;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACM,gBAAgB;QACnB,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IACM,QAAQ;QACX,yDAAyD;QACzD,gFAAgF;QAChF,MAAM,CAAC,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;CACJ;AAtFD,0BAsFC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Certificate } from "./common";
|
|
3
|
-
export declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
4
|
-
export declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
5
|
-
export declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
6
|
-
export type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
7
|
-
export declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
8
|
-
status: _VerifyStatus;
|
|
9
|
-
reason: string;
|
|
10
|
-
}>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Certificate } from "./common";
|
|
3
|
+
export declare function verifyCertificateOrClrSignature(certificateOrCrl: Buffer, parentCertificate: Certificate): boolean;
|
|
4
|
+
export declare function verifyCertificateSignature(certificate: Certificate, parentCertificate: Certificate): boolean;
|
|
5
|
+
export declare function verifyCertificateRevocationListSignature(certificateRevocationList: Certificate, parentCertificate: Certificate): boolean;
|
|
6
|
+
export type _VerifyStatus = "BadCertificateIssuerUseNotAllowed" | "BadCertificateInvalid" | "Good";
|
|
7
|
+
export declare function verifyCertificateChain(certificateChain: Certificate[]): Promise<{
|
|
8
|
+
status: _VerifyStatus;
|
|
9
|
+
reason: string;
|
|
10
|
+
}>;
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// tslint:disable: no-console
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.verifyCertificateChain = exports.verifyCertificateRevocationListSignature = exports.verifyCertificateSignature = exports.verifyCertificateOrClrSignature = void 0;
|
|
14
|
-
// Now that we got a hash of the original certificate,
|
|
15
|
-
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
16
|
-
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
17
|
-
// the signed certificate. Which, in our case, is everything but the signature.
|
|
18
|
-
// The start of the body is always the first digit of the second line of the following command:
|
|
19
|
-
const crypto = require("crypto");
|
|
20
|
-
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
21
|
-
const crypto_utils_1 = require("./crypto_utils");
|
|
22
|
-
const asn1_1 = require("./asn1");
|
|
23
|
-
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
24
|
-
const block_info = (0, asn1_1.readTag)(certificateOrCrl, 0);
|
|
25
|
-
const blocks = (0, asn1_1._readStruct)(certificateOrCrl, block_info);
|
|
26
|
-
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
27
|
-
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
28
|
-
const signatureAlgorithm = (0, asn1_1._readAlgorithmIdentifier)(certificateOrCrl, blocks[1]);
|
|
29
|
-
const signatureValue = (0, asn1_1._readSignatureValueBin)(certificateOrCrl, blocks[2]);
|
|
30
|
-
const p = (0, crypto_explore_certificate_1.split_der)(parentCertificate)[0];
|
|
31
|
-
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
32
|
-
const certPem = (0, crypto_utils_1.toPem)(p, "CERTIFICATE");
|
|
33
|
-
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
34
|
-
verify.update(bufferToBeSigned);
|
|
35
|
-
verify.end();
|
|
36
|
-
return verify.verify(certPem, signatureValue);
|
|
37
|
-
}
|
|
38
|
-
exports.verifyCertificateOrClrSignature = verifyCertificateOrClrSignature;
|
|
39
|
-
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
40
|
-
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
41
|
-
}
|
|
42
|
-
exports.verifyCertificateSignature = verifyCertificateSignature;
|
|
43
|
-
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
44
|
-
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
45
|
-
}
|
|
46
|
-
exports.verifyCertificateRevocationListSignature = verifyCertificateRevocationListSignature;
|
|
47
|
-
function verifyCertificateChain(certificateChain) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
// verify that all the certificate
|
|
50
|
-
// second certificate must be used for CertificateSign
|
|
51
|
-
for (let index = 1; index < certificateChain.length; index++) {
|
|
52
|
-
const cert = certificateChain[index - 1];
|
|
53
|
-
const certParent = certificateChain[index];
|
|
54
|
-
// parent child must have keyCertSign
|
|
55
|
-
const certParentInfo = (0, crypto_explore_certificate_1.exploreCertificate)(certParent);
|
|
56
|
-
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
57
|
-
// istanbul ignore next
|
|
58
|
-
if (!keyUsage.keyCertSign) {
|
|
59
|
-
return {
|
|
60
|
-
status: "BadCertificateIssuerUseNotAllowed",
|
|
61
|
-
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
65
|
-
if (!parentSignChild) {
|
|
66
|
-
return {
|
|
67
|
-
status: "BadCertificateInvalid",
|
|
68
|
-
reason: "One of the certificate in the chain is not signing the previous certificate",
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const certInfo = (0, crypto_explore_certificate_1.exploreCertificate)(cert);
|
|
72
|
-
// istanbul ignore next
|
|
73
|
-
if (!certInfo.tbsCertificate.extensions) {
|
|
74
|
-
return {
|
|
75
|
-
status: "BadCertificateInvalid",
|
|
76
|
-
reason: "Cannot find X409 Extension 3 in certificate",
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
// istanbul ignore next
|
|
80
|
-
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
81
|
-
return {
|
|
82
|
-
status: "BadCertificateInvalid",
|
|
83
|
-
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
// istanbul ignore next
|
|
87
|
-
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
88
|
-
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
89
|
-
return {
|
|
90
|
-
status: "BadCertificateInvalid",
|
|
91
|
-
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
status: "Good",
|
|
97
|
-
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
exports.verifyCertificateChain = verifyCertificateChain;
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable: no-console
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.verifyCertificateChain = exports.verifyCertificateRevocationListSignature = exports.verifyCertificateSignature = exports.verifyCertificateOrClrSignature = void 0;
|
|
14
|
+
// Now that we got a hash of the original certificate,
|
|
15
|
+
// we need to verify if we can obtain the same hash by using the same hashing function
|
|
16
|
+
// (in this case SHA-384). In order to do that, we need to extract just the body of
|
|
17
|
+
// the signed certificate. Which, in our case, is everything but the signature.
|
|
18
|
+
// The start of the body is always the first digit of the second line of the following command:
|
|
19
|
+
const crypto = require("crypto");
|
|
20
|
+
const crypto_explore_certificate_1 = require("./crypto_explore_certificate");
|
|
21
|
+
const crypto_utils_1 = require("./crypto_utils");
|
|
22
|
+
const asn1_1 = require("./asn1");
|
|
23
|
+
function verifyCertificateOrClrSignature(certificateOrCrl, parentCertificate) {
|
|
24
|
+
const block_info = (0, asn1_1.readTag)(certificateOrCrl, 0);
|
|
25
|
+
const blocks = (0, asn1_1._readStruct)(certificateOrCrl, block_info);
|
|
26
|
+
const bufferToBeSigned = certificateOrCrl.slice(block_info.position, blocks[1].position - 2);
|
|
27
|
+
//xx console.log("bufferToBeSigned = ", bufferToBeSigned.length, bufferToBeSigned.toString("hex").substr(0, 50), bufferToBeSigned.toString("hex").substr(-10));
|
|
28
|
+
const signatureAlgorithm = (0, asn1_1._readAlgorithmIdentifier)(certificateOrCrl, blocks[1]);
|
|
29
|
+
const signatureValue = (0, asn1_1._readSignatureValueBin)(certificateOrCrl, blocks[2]);
|
|
30
|
+
const p = (0, crypto_explore_certificate_1.split_der)(parentCertificate)[0];
|
|
31
|
+
//xx const publicKey = extractPublicKeyFromCertificateSync(p);
|
|
32
|
+
const certPem = (0, crypto_utils_1.toPem)(p, "CERTIFICATE");
|
|
33
|
+
const verify = crypto.createVerify(signatureAlgorithm.identifier);
|
|
34
|
+
verify.update(bufferToBeSigned);
|
|
35
|
+
verify.end();
|
|
36
|
+
return verify.verify(certPem, signatureValue);
|
|
37
|
+
}
|
|
38
|
+
exports.verifyCertificateOrClrSignature = verifyCertificateOrClrSignature;
|
|
39
|
+
function verifyCertificateSignature(certificate, parentCertificate) {
|
|
40
|
+
return verifyCertificateOrClrSignature(certificate, parentCertificate);
|
|
41
|
+
}
|
|
42
|
+
exports.verifyCertificateSignature = verifyCertificateSignature;
|
|
43
|
+
function verifyCertificateRevocationListSignature(certificateRevocationList, parentCertificate) {
|
|
44
|
+
return verifyCertificateOrClrSignature(certificateRevocationList, parentCertificate);
|
|
45
|
+
}
|
|
46
|
+
exports.verifyCertificateRevocationListSignature = verifyCertificateRevocationListSignature;
|
|
47
|
+
function verifyCertificateChain(certificateChain) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
// verify that all the certificate
|
|
50
|
+
// second certificate must be used for CertificateSign
|
|
51
|
+
for (let index = 1; index < certificateChain.length; index++) {
|
|
52
|
+
const cert = certificateChain[index - 1];
|
|
53
|
+
const certParent = certificateChain[index];
|
|
54
|
+
// parent child must have keyCertSign
|
|
55
|
+
const certParentInfo = (0, crypto_explore_certificate_1.exploreCertificate)(certParent);
|
|
56
|
+
const keyUsage = certParentInfo.tbsCertificate.extensions.keyUsage;
|
|
57
|
+
// istanbul ignore next
|
|
58
|
+
if (!keyUsage.keyCertSign) {
|
|
59
|
+
return {
|
|
60
|
+
status: "BadCertificateIssuerUseNotAllowed",
|
|
61
|
+
reason: "One of the certificate in the chain has not keyUsage set for Certificate Signing",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const parentSignChild = verifyCertificateSignature(cert, certParent);
|
|
65
|
+
if (!parentSignChild) {
|
|
66
|
+
return {
|
|
67
|
+
status: "BadCertificateInvalid",
|
|
68
|
+
reason: "One of the certificate in the chain is not signing the previous certificate",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const certInfo = (0, crypto_explore_certificate_1.exploreCertificate)(cert);
|
|
72
|
+
// istanbul ignore next
|
|
73
|
+
if (!certInfo.tbsCertificate.extensions) {
|
|
74
|
+
return {
|
|
75
|
+
status: "BadCertificateInvalid",
|
|
76
|
+
reason: "Cannot find X409 Extension 3 in certificate",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// istanbul ignore next
|
|
80
|
+
if (!certParentInfo.tbsCertificate.extensions || !certInfo.tbsCertificate.extensions.authorityKeyIdentifier) {
|
|
81
|
+
return {
|
|
82
|
+
status: "BadCertificateInvalid",
|
|
83
|
+
reason: "Cannot find X409 Extension 3 in certificate (parent)",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// istanbul ignore next
|
|
87
|
+
if (certParentInfo.tbsCertificate.extensions.subjectKeyIdentifier !==
|
|
88
|
+
certInfo.tbsCertificate.extensions.authorityKeyIdentifier.keyIdentifier) {
|
|
89
|
+
return {
|
|
90
|
+
status: "BadCertificateInvalid",
|
|
91
|
+
reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
status: "Good",
|
|
97
|
+
reason: `certificate chain is valid(length = ${certificateChain.length})`,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.verifyCertificateChain = verifyCertificateChain;
|
|
102
102
|
//# sourceMappingURL=verify_certificate_signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildPublicKey(privateKey: CryptoKey): Promise<CryptoKey>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.buildPublicKey = void 0;
|
|
13
|
+
const x509_1 = require("@peculiar/x509");
|
|
14
|
+
// https://stackoverflow.com/questions/56807959/generate-public-key-from-private-key-using-webcrypto-api
|
|
15
|
+
function buildPublicKey(privateKey) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const crypto = x509_1.cryptoProvider.get();
|
|
18
|
+
// export private key to JWK
|
|
19
|
+
const jwk = yield crypto.subtle.exportKey("jwk", privateKey);
|
|
20
|
+
// remove private data from JWK
|
|
21
|
+
delete jwk.d;
|
|
22
|
+
delete jwk.dp;
|
|
23
|
+
delete jwk.dq;
|
|
24
|
+
delete jwk.q;
|
|
25
|
+
delete jwk.qi;
|
|
26
|
+
jwk.key_ops = ["encrypt", "wrapKey"];
|
|
27
|
+
// import public key
|
|
28
|
+
const publicKey = yield crypto.subtle.importKey("jwk", jwk, { name: "RSA-OAEP", hash: "SHA-512" }, true, [
|
|
29
|
+
"encrypt",
|
|
30
|
+
"wrapKey",
|
|
31
|
+
]);
|
|
32
|
+
return publicKey;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.buildPublicKey = buildPublicKey;
|
|
36
|
+
//# sourceMappingURL=_build_public_key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_build_public_key.js","sourceRoot":"","sources":["../../../source/x509/_build_public_key.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAgD;AAEhD,wGAAwG;AACxG,SAAsB,cAAc,CAAC,UAAqB;;QACtD,MAAM,MAAM,GAAG,qBAAc,CAAC,GAAG,EAAE,CAAC;QAEpC,4BAA4B;QAC5B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAE7D,+BAA+B;QAC/B,OAAO,GAAG,CAAC,CAAC,CAAC;QACb,OAAO,GAAG,CAAC,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,CAAC,CAAC;QACb,OAAO,GAAG,CAAC,EAAE,CAAC;QACd,GAAG,CAAC,OAAO,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAErC,oBAAoB;QACpB,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE;YACrG,SAAS;YACT,SAAS;SACZ,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACrB,CAAC;CAAA;AArBD,wCAqBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.x509 = exports.crypto = void 0;
|
|
4
|
+
const x509 = require("@peculiar/x509");
|
|
5
|
+
const webcrypto_1 = require("@peculiar/webcrypto");
|
|
6
|
+
exports.crypto = new webcrypto_1.Crypto();
|
|
7
|
+
x509.cryptoProvider.set(exports.crypto);
|
|
8
|
+
exports.x509 = require("@peculiar/x509");
|
|
9
|
+
//# sourceMappingURL=_crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_crypto.js","sourceRoot":"","sources":["../../../source/x509/_crypto.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,mDAA6C;AAChC,QAAA,MAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;AACnC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAM,CAAC,CAAC;AAChC,yCAAuC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.x509_Pkcs10CertificateRequestGenerator_create_fixed = void 0;
|
|
13
|
+
const asn1Schema = require("@peculiar/asn1-schema");
|
|
14
|
+
const asn1Csr = require("@peculiar/asn1-csr");
|
|
15
|
+
const asn1X509 = require("@peculiar/asn1-x509");
|
|
16
|
+
const asnPkcs9 = require("@peculiar/asn1-pkcs9");
|
|
17
|
+
const tsyringe = require("tsyringe");
|
|
18
|
+
const x509_1 = require("@peculiar/x509");
|
|
19
|
+
function x509_Pkcs10CertificateRequestGenerator_create_fixed(params) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const crypto = x509_1.cryptoProvider.get();
|
|
22
|
+
if (!params.keys.privateKey) {
|
|
23
|
+
throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");
|
|
24
|
+
}
|
|
25
|
+
if (!params.keys.publicKey) {
|
|
26
|
+
throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");
|
|
27
|
+
}
|
|
28
|
+
const spki = yield crypto.subtle.exportKey("spki", params.keys.publicKey);
|
|
29
|
+
const asnReq = new asn1Csr.CertificationRequest({
|
|
30
|
+
certificationRequestInfo: new asn1Csr.CertificationRequestInfo({
|
|
31
|
+
subjectPKInfo: asn1Schema.AsnConvert.parse(spki, asn1X509.SubjectPublicKeyInfo),
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
if (params.name) {
|
|
35
|
+
const name = params.name instanceof x509_1.Name ? params.name : new x509_1.Name(params.name);
|
|
36
|
+
asnReq.certificationRequestInfo.subject = asn1Schema.AsnConvert.parse(name.toArrayBuffer(), asn1X509.Name);
|
|
37
|
+
}
|
|
38
|
+
if (params.attributes) {
|
|
39
|
+
for (const o of params.attributes) {
|
|
40
|
+
asnReq.certificationRequestInfo.attributes.push(asn1Schema.AsnConvert.parse(o.rawData, asn1X509.Attribute));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (params.extensions && params.extensions.length) {
|
|
44
|
+
const attr = new asn1X509.Attribute({ type: asnPkcs9.id_pkcs9_at_extensionRequest });
|
|
45
|
+
const extensions = new asn1X509.Extensions();
|
|
46
|
+
for (const o of params.extensions) {
|
|
47
|
+
extensions.push(asn1Schema.AsnConvert.parse(o.rawData, asn1X509.Extension));
|
|
48
|
+
}
|
|
49
|
+
attr.values.push(asn1Schema.AsnConvert.serialize(extensions));
|
|
50
|
+
asnReq.certificationRequestInfo.attributes.push(attr);
|
|
51
|
+
}
|
|
52
|
+
// const signingAlgorithm = { ...params.signingAlgorithm, ...params.keys.privateKey.algorithm };
|
|
53
|
+
const signingAlgorithm = Object.assign({}, params.keys.privateKey.algorithm);
|
|
54
|
+
const algProv = tsyringe.container.resolve(x509_1.diAlgorithmProvider);
|
|
55
|
+
asnReq.signatureAlgorithm = algProv.toAsnAlgorithm(signingAlgorithm);
|
|
56
|
+
const tbs = asn1Schema.AsnConvert.serialize(asnReq.certificationRequestInfo);
|
|
57
|
+
const signature = yield crypto.subtle.sign(signingAlgorithm, params.keys.privateKey, tbs);
|
|
58
|
+
const signatureFormatters = tsyringe.container.resolveAll(x509_1.diAsnSignatureFormatter).reverse();
|
|
59
|
+
let asnSignature = null;
|
|
60
|
+
for (const signatureFormatter of signatureFormatters) {
|
|
61
|
+
asnSignature = signatureFormatter.toAsnSignature(signingAlgorithm, signature);
|
|
62
|
+
if (asnSignature) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!asnSignature) {
|
|
67
|
+
throw Error("Cannot convert WebCrypto signature value to ASN.1 format");
|
|
68
|
+
}
|
|
69
|
+
asnReq.signature = asnSignature;
|
|
70
|
+
return new x509_1.Pkcs10CertificateRequest(asn1Schema.AsnConvert.serialize(asnReq));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.x509_Pkcs10CertificateRequestGenerator_create_fixed = x509_Pkcs10CertificateRequestGenerator_create_fixed;
|
|
74
|
+
//# sourceMappingURL=_fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fix.js","sourceRoot":"","sources":["../../../source/x509/_fix.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAoD;AACpD,8CAA8C;AAC9C,gDAAgD;AAChD,iDAAiD;AACjD,qCAAqC;AAErC,yCAOwB;AAExB,SAAsB,mDAAmD,CACrE,MAA4C;;QAG5C,MAAM,MAAM,GAAG,qBAAc,CAAC,GAAG,EAAE,CAAC;QAEpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;SACnF;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;SAClF;QACD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,oBAAoB,CAAC;YAC5C,wBAAwB,EAAE,IAAI,OAAO,CAAC,wBAAwB,CAAC;gBAC3D,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,oBAAoB,CAAC;aAClF,CAAC;SACL,CAAC,CAAC;QACH,IAAI,MAAM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gBAAgB,qBAAQ,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAE,CAAC;QAEpE,MAAM,OAAO,GAAQ,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,0BAAmB,CAAC,CAAC;QACrE,MAAM,CAAC,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAGrE,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;QAE7E,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAE1F,MAAM,mBAAmB,GAAU,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,8BAAuB,CAAC,CAAC,OAAO,EAAE,CAAC;QAEpG,IAAI,YAAY,GAAG,IAAI,CAAC;QACxB,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE;YAClD,YAAY,GAAG,kBAAkB,CAAC,cAAc,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;YAC9E,IAAI,YAAY,EAAE;gBACd,MAAM;aACT;SACJ;QACD,IAAI,CAAC,YAAY,EAAE;YACf,MAAM,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC3E;QACD,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;QAChC,OAAO,IAAI,+BAAwB,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,CAAC;CAAA;AA/DD,kHA+DC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CertificatePurpose } from "../common";
|
|
2
|
+
import { x509 } from "./_crypto";
|
|
3
|
+
export declare function getAttributes(purpose: CertificatePurpose): {
|
|
4
|
+
nsComment: string;
|
|
5
|
+
basicConstraints: x509.BasicConstraintsExtension;
|
|
6
|
+
keyUsageExtension: x509.ExtendedKeyUsage[];
|
|
7
|
+
usages: x509.KeyUsageFlags;
|
|
8
|
+
};
|