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,66 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node_opcua_crypto
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Certificate, CertificatePEM } from "./common";
|
|
6
|
-
import { exploreCertificate, SubjectPublicKey } from "./crypto_explore_certificate";
|
|
7
|
-
import { DirectoryName } from "./asn1";
|
|
8
|
-
import { convertPEMtoDER } from "./crypto_utils";
|
|
9
|
-
import * as assert from "assert";
|
|
10
|
-
|
|
11
|
-
export type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A structure exposing useful information about a certificate
|
|
15
|
-
*/
|
|
16
|
-
export interface CertificateInfo {
|
|
17
|
-
/** the public key length in bits */
|
|
18
|
-
publicKeyLength: PublicKeyLength;
|
|
19
|
-
/** the date at which the certificate starts to be valid */
|
|
20
|
-
notBefore: Date;
|
|
21
|
-
/** the date after which the certificate is not valid any more */
|
|
22
|
-
notAfter: Date;
|
|
23
|
-
/** info about certificate owner */
|
|
24
|
-
subject: DirectoryName;
|
|
25
|
-
/** public key */
|
|
26
|
-
publicKey: SubjectPublicKey;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate {
|
|
30
|
-
if (typeof certificate === "string") {
|
|
31
|
-
certificate = convertPEMtoDER(certificate);
|
|
32
|
-
}
|
|
33
|
-
assert(certificate instanceof Buffer);
|
|
34
|
-
return certificate;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @method exploreCertificateInfo
|
|
39
|
-
* returns useful information about the certificate such as public key length, start date and end of validity date,
|
|
40
|
-
* and CN
|
|
41
|
-
* @param certificate the certificate to explore
|
|
42
|
-
*/
|
|
43
|
-
export function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo {
|
|
44
|
-
certificate = coerceCertificate(certificate);
|
|
45
|
-
|
|
46
|
-
const certInfo = exploreCertificate(certificate);
|
|
47
|
-
const data: CertificateInfo = {
|
|
48
|
-
publicKeyLength: certInfo.tbsCertificate.subjectPublicKeyInfo.keyLength,
|
|
49
|
-
notBefore: certInfo.tbsCertificate.validity.notBefore,
|
|
50
|
-
notAfter: certInfo.tbsCertificate.validity.notAfter,
|
|
51
|
-
publicKey: certInfo.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey,
|
|
52
|
-
subject: certInfo.tbsCertificate.subject,
|
|
53
|
-
};
|
|
54
|
-
// istanbul ignore next
|
|
55
|
-
if (
|
|
56
|
-
!(
|
|
57
|
-
data.publicKeyLength === 512 ||
|
|
58
|
-
data.publicKeyLength === 384 ||
|
|
59
|
-
data.publicKeyLength === 256 ||
|
|
60
|
-
data.publicKeyLength === 128
|
|
61
|
-
)
|
|
62
|
-
) {
|
|
63
|
-
throw new Error("Invalid public key length (expecting 128,256,384 or 512)" + data.publicKeyLength);
|
|
64
|
-
}
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node_opcua_crypto
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Certificate, CertificatePEM } from "./common";
|
|
6
|
+
import { exploreCertificate, SubjectPublicKey } from "./crypto_explore_certificate";
|
|
7
|
+
import { DirectoryName } from "./asn1";
|
|
8
|
+
import { convertPEMtoDER } from "./crypto_utils";
|
|
9
|
+
import * as assert from "assert";
|
|
10
|
+
|
|
11
|
+
export type PublicKeyLength = 64 | 96 | 128 | 256 | 384 | 512;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A structure exposing useful information about a certificate
|
|
15
|
+
*/
|
|
16
|
+
export interface CertificateInfo {
|
|
17
|
+
/** the public key length in bits */
|
|
18
|
+
publicKeyLength: PublicKeyLength;
|
|
19
|
+
/** the date at which the certificate starts to be valid */
|
|
20
|
+
notBefore: Date;
|
|
21
|
+
/** the date after which the certificate is not valid any more */
|
|
22
|
+
notAfter: Date;
|
|
23
|
+
/** info about certificate owner */
|
|
24
|
+
subject: DirectoryName;
|
|
25
|
+
/** public key */
|
|
26
|
+
publicKey: SubjectPublicKey;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function coerceCertificate(certificate: Certificate | CertificatePEM): Certificate {
|
|
30
|
+
if (typeof certificate === "string") {
|
|
31
|
+
certificate = convertPEMtoDER(certificate);
|
|
32
|
+
}
|
|
33
|
+
assert(certificate instanceof Buffer);
|
|
34
|
+
return certificate;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @method exploreCertificateInfo
|
|
39
|
+
* returns useful information about the certificate such as public key length, start date and end of validity date,
|
|
40
|
+
* and CN
|
|
41
|
+
* @param certificate the certificate to explore
|
|
42
|
+
*/
|
|
43
|
+
export function exploreCertificateInfo(certificate: Certificate | CertificatePEM): CertificateInfo {
|
|
44
|
+
certificate = coerceCertificate(certificate);
|
|
45
|
+
|
|
46
|
+
const certInfo = exploreCertificate(certificate);
|
|
47
|
+
const data: CertificateInfo = {
|
|
48
|
+
publicKeyLength: certInfo.tbsCertificate.subjectPublicKeyInfo.keyLength,
|
|
49
|
+
notBefore: certInfo.tbsCertificate.validity.notBefore,
|
|
50
|
+
notAfter: certInfo.tbsCertificate.validity.notAfter,
|
|
51
|
+
publicKey: certInfo.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey,
|
|
52
|
+
subject: certInfo.tbsCertificate.subject,
|
|
53
|
+
};
|
|
54
|
+
// istanbul ignore next
|
|
55
|
+
if (
|
|
56
|
+
!(
|
|
57
|
+
data.publicKeyLength === 512 ||
|
|
58
|
+
data.publicKeyLength === 384 ||
|
|
59
|
+
data.publicKeyLength === 256 ||
|
|
60
|
+
data.publicKeyLength === 128
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
throw new Error("Invalid public key length (expecting 128,256,384 or 512)" + data.publicKeyLength);
|
|
64
|
+
}
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
_readStruct,
|
|
3
|
-
readTag,
|
|
4
|
-
_readBitString,
|
|
5
|
-
AlgorithmIdentifier,
|
|
6
|
-
_readAlgorithmIdentifier,
|
|
7
|
-
_readSignatureValue,
|
|
8
|
-
_readSignatureValueBin,
|
|
9
|
-
BlockInfo,
|
|
10
|
-
_readObjectIdentifier,
|
|
11
|
-
DirectoryName,
|
|
12
|
-
_readValue,
|
|
13
|
-
_readTime,
|
|
14
|
-
_readLongIntegerValue,
|
|
15
|
-
formatBuffer2DigitHexWithColum,
|
|
16
|
-
_getBlock,
|
|
17
|
-
_readDirectoryName,
|
|
18
|
-
_findBlockAtIndex,
|
|
19
|
-
_readIntegerValue,
|
|
20
|
-
TagType,
|
|
21
|
-
} from "./asn1";
|
|
22
|
-
import { CertificateRevocationList } from "./common";
|
|
23
|
-
import { makeSHA1Thumbprint, convertPEMtoDER } from "./crypto_utils";
|
|
24
|
-
|
|
25
|
-
export type Version = string;
|
|
26
|
-
export type Name = string;
|
|
27
|
-
export type CertificateSerialNumber = string;
|
|
28
|
-
export type Extensions = Record<string, unknown>;
|
|
29
|
-
export interface RevokedCertificate {
|
|
30
|
-
userCertificate: CertificateSerialNumber;
|
|
31
|
-
revocationDate: Date;
|
|
32
|
-
crlEntryExtensions?: Extensions;
|
|
33
|
-
}
|
|
34
|
-
export interface TBSCertList {
|
|
35
|
-
version?: Version; //OPTIONAL; // must be 2
|
|
36
|
-
signature: AlgorithmIdentifier;
|
|
37
|
-
issuer: Name;
|
|
38
|
-
issuerFingerprint: string; // 00:AA:BB:etc ...
|
|
39
|
-
thisUpdate: Date;
|
|
40
|
-
nextUpdate?: Date; // Time OPTIONAL,
|
|
41
|
-
revokedCertificates: RevokedCertificate[];
|
|
42
|
-
// crlExtensions[0] EXPLICIT Extensions OPTIONAL
|
|
43
|
-
}
|
|
44
|
-
export interface CertificateRevocationListInfo {
|
|
45
|
-
tbsCertList: TBSCertList;
|
|
46
|
-
signatureAlgorithm: AlgorithmIdentifier;
|
|
47
|
-
signatureValue: Buffer;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName {
|
|
51
|
-
return _readDirectoryName(buffer, block);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
|
|
55
|
-
const blocks = _readStruct(buffer, blockInfo);
|
|
56
|
-
|
|
57
|
-
const hasOptionalVersion = blocks[0].tag === TagType.INTEGER;
|
|
58
|
-
|
|
59
|
-
if (hasOptionalVersion) {
|
|
60
|
-
const version = _readIntegerValue(buffer, blocks[0]);
|
|
61
|
-
const signature = _readAlgorithmIdentifier(buffer, blocks[1]);
|
|
62
|
-
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
63
|
-
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
64
|
-
|
|
65
|
-
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
66
|
-
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
67
|
-
|
|
68
|
-
const revokedCertificates: RevokedCertificate[] = [];
|
|
69
|
-
|
|
70
|
-
if (blocks[5] && blocks[5].tag < 0x80) {
|
|
71
|
-
const list = _readStruct(buffer, blocks[5]);
|
|
72
|
-
for (const r of list) {
|
|
73
|
-
// sometime blocks[5] doesn't exits .. in this case
|
|
74
|
-
const rr = _readStruct(buffer, r);
|
|
75
|
-
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
76
|
-
const revocationDate = _readTime(buffer, rr[1]);
|
|
77
|
-
revokedCertificates.push({
|
|
78
|
-
revocationDate,
|
|
79
|
-
userCertificate,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
85
|
-
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
86
|
-
} else {
|
|
87
|
-
|
|
88
|
-
const signature = _readAlgorithmIdentifier(buffer, blocks[0]);
|
|
89
|
-
const issuer = readNameForCrl(buffer, blocks[1]);
|
|
90
|
-
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[1])));
|
|
91
|
-
|
|
92
|
-
const thisUpdate = _readTime(buffer, blocks[2]);
|
|
93
|
-
const nextUpdate = _readTime(buffer, blocks[3]);
|
|
94
|
-
|
|
95
|
-
const revokedCertificates: RevokedCertificate[] = [];
|
|
96
|
-
|
|
97
|
-
if (blocks[4] && blocks[4].tag < 0x80) {
|
|
98
|
-
const list = _readStruct(buffer, blocks[4]);
|
|
99
|
-
for (const r of list) {
|
|
100
|
-
// sometime blocks[5] doesn't exits .. in this case
|
|
101
|
-
const rr = _readStruct(buffer, r);
|
|
102
|
-
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
103
|
-
const revocationDate = _readTime(buffer, rr[1]);
|
|
104
|
-
revokedCertificates.push({
|
|
105
|
-
revocationDate,
|
|
106
|
-
userCertificate,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// see https://tools.ietf.org/html/rfc5280
|
|
114
|
-
|
|
115
|
-
export function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo {
|
|
116
|
-
const blockInfo = readTag(crl, 0);
|
|
117
|
-
const blocks = _readStruct(crl, blockInfo);
|
|
118
|
-
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
119
|
-
const signatureAlgorithm = _readAlgorithmIdentifier(crl, blocks[1]);
|
|
120
|
-
const signatureValue = _readSignatureValueBin(crl, blocks[2]);
|
|
121
|
-
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
122
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
_readStruct,
|
|
3
|
+
readTag,
|
|
4
|
+
_readBitString,
|
|
5
|
+
AlgorithmIdentifier,
|
|
6
|
+
_readAlgorithmIdentifier,
|
|
7
|
+
_readSignatureValue,
|
|
8
|
+
_readSignatureValueBin,
|
|
9
|
+
BlockInfo,
|
|
10
|
+
_readObjectIdentifier,
|
|
11
|
+
DirectoryName,
|
|
12
|
+
_readValue,
|
|
13
|
+
_readTime,
|
|
14
|
+
_readLongIntegerValue,
|
|
15
|
+
formatBuffer2DigitHexWithColum,
|
|
16
|
+
_getBlock,
|
|
17
|
+
_readDirectoryName,
|
|
18
|
+
_findBlockAtIndex,
|
|
19
|
+
_readIntegerValue,
|
|
20
|
+
TagType,
|
|
21
|
+
} from "./asn1";
|
|
22
|
+
import { CertificateRevocationList } from "./common";
|
|
23
|
+
import { makeSHA1Thumbprint, convertPEMtoDER } from "./crypto_utils";
|
|
24
|
+
|
|
25
|
+
export type Version = string;
|
|
26
|
+
export type Name = string;
|
|
27
|
+
export type CertificateSerialNumber = string;
|
|
28
|
+
export type Extensions = Record<string, unknown>;
|
|
29
|
+
export interface RevokedCertificate {
|
|
30
|
+
userCertificate: CertificateSerialNumber;
|
|
31
|
+
revocationDate: Date;
|
|
32
|
+
crlEntryExtensions?: Extensions;
|
|
33
|
+
}
|
|
34
|
+
export interface TBSCertList {
|
|
35
|
+
version?: Version; //OPTIONAL; // must be 2
|
|
36
|
+
signature: AlgorithmIdentifier;
|
|
37
|
+
issuer: Name;
|
|
38
|
+
issuerFingerprint: string; // 00:AA:BB:etc ...
|
|
39
|
+
thisUpdate: Date;
|
|
40
|
+
nextUpdate?: Date; // Time OPTIONAL,
|
|
41
|
+
revokedCertificates: RevokedCertificate[];
|
|
42
|
+
// crlExtensions[0] EXPLICIT Extensions OPTIONAL
|
|
43
|
+
}
|
|
44
|
+
export interface CertificateRevocationListInfo {
|
|
45
|
+
tbsCertList: TBSCertList;
|
|
46
|
+
signatureAlgorithm: AlgorithmIdentifier;
|
|
47
|
+
signatureValue: Buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName {
|
|
51
|
+
return _readDirectoryName(buffer, block);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
|
|
55
|
+
const blocks = _readStruct(buffer, blockInfo);
|
|
56
|
+
|
|
57
|
+
const hasOptionalVersion = blocks[0].tag === TagType.INTEGER;
|
|
58
|
+
|
|
59
|
+
if (hasOptionalVersion) {
|
|
60
|
+
const version = _readIntegerValue(buffer, blocks[0]);
|
|
61
|
+
const signature = _readAlgorithmIdentifier(buffer, blocks[1]);
|
|
62
|
+
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
63
|
+
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
64
|
+
|
|
65
|
+
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
66
|
+
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
67
|
+
|
|
68
|
+
const revokedCertificates: RevokedCertificate[] = [];
|
|
69
|
+
|
|
70
|
+
if (blocks[5] && blocks[5].tag < 0x80) {
|
|
71
|
+
const list = _readStruct(buffer, blocks[5]);
|
|
72
|
+
for (const r of list) {
|
|
73
|
+
// sometime blocks[5] doesn't exits .. in this case
|
|
74
|
+
const rr = _readStruct(buffer, r);
|
|
75
|
+
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
76
|
+
const revocationDate = _readTime(buffer, rr[1]);
|
|
77
|
+
revokedCertificates.push({
|
|
78
|
+
revocationDate,
|
|
79
|
+
userCertificate,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
85
|
+
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
86
|
+
} else {
|
|
87
|
+
|
|
88
|
+
const signature = _readAlgorithmIdentifier(buffer, blocks[0]);
|
|
89
|
+
const issuer = readNameForCrl(buffer, blocks[1]);
|
|
90
|
+
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[1])));
|
|
91
|
+
|
|
92
|
+
const thisUpdate = _readTime(buffer, blocks[2]);
|
|
93
|
+
const nextUpdate = _readTime(buffer, blocks[3]);
|
|
94
|
+
|
|
95
|
+
const revokedCertificates: RevokedCertificate[] = [];
|
|
96
|
+
|
|
97
|
+
if (blocks[4] && blocks[4].tag < 0x80) {
|
|
98
|
+
const list = _readStruct(buffer, blocks[4]);
|
|
99
|
+
for (const r of list) {
|
|
100
|
+
// sometime blocks[5] doesn't exits .. in this case
|
|
101
|
+
const rr = _readStruct(buffer, r);
|
|
102
|
+
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
103
|
+
const revocationDate = _readTime(buffer, rr[1]);
|
|
104
|
+
revokedCertificates.push({
|
|
105
|
+
revocationDate,
|
|
106
|
+
userCertificate,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// see https://tools.ietf.org/html/rfc5280
|
|
114
|
+
|
|
115
|
+
export function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo {
|
|
116
|
+
const blockInfo = readTag(crl, 0);
|
|
117
|
+
const blocks = _readStruct(crl, blockInfo);
|
|
118
|
+
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
119
|
+
const signatureAlgorithm = _readAlgorithmIdentifier(crl, blocks[1]);
|
|
120
|
+
const signatureValue = _readSignatureValueBin(crl, blocks[2]);
|
|
121
|
+
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
122
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import { BlockInfo, readTag, _findBlockAtIndex, _getBlock, _readObjectIdentifier, _readStruct, _readVersionValue } from "./asn1";
|
|
3
|
-
|
|
4
|
-
import { BasicConstraints, X509KeyUsage, _readExtension } from "./crypto_explore_certificate";
|
|
5
|
-
|
|
6
|
-
export interface ExtensionRequest {
|
|
7
|
-
basicConstraints: BasicConstraints;
|
|
8
|
-
keyUsage: X509KeyUsage;
|
|
9
|
-
subjectAltName: any;
|
|
10
|
-
}
|
|
11
|
-
export interface CertificateSigningRequestInfo {
|
|
12
|
-
extensionRequest: ExtensionRequest;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function _readExtensionRequest(buffer: Buffer): ExtensionRequest {
|
|
16
|
-
const block = readTag(buffer, 0);
|
|
17
|
-
|
|
18
|
-
const inner_blocks = _readStruct(buffer, block);
|
|
19
|
-
const extensions = inner_blocks.map((block1) => _readExtension(buffer, block1));
|
|
20
|
-
|
|
21
|
-
const result: any = {};
|
|
22
|
-
for (const e of extensions) {
|
|
23
|
-
result[e.identifier.name] = e.value;
|
|
24
|
-
}
|
|
25
|
-
const { basicConstraints, keyUsage, subjectAltName } = result;
|
|
26
|
-
return { basicConstraints, keyUsage, subjectAltName };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo {
|
|
30
|
-
const blocks = _readStruct(buffer, block);
|
|
31
|
-
if (blocks.length === 4) {
|
|
32
|
-
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
33
|
-
if (!extensionRequestBlock) {
|
|
34
|
-
throw new Error("cannot find extensionRequest block");
|
|
35
|
-
}
|
|
36
|
-
const blocks1 = _readStruct(buffer, extensionRequestBlock);
|
|
37
|
-
const blocks2 = _readStruct(buffer, blocks1[0]);
|
|
38
|
-
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
39
|
-
if (identifier.name !== "extensionRequest") {
|
|
40
|
-
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
41
|
-
}
|
|
42
|
-
const buf = _getBlock(buffer, blocks2[1]);
|
|
43
|
-
|
|
44
|
-
const extensionRequest = _readExtensionRequest(buf);
|
|
45
|
-
|
|
46
|
-
return { extensionRequest };
|
|
47
|
-
}
|
|
48
|
-
throw new Error("Invalid CSR or ");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// see https://tools.ietf.org/html/rfc2986 : Certification Request Syntax Specification Version 1.7
|
|
52
|
-
|
|
53
|
-
export function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo {
|
|
54
|
-
const blockInfo = readTag(crl, 0);
|
|
55
|
-
const blocks = _readStruct(crl, blockInfo);
|
|
56
|
-
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
57
|
-
return csrInfo;
|
|
58
|
-
}
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import { BlockInfo, readTag, _findBlockAtIndex, _getBlock, _readObjectIdentifier, _readStruct, _readVersionValue } from "./asn1";
|
|
3
|
+
|
|
4
|
+
import { BasicConstraints, X509KeyUsage, _readExtension } from "./crypto_explore_certificate";
|
|
5
|
+
|
|
6
|
+
export interface ExtensionRequest {
|
|
7
|
+
basicConstraints: BasicConstraints;
|
|
8
|
+
keyUsage: X509KeyUsage;
|
|
9
|
+
subjectAltName: any;
|
|
10
|
+
}
|
|
11
|
+
export interface CertificateSigningRequestInfo {
|
|
12
|
+
extensionRequest: ExtensionRequest;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function _readExtensionRequest(buffer: Buffer): ExtensionRequest {
|
|
16
|
+
const block = readTag(buffer, 0);
|
|
17
|
+
|
|
18
|
+
const inner_blocks = _readStruct(buffer, block);
|
|
19
|
+
const extensions = inner_blocks.map((block1) => _readExtension(buffer, block1));
|
|
20
|
+
|
|
21
|
+
const result: any = {};
|
|
22
|
+
for (const e of extensions) {
|
|
23
|
+
result[e.identifier.name] = e.value;
|
|
24
|
+
}
|
|
25
|
+
const { basicConstraints, keyUsage, subjectAltName } = result;
|
|
26
|
+
return { basicConstraints, keyUsage, subjectAltName };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readCertificationRequestInfo(buffer: Buffer, block: BlockInfo): CertificateSigningRequestInfo {
|
|
30
|
+
const blocks = _readStruct(buffer, block);
|
|
31
|
+
if (blocks.length === 4) {
|
|
32
|
+
const extensionRequestBlock = _findBlockAtIndex(blocks, 0);
|
|
33
|
+
if (!extensionRequestBlock) {
|
|
34
|
+
throw new Error("cannot find extensionRequest block");
|
|
35
|
+
}
|
|
36
|
+
const blocks1 = _readStruct(buffer, extensionRequestBlock);
|
|
37
|
+
const blocks2 = _readStruct(buffer, blocks1[0]);
|
|
38
|
+
const identifier = _readObjectIdentifier(buffer, blocks2[0]);
|
|
39
|
+
if (identifier.name !== "extensionRequest") {
|
|
40
|
+
throw new Error(" Cannot find extension Request in ASN1 block");
|
|
41
|
+
}
|
|
42
|
+
const buf = _getBlock(buffer, blocks2[1]);
|
|
43
|
+
|
|
44
|
+
const extensionRequest = _readExtensionRequest(buf);
|
|
45
|
+
|
|
46
|
+
return { extensionRequest };
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Invalid CSR or ");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// see https://tools.ietf.org/html/rfc2986 : Certification Request Syntax Specification Version 1.7
|
|
52
|
+
|
|
53
|
+
export function exploreCertificateSigningRequest(crl: Buffer): CertificateSigningRequestInfo {
|
|
54
|
+
const blockInfo = readTag(crl, 0);
|
|
55
|
+
const blocks = _readStruct(crl, blockInfo);
|
|
56
|
+
const csrInfo = readCertificationRequestInfo(crl, blocks[0]);
|
|
57
|
+
return csrInfo;
|
|
58
|
+
}
|
|
@@ -35,8 +35,7 @@ const doDebug = !!process.env.DEBUG;
|
|
|
35
35
|
}
|
|
36
36
|
*/
|
|
37
37
|
export function explorePrivateKey(privateKey1: PrivateKey): PrivateKeyInternals {
|
|
38
|
-
const privateKey = privateKey1.export({ format: "der", type: "pkcs1" })
|
|
39
|
-
assert(privateKey instanceof Buffer);
|
|
38
|
+
const privateKey = privateKey1.export({ format: "der", type: "pkcs1" });
|
|
40
39
|
const block_info = readTag(privateKey, 0);
|
|
41
40
|
const blocks = _readStruct(privateKey, block_info);
|
|
42
41
|
|
package/source/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node_opcua_crypto
|
|
3
|
-
*/
|
|
4
|
-
export * from "./common";
|
|
5
|
-
export * from "./derived_keys";
|
|
6
|
-
export * from "./explore_certificate";
|
|
7
|
-
export * from "./crypto_utils";
|
|
8
|
-
export * from "./crypto_explore_certificate";
|
|
9
|
-
export * from "./verify_certificate_signature";
|
|
10
|
-
export * from "./explore_certificate_revocation_list";
|
|
11
|
-
export * from "./explore_certificate_signing_request";
|
|
12
|
-
export * from "./explore_private_key";
|
|
13
|
-
export * from "./public_private_match";
|
|
1
|
+
/**
|
|
2
|
+
* @module node_opcua_crypto
|
|
3
|
+
*/
|
|
4
|
+
export * from "./common";
|
|
5
|
+
export * from "./derived_keys";
|
|
6
|
+
export * from "./explore_certificate";
|
|
7
|
+
export * from "./crypto_utils";
|
|
8
|
+
export * from "./crypto_explore_certificate";
|
|
9
|
+
export * from "./verify_certificate_signature";
|
|
10
|
+
export * from "./explore_certificate_revocation_list";
|
|
11
|
+
export * from "./explore_certificate_signing_request";
|
|
12
|
+
export * from "./explore_private_key";
|
|
13
|
+
export * from "./public_private_match";
|
|
14
|
+
export * from "./x509/create_key_pair";
|
|
15
|
+
export * from "./x509/create_certificate_signing_request";
|
|
16
|
+
export * from "./x509/create_self_signed_certificate";
|
|
17
|
+
export * from "./subject";
|