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.
Files changed (108) hide show
  1. package/.fossa.yml +18 -18
  2. package/.github/FUNDING.yml +12 -12
  3. package/.github/workflows/main.yml +32 -32
  4. package/.prettierrc.js +6 -6
  5. package/LICENSE +23 -22
  6. package/README.md +14 -14
  7. package/dist/source/asn1.d.ts +73 -73
  8. package/dist/source/asn1.js +359 -359
  9. package/dist/source/buffer_utils.d.ts +6 -6
  10. package/dist/source/buffer_utils.js +21 -21
  11. package/dist/source/certificate_matches_private_key.d.ts +2 -0
  12. package/dist/source/certificate_matches_private_key.js +22 -0
  13. package/dist/source/certificate_matches_private_key.js.map +1 -0
  14. package/dist/source/common.d.ts +12 -12
  15. package/dist/source/common.js +2 -2
  16. package/dist/source/crypto_explore_certificate.d.ts +107 -107
  17. package/dist/source/crypto_explore_certificate.js +601 -600
  18. package/dist/source/crypto_explore_certificate.js.map +1 -1
  19. package/dist/source/crypto_utils.d.ts +80 -78
  20. package/dist/source/crypto_utils.js +312 -280
  21. package/dist/source/crypto_utils.js.map +1 -1
  22. package/dist/source/derived_keys.d.ts +72 -72
  23. package/dist/source/derived_keys.js +248 -248
  24. package/dist/source/explore_certificate.d.ts +30 -30
  25. package/dist/source/explore_certificate.js +43 -43
  26. package/dist/source/explore_certificate_revocation_list.d.ts +28 -28
  27. package/dist/source/explore_certificate_revocation_list.js +69 -69
  28. package/dist/source/explore_certificate_signing_request.d.ts +13 -13
  29. package/dist/source/explore_certificate_signing_request.js +44 -44
  30. package/dist/source/explore_private_key.d.ts +29 -29
  31. package/dist/source/explore_private_key.js +96 -96
  32. package/dist/source/explore_private_key.js.map +1 -1
  33. package/dist/source/index.d.ts +13 -13
  34. package/dist/source/index.js +29 -29
  35. package/dist/source/oid_map.d.ts +7 -7
  36. package/dist/source/oid_map.js +303 -303
  37. package/dist/source/public_private_match.d.ts +3 -3
  38. package/dist/source/public_private_match.js +37 -16
  39. package/dist/source/public_private_match.js.map +1 -1
  40. package/dist/source/verify_certificate_signature.d.ts +10 -10
  41. package/dist/source/verify_certificate_signature.js +101 -101
  42. package/dist/source_nodejs/index.d.ts +3 -3
  43. package/dist/source_nodejs/index.js +19 -19
  44. package/dist/source_nodejs/read.d.ts +29 -29
  45. package/dist/source_nodejs/read.js +94 -94
  46. package/dist/source_nodejs/read.js.map +1 -1
  47. package/dist/source_nodejs/read_certificate_revocation_list.d.ts +2 -2
  48. package/dist/source_nodejs/read_certificate_revocation_list.js +27 -27
  49. package/dist/source_nodejs/read_certificate_signing_request.d.ts +3 -3
  50. package/dist/source_nodejs/read_certificate_signing_request.js +27 -27
  51. package/index.d.ts +2 -2
  52. package/index.js +4 -4
  53. package/index_web.js +3 -3
  54. package/package.json +12 -12
  55. package/source/asn1.ts +404 -404
  56. package/source/buffer_utils.ts +18 -18
  57. package/source/common.ts +13 -13
  58. package/source/crypto_explore_certificate.ts +764 -763
  59. package/source/crypto_utils.ts +359 -321
  60. package/source/derived_keys.ts +287 -287
  61. package/source/explore_certificate.ts +66 -66
  62. package/source/explore_certificate_revocation_list.ts +122 -122
  63. package/source/explore_certificate_signing_request.ts +58 -58
  64. package/source/explore_private_key.ts +121 -121
  65. package/source/index.ts +13 -13
  66. package/source/oid_map.ts +310 -310
  67. package/source/public_private_match.ts +41 -18
  68. package/source/verify_certificate_signature.ts +105 -105
  69. package/source_nodejs/index.ts +2 -2
  70. package/source_nodejs/read.ts +95 -95
  71. package/source_nodejs/read_certificate_revocation_list.ts +14 -14
  72. package/source_nodejs/read_certificate_signing_request.ts +17 -17
  73. package/test_certificate.ts +34 -34
  74. package/tsconfig.json +18 -18
  75. package/tslint.json +34 -34
  76. package/dist/asn1.d.ts +0 -69
  77. package/dist/asn1.js +0 -349
  78. package/dist/asn1.js.map +0 -1
  79. package/dist/buffer_utils.d.ts +0 -6
  80. package/dist/buffer_utils.js +0 -22
  81. package/dist/buffer_utils.js.map +0 -1
  82. package/dist/common.d.ts +0 -11
  83. package/dist/common.js +0 -3
  84. package/dist/common.js.map +0 -1
  85. package/dist/crypto_explore_certificate.d.ts +0 -95
  86. package/dist/crypto_explore_certificate.js +0 -547
  87. package/dist/crypto_explore_certificate.js.map +0 -1
  88. package/dist/crypto_utils.d.ts +0 -106
  89. package/dist/crypto_utils.js +0 -370
  90. package/dist/crypto_utils.js.map +0 -1
  91. package/dist/derived_keys.d.ts +0 -72
  92. package/dist/derived_keys.js +0 -247
  93. package/dist/derived_keys.js.map +0 -1
  94. package/dist/explore_certificate.d.ts +0 -30
  95. package/dist/explore_certificate.js +0 -44
  96. package/dist/explore_certificate.js.map +0 -1
  97. package/dist/explore_certificate_revocation_list.d.ts +0 -30
  98. package/dist/explore_certificate_revocation_list.js +0 -67
  99. package/dist/explore_certificate_revocation_list.js.map +0 -1
  100. package/dist/index.d.ts +0 -10
  101. package/dist/index.js +0 -23
  102. package/dist/index.js.map +0 -1
  103. package/dist/oid_map.d.ts +0 -7
  104. package/dist/oid_map.js +0 -262
  105. package/dist/oid_map.js.map +0 -1
  106. package/dist/verify_cerficate_signature.d.ts +0 -10
  107. package/dist/verify_cerficate_signature.js +0 -102
  108. package/dist/verify_cerficate_signature.js.map +0 -1
@@ -1,6 +1,6 @@
1
- /// <reference types="node" />
2
- /**
3
- * @internal
4
- * @private
5
- */
6
- export declare const createFastUninitializedBuffer: (size: number) => Buffer;
1
+ /// <reference types="node" />
2
+ /**
3
+ * @internal
4
+ * @private
5
+ */
6
+ export declare const createFastUninitializedBuffer: (size: number) => Buffer;
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFastUninitializedBuffer = void 0;
4
- //
5
- // note: new Buffer(size)# is deprecated since: v6.0. and is replaced with Buffer.allocUnsafe
6
- // to ensure backward compatibility we have to replace
7
- // new Buffer(size) with createFastUninitializedBuffer(size)
8
- //
9
- // Buffer.alloc and Buffer.allocUnsafe have been introduced in nodejs 5.1.0
10
- // in node 0.11 new Buffer
11
- //
12
- /**
13
- * @internal
14
- * @private
15
- */
16
- exports.createFastUninitializedBuffer = Buffer.allocUnsafe
17
- ? Buffer.allocUnsafe
18
- : (size) => {
19
- // istanbul ignore next
20
- return new Buffer(size);
21
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFastUninitializedBuffer = void 0;
4
+ //
5
+ // note: new Buffer(size)# is deprecated since: v6.0. and is replaced with Buffer.allocUnsafe
6
+ // to ensure backward compatibility we have to replace
7
+ // new Buffer(size) with createFastUninitializedBuffer(size)
8
+ //
9
+ // Buffer.alloc and Buffer.allocUnsafe have been introduced in nodejs 5.1.0
10
+ // in node 0.11 new Buffer
11
+ //
12
+ /**
13
+ * @internal
14
+ * @private
15
+ */
16
+ exports.createFastUninitializedBuffer = Buffer.allocUnsafe
17
+ ? Buffer.allocUnsafe
18
+ : (size) => {
19
+ // istanbul ignore next
20
+ return new Buffer(size);
21
+ };
22
22
  //# sourceMappingURL=buffer_utils.js.map
@@ -0,0 +1,2 @@
1
+ import { Certificate, PrivateKey } from "./common";
2
+ export declare function certificateMatchesPrivateKey(certificate: Certificate, privateKey: PrivateKey): boolean;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.certificateMatchesPrivateKey = void 0;
4
+ const crypto_utils_1 = require("./crypto_utils");
5
+ /**
6
+ * check that the given certificate matches the given private key
7
+ * @param certificate
8
+ * @param privateKey
9
+ */
10
+ function certificateMatchesPrivateKeyPEM(certificate, privateKey) {
11
+ const initialBuffer = Buffer.from("Lorem Ipsum");
12
+ const encryptedBuffer = (0, crypto_utils_1.publicEncrypt_long)(initialBuffer, certificate, 256, 11);
13
+ const decryptedBuffer = (0, crypto_utils_1.privateDecrypt_long)(encryptedBuffer, privateKey, 256);
14
+ return initialBuffer.toString("utf-8") === decryptedBuffer.toString("utf-8");
15
+ }
16
+ function certificateMatchesPrivateKey(certificate, privateKey) {
17
+ const certificatePEM = (0, crypto_utils_1.toPem)(certificate, "CERTIFICATE");
18
+ const privateKeyPEM = (0, crypto_utils_1.toPem)(privateKey, "RSA PRIVATE KEY");
19
+ return certificateMatchesPrivateKeyPEM(certificatePEM, privateKeyPEM);
20
+ }
21
+ exports.certificateMatchesPrivateKey = certificateMatchesPrivateKey;
22
+ //# sourceMappingURL=certificate_matches_private_key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certificate_matches_private_key.js","sourceRoot":"","sources":["../../source/certificate_matches_private_key.ts"],"names":[],"mappings":";;;AACA,iDAAgF;AAEhF;;;;GAIG;AACH,SAAS,+BAA+B,CAAC,WAA2B,EAAE,UAAyB;IAC3F,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,IAAA,iCAAkB,EAAC,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,IAAA,kCAAmB,EAAC,eAAe,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC9E,OAAO,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,4BAA4B,CAAC,WAAwB,EAAE,UAAsB;IACzF,MAAM,cAAc,GAAG,IAAA,oBAAK,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,OAAO,+BAA+B,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAC1E,CAAC;AAJD,oEAIC"}
@@ -1,12 +1,12 @@
1
- /// <reference types="node" />
2
- export declare type Nonce = Buffer;
3
- export declare type PEM = string;
4
- export declare type DER = Buffer;
5
- export declare type Certificate = DER;
6
- export declare type CertificatePEM = PEM;
7
- export declare type PrivateKey = DER;
8
- export declare type PrivateKeyPEM = PEM;
9
- export declare type PublicKey = DER;
10
- export declare type PublicKeyPEM = PEM;
11
- export declare type Signature = Buffer;
12
- export declare type CertificateRevocationList = Buffer;
1
+ /// <reference types="node" />
2
+ export type Nonce = Buffer;
3
+ export type PEM = string;
4
+ export type DER = Buffer;
5
+ export type Certificate = DER;
6
+ export type CertificatePEM = PEM;
7
+ export type PrivateKey = DER;
8
+ export type PrivateKeyPEM = PEM;
9
+ export type PublicKey = DER;
10
+ export type PublicKeyPEM = PEM;
11
+ export type Signature = Buffer;
12
+ export type CertificateRevocationList = Buffer;
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=common.js.map
@@ -1,107 +1,107 @@
1
- /**
2
- * @module node_opcua_crypto
3
- */
4
- /// <reference types="node" />
5
- import { BlockInfo, AlgorithmIdentifier, SignatureValue, DirectoryName } from "./asn1";
6
- import { Certificate } from "./common";
7
- import { PublicKeyLength } from "./explore_certificate";
8
- export interface AttributeTypeAndValue {
9
- [key: string]: any;
10
- }
11
- export interface Validity {
12
- notBefore: Date;
13
- notAfter: Date;
14
- }
15
- export interface X509KeyUsage {
16
- digitalSignature: boolean;
17
- nonRepudiation: boolean;
18
- keyEncipherment: boolean;
19
- dataEncipherment: boolean;
20
- keyAgreement: boolean;
21
- keyCertSign: boolean;
22
- cRLSign: boolean;
23
- encipherOnly: boolean;
24
- decipherOnly: boolean;
25
- }
26
- export interface X509ExtKeyUsage {
27
- clientAuth: boolean;
28
- serverAuth: boolean;
29
- codeSigning: boolean;
30
- emailProtection: boolean;
31
- timeStamping: boolean;
32
- ocspSigning: boolean;
33
- ipsecEndSystem: boolean;
34
- ipsecTunnel: boolean;
35
- ipsecUser: boolean;
36
- }
37
- export interface SubjectPublicKey {
38
- modulus: Buffer;
39
- }
40
- export declare function _readExtension(buffer: Buffer, block: BlockInfo): {
41
- identifier: {
42
- oid: string;
43
- name: string;
44
- };
45
- value: any;
46
- };
47
- export interface SubjectPublicKeyInfo {
48
- algorithm: string;
49
- keyLength: PublicKeyLength;
50
- subjectPublicKey: SubjectPublicKey;
51
- }
52
- export interface BasicConstraints {
53
- critical: boolean;
54
- cA: boolean;
55
- pathLengthConstraint?: number;
56
- }
57
- export interface AuthorityKeyIdentifier {
58
- keyIdentifier: string | null;
59
- authorityCertIssuer: DirectoryName | null;
60
- authorityCertIssuerFingerPrint: string;
61
- serial: string | null;
62
- }
63
- export interface CertificateExtension {
64
- basicConstraints: BasicConstraints;
65
- subjectKeyIdentifier?: string;
66
- authorityKeyIdentifier?: AuthorityKeyIdentifier;
67
- keyUsage?: X509KeyUsage;
68
- extKeyUsage?: X509ExtKeyUsage;
69
- subjectAltName?: any;
70
- }
71
- export interface TbsCertificate {
72
- version: number;
73
- serialNumber: string;
74
- issuer: any;
75
- signature: AlgorithmIdentifier;
76
- validity: Validity;
77
- subject: DirectoryName;
78
- subjectFingerPrint: string;
79
- subjectPublicKeyInfo: SubjectPublicKeyInfo;
80
- extensions: CertificateExtension | null;
81
- }
82
- export declare function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate;
83
- export interface CertificateInternals {
84
- tbsCertificate: TbsCertificate;
85
- signatureAlgorithm: AlgorithmIdentifier;
86
- signatureValue: SignatureValue;
87
- }
88
- /**
89
- * explore a certificate structure
90
- * @param certificate
91
- * @returns a json object that exhibits the internal data of the certificate
92
- */
93
- export declare function exploreCertificate(certificate: Certificate): CertificateInternals;
94
- /**
95
- * @method split_der
96
- * split a multi chain certificates
97
- * @param certificateChain the certificate chain in der (binary) format}
98
- * @returns an array of Der , each element of the array is one certificate of the chain
99
- */
100
- export declare function split_der(certificateChain: Certificate): Certificate[];
101
- /**
102
- * @method combine_der
103
- * combine an array of certificates into a single blob
104
- * @param certificates a array with the individual DER certificates of the chain
105
- * @return a concatenated buffer containing the certificates
106
- */
107
- export declare function combine_der(certificates: Certificate[]): Certificate;
1
+ /**
2
+ * @module node_opcua_crypto
3
+ */
4
+ /// <reference types="node" />
5
+ import { BlockInfo, AlgorithmIdentifier, SignatureValue, DirectoryName } from "./asn1";
6
+ import { Certificate } from "./common";
7
+ import { PublicKeyLength } from "./explore_certificate";
8
+ export interface AttributeTypeAndValue {
9
+ [key: string]: any;
10
+ }
11
+ export interface Validity {
12
+ notBefore: Date;
13
+ notAfter: Date;
14
+ }
15
+ export interface X509KeyUsage {
16
+ digitalSignature: boolean;
17
+ nonRepudiation: boolean;
18
+ keyEncipherment: boolean;
19
+ dataEncipherment: boolean;
20
+ keyAgreement: boolean;
21
+ keyCertSign: boolean;
22
+ cRLSign: boolean;
23
+ encipherOnly: boolean;
24
+ decipherOnly: boolean;
25
+ }
26
+ export interface X509ExtKeyUsage {
27
+ clientAuth: boolean;
28
+ serverAuth: boolean;
29
+ codeSigning: boolean;
30
+ emailProtection: boolean;
31
+ timeStamping: boolean;
32
+ ocspSigning: boolean;
33
+ ipsecEndSystem: boolean;
34
+ ipsecTunnel: boolean;
35
+ ipsecUser: boolean;
36
+ }
37
+ export interface SubjectPublicKey {
38
+ modulus: Buffer;
39
+ }
40
+ export declare function _readExtension(buffer: Buffer, block: BlockInfo): {
41
+ identifier: {
42
+ oid: string;
43
+ name: string;
44
+ };
45
+ value: any;
46
+ };
47
+ export interface SubjectPublicKeyInfo {
48
+ algorithm: string;
49
+ keyLength: PublicKeyLength;
50
+ subjectPublicKey: SubjectPublicKey;
51
+ }
52
+ export interface BasicConstraints {
53
+ critical: boolean;
54
+ cA: boolean;
55
+ pathLengthConstraint?: number;
56
+ }
57
+ export interface AuthorityKeyIdentifier {
58
+ keyIdentifier: string | null;
59
+ authorityCertIssuer: DirectoryName | null;
60
+ authorityCertIssuerFingerPrint: string;
61
+ serial: string | null;
62
+ }
63
+ export interface CertificateExtension {
64
+ basicConstraints: BasicConstraints;
65
+ subjectKeyIdentifier?: string;
66
+ authorityKeyIdentifier?: AuthorityKeyIdentifier;
67
+ keyUsage?: X509KeyUsage;
68
+ extKeyUsage?: X509ExtKeyUsage;
69
+ subjectAltName?: any;
70
+ }
71
+ export interface TbsCertificate {
72
+ version: number;
73
+ serialNumber: string;
74
+ issuer: any;
75
+ signature: AlgorithmIdentifier;
76
+ validity: Validity;
77
+ subject: DirectoryName;
78
+ subjectFingerPrint: string;
79
+ subjectPublicKeyInfo: SubjectPublicKeyInfo;
80
+ extensions: CertificateExtension | null;
81
+ }
82
+ export declare function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate;
83
+ export interface CertificateInternals {
84
+ tbsCertificate: TbsCertificate;
85
+ signatureAlgorithm: AlgorithmIdentifier;
86
+ signatureValue: SignatureValue;
87
+ }
88
+ /**
89
+ * explore a certificate structure
90
+ * @param certificate
91
+ * @returns a json object that exhibits the internal data of the certificate
92
+ */
93
+ export declare function exploreCertificate(certificate: Certificate): CertificateInternals;
94
+ /**
95
+ * @method split_der
96
+ * split a multi chain certificates
97
+ * @param certificateChain the certificate chain in der (binary) format}
98
+ * @returns an array of Der , each element of the array is one certificate of the chain
99
+ */
100
+ export declare function split_der(certificateChain: Certificate): Certificate[];
101
+ /**
102
+ * @method combine_der
103
+ * combine an array of certificates into a single blob
104
+ * @param certificates a array with the individual DER certificates of the chain
105
+ * @return a concatenated buffer containing the certificates
106
+ */
107
+ export declare function combine_der(certificates: Certificate[]): Certificate;