react-native-quick-crypto 1.0.11 → 1.0.13
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/android/CMakeLists.txt +7 -0
- package/cpp/cipher/CCMCipher.cpp +4 -1
- package/cpp/cipher/ChaCha20Cipher.cpp +3 -1
- package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +5 -5
- package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +1 -2
- package/cpp/cipher/HybridCipher.cpp +10 -1
- package/cpp/cipher/HybridCipher.hpp +2 -0
- package/cpp/cipher/HybridRsaCipher.cpp +0 -13
- package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +7 -5
- package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +1 -2
- package/cpp/cipher/XSalsa20Cipher.cpp +4 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +7 -5
- package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +1 -2
- package/cpp/ecdh/HybridECDH.cpp +20 -133
- package/cpp/keys/HybridKeyObjectHandle.cpp +144 -141
- package/cpp/keys/HybridKeyObjectHandle.hpp +6 -3
- package/cpp/keys/KeyObjectData.hpp +2 -0
- package/cpp/kmac/HybridKmac.cpp +83 -0
- package/cpp/kmac/HybridKmac.hpp +31 -0
- package/cpp/mldsa/HybridMlDsaKeyPair.cpp +11 -20
- package/cpp/mldsa/HybridMlDsaKeyPair.hpp +4 -2
- package/cpp/mlkem/HybridMlKemKeyPair.cpp +319 -0
- package/cpp/mlkem/HybridMlKemKeyPair.hpp +48 -0
- package/cpp/sign/SignUtils.hpp +9 -26
- package/cpp/utils/QuickCryptoUtils.cpp +44 -0
- package/cpp/utils/QuickCryptoUtils.hpp +39 -0
- package/cpp/x509/HybridX509Certificate.cpp +174 -0
- package/cpp/x509/HybridX509Certificate.hpp +51 -0
- package/lib/commonjs/cipher.js +15 -2
- package/lib/commonjs/cipher.js.map +1 -1
- package/lib/commonjs/dhKeyPair.js +3 -3
- package/lib/commonjs/dhKeyPair.js.map +1 -1
- package/lib/commonjs/dsa.js +3 -3
- package/lib/commonjs/dsa.js.map +1 -1
- package/lib/commonjs/ec.js +18 -18
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/ed.js +9 -9
- package/lib/commonjs/ed.js.map +1 -1
- package/lib/commonjs/hash.js +17 -12
- package/lib/commonjs/hash.js.map +1 -1
- package/lib/commonjs/hkdf.js.map +1 -1
- package/lib/commonjs/index.js +22 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +2 -2
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/keys/index.js +24 -0
- package/lib/commonjs/keys/index.js.map +1 -1
- package/lib/commonjs/keys/publicCipher.js +2 -2
- package/lib/commonjs/keys/publicCipher.js.map +1 -1
- package/lib/commonjs/keys/signVerify.js +0 -2
- package/lib/commonjs/keys/signVerify.js.map +1 -1
- package/lib/commonjs/mlkem.js +219 -0
- package/lib/commonjs/mlkem.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +18 -1
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/rsa.js +7 -7
- package/lib/commonjs/rsa.js.map +1 -1
- package/lib/commonjs/specs/kmac.nitro.js +6 -0
- package/lib/commonjs/specs/kmac.nitro.js.map +1 -0
- package/lib/commonjs/specs/mlKemKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/mlKemKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/x509certificate.nitro.js +6 -0
- package/lib/commonjs/specs/x509certificate.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +292 -112
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/conversion.js +3 -3
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/hashnames.js +31 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/x509certificate.js +189 -0
- package/lib/commonjs/x509certificate.js.map +1 -0
- package/lib/module/cipher.js +16 -3
- package/lib/module/cipher.js.map +1 -1
- package/lib/module/dhKeyPair.js +1 -1
- package/lib/module/dhKeyPair.js.map +1 -1
- package/lib/module/dsa.js +1 -1
- package/lib/module/dsa.js.map +1 -1
- package/lib/module/ec.js +6 -6
- package/lib/module/ec.js.map +1 -1
- package/lib/module/ed.js +1 -1
- package/lib/module/ed.js.map +1 -1
- package/lib/module/hash.js +17 -12
- package/lib/module/hash.js.map +1 -1
- package/lib/module/hkdf.js.map +1 -1
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +2 -2
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/keys/index.js +25 -1
- package/lib/module/keys/index.js.map +1 -1
- package/lib/module/keys/publicCipher.js +2 -2
- package/lib/module/keys/publicCipher.js.map +1 -1
- package/lib/module/keys/signVerify.js +0 -2
- package/lib/module/keys/signVerify.js.map +1 -1
- package/lib/module/mlkem.js +211 -0
- package/lib/module/mlkem.js.map +1 -0
- package/lib/module/pbkdf2.js +18 -1
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/rsa.js +1 -1
- package/lib/module/rsa.js.map +1 -1
- package/lib/module/specs/kmac.nitro.js +4 -0
- package/lib/module/specs/kmac.nitro.js.map +1 -0
- package/lib/module/specs/mlKemKeyPair.nitro.js +4 -0
- package/lib/module/specs/mlKemKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/x509certificate.nitro.js +4 -0
- package/lib/module/specs/x509certificate.nitro.js.map +1 -0
- package/lib/module/subtle.js +292 -112
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/conversion.js +3 -4
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/hashnames.js +31 -0
- package/lib/module/utils/hashnames.js.map +1 -1
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/x509certificate.js +184 -0
- package/lib/module/x509certificate.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/cipher.d.ts +3 -0
- package/lib/typescript/cipher.d.ts.map +1 -1
- package/lib/typescript/dhKeyPair.d.ts +1 -1
- package/lib/typescript/dhKeyPair.d.ts.map +1 -1
- package/lib/typescript/dsa.d.ts +1 -1
- package/lib/typescript/dsa.d.ts.map +1 -1
- package/lib/typescript/ec.d.ts +1 -1
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/ed.d.ts +1 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- package/lib/typescript/hash.d.ts.map +1 -1
- package/lib/typescript/hkdf.d.ts +2 -6
- package/lib/typescript/hkdf.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +15 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +5 -5
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/index.d.ts +2 -2
- package/lib/typescript/keys/index.d.ts.map +1 -1
- package/lib/typescript/keys/signVerify.d.ts.map +1 -1
- package/lib/typescript/mlkem.d.ts +30 -0
- package/lib/typescript/mlkem.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +2 -2
- package/lib/typescript/pbkdf2.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +1 -1
- package/lib/typescript/rsa.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/kmac.nitro.d.ts +10 -0
- package/lib/typescript/specs/kmac.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts +18 -0
- package/lib/typescript/specs/mlKemKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/x509certificate.nitro.d.ts +34 -0
- package/lib/typescript/specs/x509certificate.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +10 -0
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/hashnames.d.ts +1 -1
- package/lib/typescript/utils/hashnames.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +13 -7
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/x509certificate.d.ts +64 -0
- package/lib/typescript/x509certificate.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +3 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +30 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +30 -0
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +12 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKmacSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridKmacSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp +31 -0
- package/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp +46 -0
- package/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp +96 -0
- package/package.json +4 -1
- package/src/cipher.ts +17 -3
- package/src/dhKeyPair.ts +1 -1
- package/src/dsa.ts +1 -1
- package/src/ec.ts +9 -9
- package/src/ed.ts +2 -2
- package/src/hash.ts +34 -11
- package/src/hkdf.ts +2 -7
- package/src/index.ts +7 -0
- package/src/keys/classes.ts +10 -9
- package/src/keys/index.ts +37 -2
- package/src/keys/publicCipher.ts +2 -2
- package/src/keys/signVerify.ts +0 -5
- package/src/mlkem.ts +350 -0
- package/src/pbkdf2.ts +34 -5
- package/src/rsa.ts +1 -1
- package/src/specs/keyObjectHandle.nitro.ts +5 -0
- package/src/specs/kmac.nitro.ts +12 -0
- package/src/specs/mlKemKeyPair.nitro.ts +32 -0
- package/src/specs/x509certificate.nitro.ts +38 -0
- package/src/subtle.ts +551 -125
- package/src/utils/conversion.ts +10 -4
- package/src/utils/hashnames.ts +33 -2
- package/src/utils/types.ts +42 -5
- package/src/x509certificate.ts +277 -0
package/src/utils/conversion.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer';
|
|
2
2
|
import { Buffer as SafeBuffer } from 'safe-buffer';
|
|
3
3
|
import type { ABV, BinaryLikeNode, BufferLike } from './types';
|
|
4
|
-
import { KeyObject } from '../keys/classes';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Converts supplied argument to an ArrayBuffer. Note this does not copy the
|
|
@@ -133,9 +132,16 @@ export function binaryLikeToArrayBuffer(
|
|
|
133
132
|
// }
|
|
134
133
|
// }
|
|
135
134
|
|
|
136
|
-
// KeyObject
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
// KeyObject — duck-typed via Symbol.toStringTag to avoid circular dependency
|
|
136
|
+
// with keys/classes. The type assertion must match KeyObjectHandle.exportKey().
|
|
137
|
+
if (
|
|
138
|
+
typeof input === 'object' &&
|
|
139
|
+
input != null &&
|
|
140
|
+
Object.prototype.toString.call(input) === '[object KeyObject]'
|
|
141
|
+
) {
|
|
142
|
+
return (
|
|
143
|
+
input as { handle: { exportKey(): ArrayBuffer } }
|
|
144
|
+
).handle.exportKey();
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
throw new Error(
|
package/src/utils/hashnames.ts
CHANGED
|
@@ -63,6 +63,26 @@ const kHashNames: HashNames = {
|
|
|
63
63
|
[HashContext.Node]: 'ripemd160',
|
|
64
64
|
[HashContext.WebCrypto]: 'RIPEMD-160',
|
|
65
65
|
},
|
|
66
|
+
'sha3-256': {
|
|
67
|
+
[HashContext.Node]: 'sha3-256',
|
|
68
|
+
[HashContext.WebCrypto]: 'SHA3-256',
|
|
69
|
+
},
|
|
70
|
+
'sha3-384': {
|
|
71
|
+
[HashContext.Node]: 'sha3-384',
|
|
72
|
+
[HashContext.WebCrypto]: 'SHA3-384',
|
|
73
|
+
},
|
|
74
|
+
'sha3-512': {
|
|
75
|
+
[HashContext.Node]: 'sha3-512',
|
|
76
|
+
[HashContext.WebCrypto]: 'SHA3-512',
|
|
77
|
+
},
|
|
78
|
+
shake128: {
|
|
79
|
+
[HashContext.Node]: 'shake128',
|
|
80
|
+
[HashContext.WebCrypto]: 'cSHAKE128',
|
|
81
|
+
},
|
|
82
|
+
shake256: {
|
|
83
|
+
[HashContext.Node]: 'shake256',
|
|
84
|
+
[HashContext.WebCrypto]: 'cSHAKE256',
|
|
85
|
+
},
|
|
66
86
|
};
|
|
67
87
|
|
|
68
88
|
{
|
|
@@ -76,18 +96,29 @@ const kHashNames: HashNames = {
|
|
|
76
96
|
kHashNames[alias] = kHashNames[keys[n]!]!;
|
|
77
97
|
}
|
|
78
98
|
}
|
|
99
|
+
|
|
100
|
+
// Add OpenSSL legacy RSA-* aliases (e.g. RSA-SHA256 -> sha256)
|
|
101
|
+
for (let n: number = 0; n < keys.length; n++) {
|
|
102
|
+
const key = keys[n]!;
|
|
103
|
+
if (key.startsWith('sha') || key === 'ripemd160') {
|
|
104
|
+
const rsaAlias = 'rsa-' + key;
|
|
105
|
+
if (kHashNames[rsaAlias] === undefined) {
|
|
106
|
+
kHashNames[rsaAlias] = kHashNames[key]!;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
export function normalizeHashName(
|
|
82
113
|
algo: string | HashAlgorithm | { name: string } | undefined,
|
|
83
114
|
context: HashContext = HashContext.Node,
|
|
84
|
-
):
|
|
115
|
+
): string {
|
|
85
116
|
if (typeof algo !== 'undefined') {
|
|
86
117
|
const hashName =
|
|
87
118
|
typeof algo === 'string' ? algo : algo.name || algo.toString();
|
|
88
119
|
const normAlgo = hashName.toLowerCase();
|
|
89
120
|
try {
|
|
90
|
-
const alias = kHashNames[normAlgo]![context]
|
|
121
|
+
const alias = kHashNames[normAlgo]![context];
|
|
91
122
|
if (alias) return alias;
|
|
92
123
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
93
124
|
} catch (_e) {
|
package/src/utils/types.ts
CHANGED
|
@@ -40,7 +40,16 @@ export type BinaryLike =
|
|
|
40
40
|
|
|
41
41
|
export type BinaryLikeNode = CipherKey | BinaryLike | KeyObject;
|
|
42
42
|
|
|
43
|
-
export type DigestAlgorithm =
|
|
43
|
+
export type DigestAlgorithm =
|
|
44
|
+
| 'SHA-1'
|
|
45
|
+
| 'SHA-256'
|
|
46
|
+
| 'SHA-384'
|
|
47
|
+
| 'SHA-512'
|
|
48
|
+
| 'SHA3-256'
|
|
49
|
+
| 'SHA3-384'
|
|
50
|
+
| 'SHA3-512'
|
|
51
|
+
| 'cSHAKE128'
|
|
52
|
+
| 'cSHAKE256';
|
|
44
53
|
|
|
45
54
|
export type HashAlgorithm = DigestAlgorithm | 'SHA-224' | 'RIPEMD-160';
|
|
46
55
|
|
|
@@ -65,8 +74,27 @@ export type ECKeyPairAlgorithm = 'ECDSA' | 'ECDH';
|
|
|
65
74
|
export type CFRGKeyPairAlgorithm = 'Ed25519' | 'Ed448' | 'X25519' | 'X448';
|
|
66
75
|
export type CFRGKeyPairType = 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
67
76
|
|
|
68
|
-
export type PQCKeyPairAlgorithm =
|
|
69
|
-
|
|
77
|
+
export type PQCKeyPairAlgorithm =
|
|
78
|
+
| 'ML-DSA-44'
|
|
79
|
+
| 'ML-DSA-65'
|
|
80
|
+
| 'ML-DSA-87'
|
|
81
|
+
| 'ML-KEM-512'
|
|
82
|
+
| 'ML-KEM-768'
|
|
83
|
+
| 'ML-KEM-1024';
|
|
84
|
+
export type PQCKeyPairType =
|
|
85
|
+
| 'ml-dsa-44'
|
|
86
|
+
| 'ml-dsa-65'
|
|
87
|
+
| 'ml-dsa-87'
|
|
88
|
+
| 'ml-kem-512'
|
|
89
|
+
| 'ml-kem-768'
|
|
90
|
+
| 'ml-kem-1024';
|
|
91
|
+
|
|
92
|
+
export type MlKemAlgorithm = 'ML-KEM-512' | 'ML-KEM-768' | 'ML-KEM-1024';
|
|
93
|
+
|
|
94
|
+
export interface EncapsulateResult {
|
|
95
|
+
sharedKey: ArrayBuffer;
|
|
96
|
+
ciphertext: ArrayBuffer;
|
|
97
|
+
}
|
|
70
98
|
|
|
71
99
|
// Node.js style key pair types (lowercase)
|
|
72
100
|
export type RSAKeyPairType = 'rsa' | 'rsa-pss';
|
|
@@ -94,6 +122,8 @@ export type SignVerifyAlgorithm =
|
|
|
94
122
|
| 'RSA-PSS'
|
|
95
123
|
| 'ECDSA'
|
|
96
124
|
| 'HMAC'
|
|
125
|
+
| 'KMAC128'
|
|
126
|
+
| 'KMAC256'
|
|
97
127
|
| 'Ed25519'
|
|
98
128
|
| 'Ed448'
|
|
99
129
|
| 'ML-DSA-44'
|
|
@@ -198,7 +228,7 @@ export type SubtleAlgorithm = {
|
|
|
198
228
|
name: AnyAlgorithm;
|
|
199
229
|
salt?: string | BufferLike;
|
|
200
230
|
iterations?: number;
|
|
201
|
-
hash?: HashAlgorithm | { name: string };
|
|
231
|
+
hash?: HashAlgorithm | string | { name: string };
|
|
202
232
|
namedCurve?: NamedCurve;
|
|
203
233
|
length?: number;
|
|
204
234
|
modulusLength?: number;
|
|
@@ -215,6 +245,8 @@ export type SubtleAlgorithm = {
|
|
|
215
245
|
secretValue?: BufferLike;
|
|
216
246
|
associatedData?: BufferLike;
|
|
217
247
|
version?: number;
|
|
248
|
+
// KMAC parameters
|
|
249
|
+
customization?: BufferLike;
|
|
218
250
|
};
|
|
219
251
|
|
|
220
252
|
export type KeyPairType =
|
|
@@ -479,6 +511,7 @@ export type ImportFormat =
|
|
|
479
511
|
| 'raw'
|
|
480
512
|
| 'raw-public'
|
|
481
513
|
| 'raw-secret'
|
|
514
|
+
| 'raw-seed'
|
|
482
515
|
| 'pkcs8'
|
|
483
516
|
| 'spki'
|
|
484
517
|
| 'jwk';
|
|
@@ -493,7 +526,11 @@ export type Operation =
|
|
|
493
526
|
| 'exportKey'
|
|
494
527
|
| 'deriveBits'
|
|
495
528
|
| 'wrapKey'
|
|
496
|
-
| 'unwrapKey'
|
|
529
|
+
| 'unwrapKey'
|
|
530
|
+
| 'encapsulateBits'
|
|
531
|
+
| 'decapsulateBits'
|
|
532
|
+
| 'encapsulateKey'
|
|
533
|
+
| 'decapsulateKey';
|
|
497
534
|
|
|
498
535
|
export interface KeyPairOptions {
|
|
499
536
|
namedCurve: string;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
3
|
+
import type { X509CertificateHandle } from './specs/x509certificate.nitro';
|
|
4
|
+
import { PublicKeyObject, KeyObject } from './keys';
|
|
5
|
+
import type { BinaryLike } from './utils';
|
|
6
|
+
import { binaryLikeToArrayBuffer } from './utils';
|
|
7
|
+
|
|
8
|
+
const X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT = 0x1;
|
|
9
|
+
const X509_CHECK_FLAG_NO_WILDCARDS = 0x2;
|
|
10
|
+
const X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS = 0x4;
|
|
11
|
+
const X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS = 0x8;
|
|
12
|
+
const X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS = 0x10;
|
|
13
|
+
const X509_CHECK_FLAG_NEVER_CHECK_SUBJECT = 0x20;
|
|
14
|
+
|
|
15
|
+
export interface X509LegacyObject {
|
|
16
|
+
subject: string;
|
|
17
|
+
issuer: string;
|
|
18
|
+
subjectaltname: string;
|
|
19
|
+
infoAccess: string;
|
|
20
|
+
ca: boolean;
|
|
21
|
+
modulus: undefined;
|
|
22
|
+
bits: undefined;
|
|
23
|
+
exponent: undefined;
|
|
24
|
+
valid_from: string;
|
|
25
|
+
valid_to: string;
|
|
26
|
+
fingerprint: string;
|
|
27
|
+
fingerprint256: string;
|
|
28
|
+
fingerprint512: string;
|
|
29
|
+
ext_key_usage: string[];
|
|
30
|
+
serialNumber: string;
|
|
31
|
+
raw: Buffer;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CheckOptions {
|
|
35
|
+
subject?: 'default' | 'always' | 'never';
|
|
36
|
+
wildcards?: boolean;
|
|
37
|
+
partialWildcards?: boolean;
|
|
38
|
+
multiLabelWildcards?: boolean;
|
|
39
|
+
singleLabelSubdomains?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getFlags(options?: CheckOptions): number {
|
|
43
|
+
if (!options) return 0;
|
|
44
|
+
|
|
45
|
+
let flags = 0;
|
|
46
|
+
|
|
47
|
+
if (options.subject === 'always') {
|
|
48
|
+
flags |= X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT;
|
|
49
|
+
} else if (options.subject === 'never') {
|
|
50
|
+
flags |= X509_CHECK_FLAG_NEVER_CHECK_SUBJECT;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.wildcards === false) {
|
|
54
|
+
flags |= X509_CHECK_FLAG_NO_WILDCARDS;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (options.partialWildcards === false) {
|
|
58
|
+
flags |= X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.multiLabelWildcards === true) {
|
|
62
|
+
flags |= X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.singleLabelSubdomains === true) {
|
|
66
|
+
flags |= X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return flags;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class X509Certificate {
|
|
73
|
+
private readonly handle: X509CertificateHandle;
|
|
74
|
+
private readonly cache = new Map<string, unknown>();
|
|
75
|
+
|
|
76
|
+
constructor(buffer: BinaryLike) {
|
|
77
|
+
this.handle = NitroModules.createHybridObject<X509CertificateHandle>(
|
|
78
|
+
'X509CertificateHandle',
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
let ab: ArrayBuffer;
|
|
82
|
+
if (typeof buffer === 'string') {
|
|
83
|
+
ab = Buffer.from(buffer).buffer as ArrayBuffer;
|
|
84
|
+
} else {
|
|
85
|
+
ab = binaryLikeToArrayBuffer(buffer);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.handle.init(ab);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private cached<T>(key: string, compute: () => T): T {
|
|
92
|
+
if (this.cache.has(key)) {
|
|
93
|
+
return this.cache.get(key) as T;
|
|
94
|
+
}
|
|
95
|
+
const value = compute();
|
|
96
|
+
this.cache.set(key, value);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get subject(): string {
|
|
101
|
+
return this.cached('subject', () => this.handle.subject());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get subjectAltName(): string {
|
|
105
|
+
return this.cached('subjectAltName', () => this.handle.subjectAltName());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get issuer(): string {
|
|
109
|
+
return this.cached('issuer', () => this.handle.issuer());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get infoAccess(): string {
|
|
113
|
+
return this.cached('infoAccess', () => this.handle.infoAccess());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get validFrom(): string {
|
|
117
|
+
return this.cached('validFrom', () => this.handle.validFrom());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get validTo(): string {
|
|
121
|
+
return this.cached('validTo', () => this.handle.validTo());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get validFromDate(): Date {
|
|
125
|
+
return this.cached(
|
|
126
|
+
'validFromDate',
|
|
127
|
+
() => new Date(this.handle.validFromDate()),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get validToDate(): Date {
|
|
132
|
+
return this.cached(
|
|
133
|
+
'validToDate',
|
|
134
|
+
() => new Date(this.handle.validToDate()),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get fingerprint(): string {
|
|
139
|
+
return this.cached('fingerprint', () => this.handle.fingerprint());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get fingerprint256(): string {
|
|
143
|
+
return this.cached('fingerprint256', () => this.handle.fingerprint256());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get fingerprint512(): string {
|
|
147
|
+
return this.cached('fingerprint512', () => this.handle.fingerprint512());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get extKeyUsage(): string[] {
|
|
151
|
+
return this.cached('extKeyUsage', () => this.handle.keyUsage());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get keyUsage(): string[] {
|
|
155
|
+
return this.extKeyUsage;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get serialNumber(): string {
|
|
159
|
+
return this.cached('serialNumber', () => this.handle.serialNumber());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get signatureAlgorithm(): string {
|
|
163
|
+
return this.cached('signatureAlgorithm', () =>
|
|
164
|
+
this.handle.signatureAlgorithm(),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get signatureAlgorithmOid(): string {
|
|
169
|
+
return this.cached('signatureAlgorithmOid', () =>
|
|
170
|
+
this.handle.signatureAlgorithmOid(),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get ca(): boolean {
|
|
175
|
+
return this.cached('ca', () => this.handle.ca());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get raw(): Buffer {
|
|
179
|
+
return this.cached('raw', () => Buffer.from(this.handle.raw()));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get publicKey(): PublicKeyObject {
|
|
183
|
+
return this.cached(
|
|
184
|
+
'publicKey',
|
|
185
|
+
() => new PublicKeyObject(this.handle.publicKey()),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get issuerCertificate(): undefined {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
checkHost(name: string, options?: CheckOptions): string | undefined {
|
|
194
|
+
if (typeof name !== 'string') {
|
|
195
|
+
throw new TypeError('The "name" argument must be a string');
|
|
196
|
+
}
|
|
197
|
+
return this.handle.checkHost(name, getFlags(options));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
checkEmail(email: string, options?: CheckOptions): string | undefined {
|
|
201
|
+
if (typeof email !== 'string') {
|
|
202
|
+
throw new TypeError('The "email" argument must be a string');
|
|
203
|
+
}
|
|
204
|
+
return this.handle.checkEmail(email, getFlags(options));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
checkIP(ip: string): string | undefined {
|
|
208
|
+
if (typeof ip !== 'string') {
|
|
209
|
+
throw new TypeError('The "ip" argument must be a string');
|
|
210
|
+
}
|
|
211
|
+
return this.handle.checkIP(ip);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
checkIssued(otherCert: X509Certificate): boolean {
|
|
215
|
+
if (!(otherCert instanceof X509Certificate)) {
|
|
216
|
+
throw new TypeError(
|
|
217
|
+
'The "otherCert" argument must be an instance of X509Certificate',
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return this.handle.checkIssued(otherCert.handle);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
checkPrivateKey(pkey: KeyObject): boolean {
|
|
224
|
+
if (!(pkey instanceof KeyObject)) {
|
|
225
|
+
throw new TypeError(
|
|
226
|
+
'The "pkey" argument must be an instance of KeyObject',
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (pkey.type !== 'private') {
|
|
230
|
+
throw new TypeError('The "pkey" argument must be a private key');
|
|
231
|
+
}
|
|
232
|
+
return this.handle.checkPrivateKey(pkey.handle);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
verify(pkey: KeyObject): boolean {
|
|
236
|
+
if (!(pkey instanceof KeyObject)) {
|
|
237
|
+
throw new TypeError(
|
|
238
|
+
'The "pkey" argument must be an instance of KeyObject',
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (pkey.type !== 'public') {
|
|
242
|
+
throw new TypeError(
|
|
243
|
+
`The "pkey" argument must be a public key, got '${pkey.type}'`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return this.handle.verify(pkey.handle);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
toString(): string {
|
|
250
|
+
return this.cached('pem', () => this.handle.pem());
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
toJSON(): string {
|
|
254
|
+
return this.toString();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
toLegacyObject(): X509LegacyObject {
|
|
258
|
+
return {
|
|
259
|
+
subject: this.subject,
|
|
260
|
+
issuer: this.issuer,
|
|
261
|
+
subjectaltname: this.subjectAltName,
|
|
262
|
+
infoAccess: this.infoAccess,
|
|
263
|
+
ca: this.ca,
|
|
264
|
+
modulus: undefined,
|
|
265
|
+
bits: undefined,
|
|
266
|
+
exponent: undefined,
|
|
267
|
+
valid_from: this.validFrom,
|
|
268
|
+
valid_to: this.validTo,
|
|
269
|
+
fingerprint: this.fingerprint,
|
|
270
|
+
fingerprint256: this.fingerprint256,
|
|
271
|
+
fingerprint512: this.fingerprint512,
|
|
272
|
+
ext_key_usage: this.keyUsage,
|
|
273
|
+
serialNumber: this.serialNumber,
|
|
274
|
+
raw: this.raw,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|