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
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import { BlockInfo, readTag, TagType, _readIntegerAsByteString, _readStruct } from "./asn1";
|
|
3
|
-
import { PrivateKey } from "./common";
|
|
4
|
-
|
|
5
|
-
// tslint:disable:no-empty-interface
|
|
6
|
-
export interface PrivateKeyInternals {
|
|
7
|
-
/***/
|
|
8
|
-
version: Buffer;
|
|
9
|
-
modulus: Buffer;
|
|
10
|
-
publicExponent: Buffer;
|
|
11
|
-
privateExponent: Buffer;
|
|
12
|
-
prime1: Buffer;
|
|
13
|
-
prime2: Buffer;
|
|
14
|
-
exponent1: Buffer;
|
|
15
|
-
exponent2: Buffer;
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function f(buffer: Buffer, b: BlockInfo) {
|
|
20
|
-
return buffer.
|
|
21
|
-
}
|
|
22
|
-
const doDebug= !!process.env.DEBUG;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param privateKey RSAPrivateKey ::= SEQUENCE {
|
|
26
|
-
* version Version,
|
|
27
|
-
* modulus INTEGER, -- n
|
|
28
|
-
* publicExponent INTEGER, -- e
|
|
29
|
-
* privateExponent INTEGER, -- d
|
|
30
|
-
* prime1 INTEGER, -- p
|
|
31
|
-
* prime2 INTEGER, -- q
|
|
32
|
-
* exponent1 INTEGER, -- d mod (p-1)
|
|
33
|
-
* exponent2 INTEGER, -- d mod (q-1)
|
|
34
|
-
* coefficient INTEGER, -- (inverse of q) mod p
|
|
35
|
-
* otherPrimeInfos OtherPrimeInfos OPTIONAL
|
|
36
|
-
}
|
|
37
|
-
*/
|
|
38
|
-
export function explorePrivateKey(privateKey: PrivateKey): PrivateKeyInternals {
|
|
39
|
-
assert(privateKey instanceof Buffer);
|
|
40
|
-
const block_info = readTag(privateKey, 0);
|
|
41
|
-
const blocks = _readStruct(privateKey, block_info);
|
|
42
|
-
|
|
43
|
-
if (blocks.length === 9) {
|
|
44
|
-
// alice_rsa
|
|
45
|
-
const version = f(privateKey,blocks[0]);// _readIntegerAsByteString(privateKey, blocks1[0]);
|
|
46
|
-
const modulus= f(privateKey, blocks[1]);
|
|
47
|
-
const publicExponent= f(privateKey, blocks[2]);
|
|
48
|
-
const privateExponent= f(privateKey, blocks[3]);
|
|
49
|
-
const prime1= f(privateKey, blocks[4]);
|
|
50
|
-
const prime2= f(privateKey, blocks[5]);
|
|
51
|
-
const exponent1= f(privateKey, blocks[6]);
|
|
52
|
-
const exponent2= f(privateKey, blocks[7]);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
version,
|
|
56
|
-
modulus,
|
|
57
|
-
publicExponent,
|
|
58
|
-
privateExponent,
|
|
59
|
-
prime1,
|
|
60
|
-
prime2,
|
|
61
|
-
exponent1,
|
|
62
|
-
exponent2
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
/* istanbul ignore next */
|
|
67
|
-
if (doDebug) {
|
|
68
|
-
// tslint:disable:no-console
|
|
69
|
-
console.log("--------------------")
|
|
70
|
-
console.log(block_info);
|
|
71
|
-
|
|
72
|
-
// tslint:disable:no-console
|
|
73
|
-
console.log(
|
|
74
|
-
blocks.map((b) => ({
|
|
75
|
-
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
76
|
-
l: b.length,
|
|
77
|
-
p: b.position,
|
|
78
|
-
buff: privateKey.
|
|
79
|
-
}))
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const b = blocks[2];
|
|
84
|
-
const bb = privateKey.
|
|
85
|
-
const block_info1 = readTag(bb, 0);
|
|
86
|
-
const blocks1 = _readStruct(bb, block_info1);
|
|
87
|
-
|
|
88
|
-
/* istanbul ignore next */
|
|
89
|
-
if (doDebug) {
|
|
90
|
-
// tslint:disable:no-console
|
|
91
|
-
console.log(
|
|
92
|
-
blocks1.map((b) => ({
|
|
93
|
-
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
94
|
-
l: b.length,
|
|
95
|
-
p: b.position,
|
|
96
|
-
buff: bb.
|
|
97
|
-
}))
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const version =f(bb, blocks1[0]);
|
|
102
|
-
const modulus= f(bb, blocks1[1]);
|
|
103
|
-
const publicExponent= f(bb, blocks1[2]);
|
|
104
|
-
const privateExponent= f(bb, blocks1[3]);
|
|
105
|
-
const prime1= f(bb, blocks1[4]);
|
|
106
|
-
const prime2= f(bb, blocks1[5]);
|
|
107
|
-
const exponent1= f(bb, blocks1[6]);
|
|
108
|
-
const exponent2= f(bb, blocks1[7]);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
version,
|
|
113
|
-
modulus,
|
|
114
|
-
publicExponent,
|
|
115
|
-
privateExponent,
|
|
116
|
-
prime1,
|
|
117
|
-
prime2,
|
|
118
|
-
exponent1,
|
|
119
|
-
exponent2
|
|
120
|
-
};
|
|
121
|
-
}
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import { BlockInfo, readTag, TagType, _readIntegerAsByteString, _readStruct } from "./asn1";
|
|
3
|
+
import { PrivateKey } from "./common";
|
|
4
|
+
|
|
5
|
+
// tslint:disable:no-empty-interface
|
|
6
|
+
export interface PrivateKeyInternals {
|
|
7
|
+
/***/
|
|
8
|
+
version: Buffer;
|
|
9
|
+
modulus: Buffer;
|
|
10
|
+
publicExponent: Buffer;
|
|
11
|
+
privateExponent: Buffer;
|
|
12
|
+
prime1: Buffer;
|
|
13
|
+
prime2: Buffer;
|
|
14
|
+
exponent1: Buffer;
|
|
15
|
+
exponent2: Buffer;
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function f(buffer: Buffer, b: BlockInfo) {
|
|
20
|
+
return buffer.subarray(b.position+1, b.position + b.length)
|
|
21
|
+
}
|
|
22
|
+
const doDebug= !!process.env.DEBUG;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param privateKey RSAPrivateKey ::= SEQUENCE {
|
|
26
|
+
* version Version,
|
|
27
|
+
* modulus INTEGER, -- n
|
|
28
|
+
* publicExponent INTEGER, -- e
|
|
29
|
+
* privateExponent INTEGER, -- d
|
|
30
|
+
* prime1 INTEGER, -- p
|
|
31
|
+
* prime2 INTEGER, -- q
|
|
32
|
+
* exponent1 INTEGER, -- d mod (p-1)
|
|
33
|
+
* exponent2 INTEGER, -- d mod (q-1)
|
|
34
|
+
* coefficient INTEGER, -- (inverse of q) mod p
|
|
35
|
+
* otherPrimeInfos OtherPrimeInfos OPTIONAL
|
|
36
|
+
}
|
|
37
|
+
*/
|
|
38
|
+
export function explorePrivateKey(privateKey: PrivateKey): PrivateKeyInternals {
|
|
39
|
+
assert(privateKey instanceof Buffer);
|
|
40
|
+
const block_info = readTag(privateKey, 0);
|
|
41
|
+
const blocks = _readStruct(privateKey, block_info);
|
|
42
|
+
|
|
43
|
+
if (blocks.length === 9) {
|
|
44
|
+
// alice_rsa
|
|
45
|
+
const version = f(privateKey,blocks[0]);// _readIntegerAsByteString(privateKey, blocks1[0]);
|
|
46
|
+
const modulus= f(privateKey, blocks[1]);
|
|
47
|
+
const publicExponent= f(privateKey, blocks[2]);
|
|
48
|
+
const privateExponent= f(privateKey, blocks[3]);
|
|
49
|
+
const prime1= f(privateKey, blocks[4]);
|
|
50
|
+
const prime2= f(privateKey, blocks[5]);
|
|
51
|
+
const exponent1= f(privateKey, blocks[6]);
|
|
52
|
+
const exponent2= f(privateKey, blocks[7]);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
version,
|
|
56
|
+
modulus,
|
|
57
|
+
publicExponent,
|
|
58
|
+
privateExponent,
|
|
59
|
+
prime1,
|
|
60
|
+
prime2,
|
|
61
|
+
exponent1,
|
|
62
|
+
exponent2
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
/* istanbul ignore next */
|
|
67
|
+
if (doDebug) {
|
|
68
|
+
// tslint:disable:no-console
|
|
69
|
+
console.log("-------------------- private key:")
|
|
70
|
+
console.log(block_info);
|
|
71
|
+
|
|
72
|
+
// tslint:disable:no-console
|
|
73
|
+
console.log(
|
|
74
|
+
blocks.map((b) => ({
|
|
75
|
+
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
76
|
+
l: b.length,
|
|
77
|
+
p: b.position,
|
|
78
|
+
buff: privateKey.subarray(b.position, b.position + b.length).toString("hex"),
|
|
79
|
+
}))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const b = blocks[2];
|
|
84
|
+
const bb = privateKey.subarray(b.position, b.position + b.length);
|
|
85
|
+
const block_info1 = readTag(bb, 0);
|
|
86
|
+
const blocks1 = _readStruct(bb, block_info1);
|
|
87
|
+
|
|
88
|
+
/* istanbul ignore next */
|
|
89
|
+
if (doDebug) {
|
|
90
|
+
// tslint:disable:no-console
|
|
91
|
+
console.log(
|
|
92
|
+
blocks1.map((b) => ({
|
|
93
|
+
tag: TagType[b.tag] + " 0x" + b.tag.toString(16),
|
|
94
|
+
l: b.length,
|
|
95
|
+
p: b.position,
|
|
96
|
+
buff: bb.subarray(b.position, b.position + b.length).toString("hex"),
|
|
97
|
+
}))
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const version =f(bb, blocks1[0]);
|
|
102
|
+
const modulus= f(bb, blocks1[1]);
|
|
103
|
+
const publicExponent= f(bb, blocks1[2]);
|
|
104
|
+
const privateExponent= f(bb, blocks1[3]);
|
|
105
|
+
const prime1= f(bb, blocks1[4]);
|
|
106
|
+
const prime2= f(bb, blocks1[5]);
|
|
107
|
+
const exponent1= f(bb, blocks1[6]);
|
|
108
|
+
const exponent2= f(bb, blocks1[7]);
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
version,
|
|
113
|
+
modulus,
|
|
114
|
+
publicExponent,
|
|
115
|
+
privateExponent,
|
|
116
|
+
prime1,
|
|
117
|
+
prime2,
|
|
118
|
+
exponent1,
|
|
119
|
+
exponent2
|
|
120
|
+
};
|
|
121
|
+
}
|
package/source/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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";
|