node-opcua-crypto 1.7.1 → 1.7.5
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/workflows/main.yml +32 -0
- package/.prettierrc.js +6 -6
- package/dist/source/asn1.d.ts +6 -2
- package/dist/source/asn1.js +13 -1
- package/dist/source/asn1.js.map +1 -1
- package/dist/source/buffer_utils.d.ts +1 -2
- package/dist/source/crypto_explore_certificate.js +94 -63
- package/dist/source/crypto_explore_certificate.js.map +1 -1
- package/dist/source/crypto_utils.js +10 -10
- package/dist/source/crypto_utils.js.map +1 -1
- package/dist/source/derived_keys.js +9 -6
- package/dist/source/derived_keys.js.map +1 -1
- package/dist/source/explore_certificate.d.ts +1 -1
- package/dist/source/explore_certificate.js +2 -2
- package/dist/source/explore_certificate.js.map +1 -1
- package/dist/source/explore_certificate_revocation_list.js +16 -16
- package/dist/source/explore_certificate_revocation_list.js.map +1 -1
- package/dist/source/explore_certificate_signing_request.js +11 -11
- package/dist/source/explore_certificate_signing_request.js.map +1 -1
- package/dist/source/explore_private_key.js +4 -4
- package/dist/source/explore_private_key.js.map +1 -1
- package/dist/source/oid_map.js +42 -0
- package/dist/source/oid_map.js.map +1 -1
- package/dist/source/public_private_match.js +2 -2
- package/dist/source/public_private_match.js.map +1 -1
- package/dist/source/verify_certificate_signature.js +8 -8
- package/dist/source/verify_certificate_signature.js.map +1 -1
- package/dist/source_nodejs/read.js +2 -2
- package/dist/source_nodejs/read.js.map +1 -1
- package/dist/source_nodejs/read_certificate_revocation_list.js +2 -2
- package/dist/source_nodejs/read_certificate_revocation_list.js.map +1 -1
- package/dist/source_nodejs/read_certificate_signing_request.js +2 -2
- package/dist/source_nodejs/read_certificate_signing_request.js.map +1 -1
- package/index.d.ts +2 -2
- package/package.json +16 -19
- package/source/asn1.ts +404 -393
- package/source/buffer_utils.ts +18 -18
- package/source/common.ts +13 -13
- package/source/crypto_explore_certificate.ts +38 -4
- package/source/crypto_utils.ts +3 -3
- package/source/derived_keys.ts +287 -284
- package/source/explore_certificate.ts +1 -1
- package/source/explore_certificate_revocation_list.ts +93 -93
- package/source/oid_map.ts +310 -265
- package/source/verify_certificate_signature.ts +105 -105
- package/source_nodejs/read.ts +95 -95
- package/source_nodejs/read_certificate_revocation_list.ts +14 -14
- package/test_certificate.ts +34 -34
|
@@ -1,93 +1,93 @@
|
|
|
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
|
-
} from "./asn1";
|
|
21
|
-
import { CertificateRevocationList } from "./common";
|
|
22
|
-
import { makeSHA1Thumbprint, convertPEMtoDER } from "./crypto_utils";
|
|
23
|
-
|
|
24
|
-
export type Version = string;
|
|
25
|
-
export type Name = string;
|
|
26
|
-
export type CertificateSerialNumber = string;
|
|
27
|
-
export type Extensions = Record<string, unknown>;
|
|
28
|
-
export interface RevokedCertificate {
|
|
29
|
-
userCertificate: CertificateSerialNumber;
|
|
30
|
-
revocationDate: Date;
|
|
31
|
-
crlEntryExtensions?: Extensions;
|
|
32
|
-
}
|
|
33
|
-
export interface TBSCertList {
|
|
34
|
-
version?: Version; //OPTIONAL; // must be 2
|
|
35
|
-
signature: AlgorithmIdentifier;
|
|
36
|
-
issuer: Name;
|
|
37
|
-
issuerFingerprint: string; // 00:AA:BB:etc ...
|
|
38
|
-
thisUpdate: Date;
|
|
39
|
-
nextUpdate?: Date; // Time OPTIONAL,
|
|
40
|
-
revokedCertificates: RevokedCertificate[];
|
|
41
|
-
// crlExtensions[0] EXPLICIT Extensions OPTIONAL
|
|
42
|
-
}
|
|
43
|
-
export interface CertificateRevocationListInfo {
|
|
44
|
-
tbsCertList: TBSCertList;
|
|
45
|
-
signatureAlgorithm: AlgorithmIdentifier;
|
|
46
|
-
signatureValue: Buffer;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName {
|
|
50
|
-
return _readDirectoryName(buffer, block);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
|
|
54
|
-
const blocks = _readStruct(buffer, blockInfo);
|
|
55
|
-
|
|
56
|
-
const version = _readIntegerValue(buffer, blocks[0]);
|
|
57
|
-
const signature = _readAlgorithmIdentifier(buffer, blocks[1]);
|
|
58
|
-
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
59
|
-
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
60
|
-
|
|
61
|
-
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
62
|
-
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
63
|
-
|
|
64
|
-
const revokedCertificates: RevokedCertificate[] = [];
|
|
65
|
-
|
|
66
|
-
if (blocks[5] && blocks[5].tag < 0x80) {
|
|
67
|
-
const list = _readStruct(buffer, blocks[5]);
|
|
68
|
-
for (const r of list) {
|
|
69
|
-
// sometime blocks[5] doesn't exits .. in this case
|
|
70
|
-
const rr = _readStruct(buffer, r);
|
|
71
|
-
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
72
|
-
const revocationDate = _readTime(buffer, rr[1]);
|
|
73
|
-
revokedCertificates.push({
|
|
74
|
-
revocationDate,
|
|
75
|
-
userCertificate,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
81
|
-
|
|
82
|
-
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
83
|
-
}
|
|
84
|
-
// see https://tools.ietf.org/html/rfc5280
|
|
85
|
-
|
|
86
|
-
export function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo {
|
|
87
|
-
const blockInfo = readTag(crl, 0);
|
|
88
|
-
const blocks = _readStruct(crl, blockInfo);
|
|
89
|
-
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
90
|
-
const signatureAlgorithm = _readAlgorithmIdentifier(crl, blocks[1]);
|
|
91
|
-
const signatureValue = _readSignatureValueBin(crl, blocks[2]);
|
|
92
|
-
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
93
|
-
}
|
|
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
|
+
} from "./asn1";
|
|
21
|
+
import { CertificateRevocationList } from "./common";
|
|
22
|
+
import { makeSHA1Thumbprint, convertPEMtoDER } from "./crypto_utils";
|
|
23
|
+
|
|
24
|
+
export type Version = string;
|
|
25
|
+
export type Name = string;
|
|
26
|
+
export type CertificateSerialNumber = string;
|
|
27
|
+
export type Extensions = Record<string, unknown>;
|
|
28
|
+
export interface RevokedCertificate {
|
|
29
|
+
userCertificate: CertificateSerialNumber;
|
|
30
|
+
revocationDate: Date;
|
|
31
|
+
crlEntryExtensions?: Extensions;
|
|
32
|
+
}
|
|
33
|
+
export interface TBSCertList {
|
|
34
|
+
version?: Version; //OPTIONAL; // must be 2
|
|
35
|
+
signature: AlgorithmIdentifier;
|
|
36
|
+
issuer: Name;
|
|
37
|
+
issuerFingerprint: string; // 00:AA:BB:etc ...
|
|
38
|
+
thisUpdate: Date;
|
|
39
|
+
nextUpdate?: Date; // Time OPTIONAL,
|
|
40
|
+
revokedCertificates: RevokedCertificate[];
|
|
41
|
+
// crlExtensions[0] EXPLICIT Extensions OPTIONAL
|
|
42
|
+
}
|
|
43
|
+
export interface CertificateRevocationListInfo {
|
|
44
|
+
tbsCertList: TBSCertList;
|
|
45
|
+
signatureAlgorithm: AlgorithmIdentifier;
|
|
46
|
+
signatureValue: Buffer;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function readNameForCrl(buffer: Buffer, block: BlockInfo): DirectoryName {
|
|
50
|
+
return _readDirectoryName(buffer, block);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
|
|
54
|
+
const blocks = _readStruct(buffer, blockInfo);
|
|
55
|
+
|
|
56
|
+
const version = _readIntegerValue(buffer, blocks[0]);
|
|
57
|
+
const signature = _readAlgorithmIdentifier(buffer, blocks[1]);
|
|
58
|
+
const issuer = readNameForCrl(buffer, blocks[2]);
|
|
59
|
+
const issuerFingerprint = formatBuffer2DigitHexWithColum(makeSHA1Thumbprint(_getBlock(buffer, blocks[2])));
|
|
60
|
+
|
|
61
|
+
const thisUpdate = _readTime(buffer, blocks[3]);
|
|
62
|
+
const nextUpdate = _readTime(buffer, blocks[4]);
|
|
63
|
+
|
|
64
|
+
const revokedCertificates: RevokedCertificate[] = [];
|
|
65
|
+
|
|
66
|
+
if (blocks[5] && blocks[5].tag < 0x80) {
|
|
67
|
+
const list = _readStruct(buffer, blocks[5]);
|
|
68
|
+
for (const r of list) {
|
|
69
|
+
// sometime blocks[5] doesn't exits .. in this case
|
|
70
|
+
const rr = _readStruct(buffer, r);
|
|
71
|
+
const userCertificate = formatBuffer2DigitHexWithColum(_readLongIntegerValue(buffer, rr[0]));
|
|
72
|
+
const revocationDate = _readTime(buffer, rr[1]);
|
|
73
|
+
revokedCertificates.push({
|
|
74
|
+
revocationDate,
|
|
75
|
+
userCertificate,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ext0 = _findBlockAtIndex(blocks, 0);
|
|
81
|
+
|
|
82
|
+
return { issuer, issuerFingerprint, thisUpdate, nextUpdate, signature, revokedCertificates } as TBSCertList;
|
|
83
|
+
}
|
|
84
|
+
// see https://tools.ietf.org/html/rfc5280
|
|
85
|
+
|
|
86
|
+
export function exploreCertificateRevocationList(crl: CertificateRevocationList): CertificateRevocationListInfo {
|
|
87
|
+
const blockInfo = readTag(crl, 0);
|
|
88
|
+
const blocks = _readStruct(crl, blockInfo);
|
|
89
|
+
const tbsCertList = _readTbsCertList(crl, blocks[0]);
|
|
90
|
+
const signatureAlgorithm = _readAlgorithmIdentifier(crl, blocks[1]);
|
|
91
|
+
const signatureValue = _readSignatureValueBin(crl, blocks[2]);
|
|
92
|
+
return { tbsCertList, signatureAlgorithm, signatureValue };
|
|
93
|
+
}
|