react-native-quick-crypto 0.7.3 → 1.0.0-beta.2
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/QuickCrypto.podspec +34 -0
- package/README.md +13 -46
- package/android/CMakeLists.txt +32 -64
- package/android/build.gradle +52 -125
- package/android/gradle.properties +4 -4
- package/android/src/main/cpp/cpp-adapter.cpp +9 -54
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
- package/cpp/random/HybridRandom.cpp +34 -0
- package/cpp/random/HybridRandom.hpp +44 -0
- package/cpp/utils/Utils.hpp +9 -0
- package/ios/QuickCryptoOnLoad.mm +19 -0
- package/lib/commonjs/index.js +39 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/random.js +26 -12
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +22 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +2 -0
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
- package/lib/module/index.js +38 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/random.js +26 -12
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/module/utils/conversion.js +16 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +10 -141
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +4 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +5 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
- package/package.json +50 -106
- package/src/index.ts +38 -48
- package/src/random.ts +51 -48
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +16 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +15 -0
- package/LICENSE +0 -27
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
- package/cpp/JSIUtils/MGLTypedArray.h +0 -160
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
- package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -42
- package/lib/commonjs/Cipher.js +0 -502
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -99
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js +0 -87
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -79
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -608
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -281
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -276
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -56
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -492
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/pbkdf2.js +0 -90
- package/lib/commonjs/pbkdf2.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -129
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -448
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Cipher.js +0 -491
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -93
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js +0 -85
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -74
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -539
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -274
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -267
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -49
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -477
- package/lib/module/keys.js.map +0 -1
- package/lib/module/pbkdf2.js +0 -84
- package/lib/module/pbkdf2.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -124
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -443
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -81
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts +0 -44
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts +0 -11
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts +0 -37
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts +0 -48
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts +0 -22
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -76
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts +0 -7
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts +0 -6
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts +0 -206
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts +0 -12
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts +0 -12
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts +0 -21
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts +0 -15
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts +0 -9
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Cipher.ts +0 -832
- package/src/Hash.ts +0 -132
- package/src/Hashnames.ts +0 -93
- package/src/Hmac.ts +0 -106
- package/src/NativeQuickCrypto/Cipher.ts +0 -102
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -44
- package/src/NativeQuickCrypto/webcrypto.ts +0 -72
- package/src/Utils.ts +0 -777
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -375
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -787
- package/src/pbkdf2.ts +0 -169
- package/src/rsa.ts +0 -370
- package/src/sig.ts +0 -164
- package/src/subtle.ts +0 -639
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
package/cpp/MGLKeys.h
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// MGLCipherKeys.h
|
|
3
|
-
// react-native-quick-crypto
|
|
4
|
-
//
|
|
5
|
-
// Created by Oscar on 20.06.22.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#ifndef MGLCipherKeys_h
|
|
9
|
-
#define MGLCipherKeys_h
|
|
10
|
-
|
|
11
|
-
#include <jsi/jsi.h>
|
|
12
|
-
#include <openssl/evp.h>
|
|
13
|
-
|
|
14
|
-
#include <memory>
|
|
15
|
-
#include <optional>
|
|
16
|
-
#include <string>
|
|
17
|
-
|
|
18
|
-
#ifdef ANDROID
|
|
19
|
-
#include "Utils/MGLUtils.h"
|
|
20
|
-
#include "JSIUtils/MGLSmartHostObject.h"
|
|
21
|
-
#else
|
|
22
|
-
#include "MGLUtils.h"
|
|
23
|
-
#include "MGLSmartHostObject.h"
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
// This file should roughly match https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.cc
|
|
27
|
-
|
|
28
|
-
namespace margelo {
|
|
29
|
-
|
|
30
|
-
namespace jsi = facebook::jsi;
|
|
31
|
-
|
|
32
|
-
enum PKEncodingType {
|
|
33
|
-
// RSAPublicKey / RSAPrivateKey according to PKCS#1.
|
|
34
|
-
kKeyEncodingPKCS1,
|
|
35
|
-
// PrivateKeyInfo or EncryptedPrivateKeyInfo according to PKCS#8.
|
|
36
|
-
kKeyEncodingPKCS8,
|
|
37
|
-
// SubjectPublicKeyInfo according to X.509.
|
|
38
|
-
kKeyEncodingSPKI,
|
|
39
|
-
// ECPrivateKey according to SEC1.
|
|
40
|
-
kKeyEncodingSEC1
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
enum PKFormatType { kKeyFormatDER, kKeyFormatPEM, kKeyFormatJWK };
|
|
44
|
-
|
|
45
|
-
enum KeyType { kKeyTypeSecret, kKeyTypePublic, kKeyTypePrivate };
|
|
46
|
-
|
|
47
|
-
enum KeyEncodingContext {
|
|
48
|
-
kKeyContextInput,
|
|
49
|
-
kKeyContextExport,
|
|
50
|
-
kKeyContextGenerate
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
enum class ParseKeyResult {
|
|
54
|
-
kParseKeyOk,
|
|
55
|
-
kParseKeyNotRecognized,
|
|
56
|
-
kParseKeyNeedPassphrase,
|
|
57
|
-
kParseKeyFailed
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
enum class WebCryptoKeyExportStatus {
|
|
61
|
-
OK,
|
|
62
|
-
INVALID_KEY_TYPE,
|
|
63
|
-
FAILED
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
struct AsymmetricKeyEncodingConfig {
|
|
67
|
-
bool output_key_object_ = false;
|
|
68
|
-
PKFormatType format_ = kKeyFormatDER;
|
|
69
|
-
std::optional<PKEncodingType> type_ = std::nullopt;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
using PublicKeyEncodingConfig = AsymmetricKeyEncodingConfig;
|
|
73
|
-
|
|
74
|
-
struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
|
|
75
|
-
const EVP_CIPHER *cipher_;
|
|
76
|
-
// The ByteSource alone is not enough to distinguish between "no passphrase"
|
|
77
|
-
// and a zero-length passphrase (which can be a null pointer), therefore, we
|
|
78
|
-
// use a NonCopyableMaybe.
|
|
79
|
-
NonCopyableMaybe<ByteSource> passphrase_;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Here node uses extends MemoryRetainer no clue what that is, something with
|
|
83
|
-
// Snapshots stripped it for our implementation but if something doesn't work,
|
|
84
|
-
// you know why
|
|
85
|
-
class ManagedEVPPKey {
|
|
86
|
-
public:
|
|
87
|
-
ManagedEVPPKey() {}
|
|
88
|
-
explicit ManagedEVPPKey(EVPKeyPointer &&pkey);
|
|
89
|
-
ManagedEVPPKey(const ManagedEVPPKey &that);
|
|
90
|
-
ManagedEVPPKey &operator=(const ManagedEVPPKey &that);
|
|
91
|
-
|
|
92
|
-
operator bool() const;
|
|
93
|
-
EVP_PKEY *get() const;
|
|
94
|
-
|
|
95
|
-
static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
|
|
96
|
-
jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
|
|
97
|
-
KeyEncodingContext context);
|
|
98
|
-
|
|
99
|
-
static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
|
|
100
|
-
jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
|
|
101
|
-
KeyEncodingContext context);
|
|
102
|
-
//
|
|
103
|
-
static ManagedEVPPKey GetParsedKey(jsi::Runtime &runtime,
|
|
104
|
-
EVPKeyPointer &&pkey,
|
|
105
|
-
ParseKeyResult ret,
|
|
106
|
-
const char *default_msg);
|
|
107
|
-
|
|
108
|
-
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(jsi::Runtime &runtime,
|
|
109
|
-
const jsi::Value *args,
|
|
110
|
-
unsigned int *offset);
|
|
111
|
-
|
|
112
|
-
static ManagedEVPPKey GetPrivateKeyFromJs(jsi::Runtime &runtime,
|
|
113
|
-
const jsi::Value *args,
|
|
114
|
-
unsigned int *offset,
|
|
115
|
-
bool allow_key_object);
|
|
116
|
-
|
|
117
|
-
static jsi::Value ToEncodedPublicKey(jsi::Runtime &runtime,
|
|
118
|
-
ManagedEVPPKey key,
|
|
119
|
-
const PublicKeyEncodingConfig &config);
|
|
120
|
-
|
|
121
|
-
static jsi::Value ToEncodedPrivateKey(jsi::Runtime &runtime,
|
|
122
|
-
ManagedEVPPKey key,
|
|
123
|
-
const PrivateKeyEncodingConfig &config);
|
|
124
|
-
|
|
125
|
-
private:
|
|
126
|
-
size_t size_of_private_key() const;
|
|
127
|
-
size_t size_of_public_key() const;
|
|
128
|
-
|
|
129
|
-
EVPKeyPointer pkey_;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// Analogous to the KeyObjectData class on node
|
|
133
|
-
// https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L132
|
|
134
|
-
class KeyObjectData {
|
|
135
|
-
public:
|
|
136
|
-
static std::shared_ptr<KeyObjectData> CreateSecret(ByteSource key);
|
|
137
|
-
|
|
138
|
-
static std::shared_ptr<KeyObjectData> CreateAsymmetric(
|
|
139
|
-
KeyType type,
|
|
140
|
-
const ManagedEVPPKey& pkey);
|
|
141
|
-
|
|
142
|
-
KeyType GetKeyType() const;
|
|
143
|
-
|
|
144
|
-
// These functions allow unprotected access to the raw key material and should
|
|
145
|
-
// only be used to implement cryptographic operations requiring the key.
|
|
146
|
-
ManagedEVPPKey GetAsymmetricKey() const;
|
|
147
|
-
std::string GetSymmetricKey() const;
|
|
148
|
-
size_t GetSymmetricKeySize() const;
|
|
149
|
-
|
|
150
|
-
private:
|
|
151
|
-
explicit KeyObjectData(ByteSource symmetric_key);
|
|
152
|
-
|
|
153
|
-
KeyObjectData(
|
|
154
|
-
KeyType type,
|
|
155
|
-
const ManagedEVPPKey& pkey);
|
|
156
|
-
|
|
157
|
-
const KeyType key_type_;
|
|
158
|
-
const ByteSource symmetric_key_;
|
|
159
|
-
const size_t symmetric_key_len_;
|
|
160
|
-
const ManagedEVPPKey asymmetric_key_;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// Analogous to the KeyObjectHandle class in node
|
|
164
|
-
// https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L164
|
|
165
|
-
class JSI_EXPORT KeyObjectHandle: public jsi::HostObject {
|
|
166
|
-
public:
|
|
167
|
-
KeyObjectHandle() {}
|
|
168
|
-
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
|
|
169
|
-
const std::shared_ptr<KeyObjectData>& Data();
|
|
170
|
-
|
|
171
|
-
static std::shared_ptr<KeyObjectHandle> Create(std::shared_ptr<KeyObjectData> data);
|
|
172
|
-
|
|
173
|
-
protected:
|
|
174
|
-
jsi::Value Export(jsi::Runtime &rt);
|
|
175
|
-
jsi::Value ExportJWK(jsi::Runtime &rt);
|
|
176
|
-
jsi::Value ExportPublicKey(
|
|
177
|
-
jsi::Runtime& rt,
|
|
178
|
-
const PublicKeyEncodingConfig& config) const;
|
|
179
|
-
jsi::Value ExportPrivateKey(
|
|
180
|
-
jsi::Runtime& rt,
|
|
181
|
-
const PrivateKeyEncodingConfig& config) const;
|
|
182
|
-
jsi::Value ExportSecretKey(jsi::Runtime& rt) const;
|
|
183
|
-
jsi::Value GetKeyDetail(jsi::Runtime &rt);
|
|
184
|
-
jsi::Value GetAsymmetricKeyType(jsi::Runtime &rt) const;
|
|
185
|
-
jsi::Value Init(jsi::Runtime &rt);
|
|
186
|
-
jsi::Value InitECRaw(jsi::Runtime &rt);
|
|
187
|
-
jsi::Value InitJWK(jsi::Runtime &rt);
|
|
188
|
-
|
|
189
|
-
private:
|
|
190
|
-
std::shared_ptr<KeyObjectData> data_;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
WebCryptoKeyExportStatus PKEY_SPKI_Export(
|
|
194
|
-
KeyObjectData* key_data,
|
|
195
|
-
ByteSource* out);
|
|
196
|
-
|
|
197
|
-
WebCryptoKeyExportStatus PKEY_PKCS8_Export(
|
|
198
|
-
KeyObjectData* key_data,
|
|
199
|
-
ByteSource* out);
|
|
200
|
-
|
|
201
|
-
} // namespace margelo
|
|
202
|
-
|
|
203
|
-
#endif /* MGLCipherKeys_h */
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 Margelo
|
|
2
|
-
#include "MGLQuickCryptoHostObject.h"
|
|
3
|
-
|
|
4
|
-
#include <ReactCommon/TurboModuleUtils.h>
|
|
5
|
-
#include <jsi/jsi.h>
|
|
6
|
-
|
|
7
|
-
#include <memory>
|
|
8
|
-
#include <string>
|
|
9
|
-
#include <vector>
|
|
10
|
-
|
|
11
|
-
#ifdef ANDROID
|
|
12
|
-
#include "Cipher/MGLCreateCipherInstaller.h"
|
|
13
|
-
#include "Cipher/MGLCreateDecipherInstaller.h"
|
|
14
|
-
#include "Cipher/MGLGenerateKeyPairInstaller.h"
|
|
15
|
-
#include "Cipher/MGLGenerateKeyPairSyncInstaller.h"
|
|
16
|
-
#include "Cipher/MGLPublicCipher.h"
|
|
17
|
-
#include "Cipher/MGLPublicCipherInstaller.h"
|
|
18
|
-
#include "HMAC/MGLHmacInstaller.h"
|
|
19
|
-
#include "Hash/MGLHashInstaller.h"
|
|
20
|
-
#include "Random/MGLRandomHostObject.h"
|
|
21
|
-
#include "Sig/MGLSignInstaller.h"
|
|
22
|
-
#include "Sig/MGLVerifyInstaller.h"
|
|
23
|
-
#include "fastpbkdf2/MGLPbkdf2HostObject.h"
|
|
24
|
-
#include "webcrypto/MGLWebCrypto.h"
|
|
25
|
-
#else
|
|
26
|
-
#include "MGLCreateCipherInstaller.h"
|
|
27
|
-
#include "MGLCreateDecipherInstaller.h"
|
|
28
|
-
#include "MGLGenerateKeyPairInstaller.h"
|
|
29
|
-
#include "MGLGenerateKeyPairSyncInstaller.h"
|
|
30
|
-
#include "MGLHashInstaller.h"
|
|
31
|
-
#include "MGLHmacInstaller.h"
|
|
32
|
-
#include "MGLPbkdf2HostObject.h"
|
|
33
|
-
#include "MGLPublicCipher.h"
|
|
34
|
-
#include "MGLPublicCipherInstaller.h"
|
|
35
|
-
#include "MGLRandomHostObject.h"
|
|
36
|
-
#include "MGLSignInstaller.h"
|
|
37
|
-
#include "MGLVerifyInstaller.h"
|
|
38
|
-
#include "MGLWebCrypto.h"
|
|
39
|
-
#endif
|
|
40
|
-
|
|
41
|
-
namespace margelo {
|
|
42
|
-
|
|
43
|
-
namespace jsi = facebook::jsi;
|
|
44
|
-
|
|
45
|
-
MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
|
|
46
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
47
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
|
|
48
|
-
: MGLSmartHostObject(jsCallInvoker, workerQueue) {
|
|
49
|
-
// HmacInstaller
|
|
50
|
-
this->fields.push_back(getHmacFieldDefinition(jsCallInvoker, workerQueue));
|
|
51
|
-
|
|
52
|
-
// HashInstaller
|
|
53
|
-
this->fields.push_back(getHashFieldDefinition(jsCallInvoker, workerQueue));
|
|
54
|
-
|
|
55
|
-
// createCipher
|
|
56
|
-
this->fields.push_back(
|
|
57
|
-
getCreateCipherFieldDefinition(jsCallInvoker, workerQueue));
|
|
58
|
-
|
|
59
|
-
// createDecipher
|
|
60
|
-
this->fields.push_back(
|
|
61
|
-
getCreateDecipherFieldDefinition(jsCallInvoker, workerQueue));
|
|
62
|
-
|
|
63
|
-
// publicEncrypt
|
|
64
|
-
this->fields.push_back(
|
|
65
|
-
getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
|
|
66
|
-
EVP_PKEY_encrypt_init,
|
|
67
|
-
EVP_PKEY_encrypt>(
|
|
68
|
-
"publicEncrypt", jsCallInvoker, workerQueue));
|
|
69
|
-
|
|
70
|
-
// privateDecrypt
|
|
71
|
-
this->fields.push_back(
|
|
72
|
-
getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
|
|
73
|
-
EVP_PKEY_decrypt_init,
|
|
74
|
-
EVP_PKEY_decrypt>(
|
|
75
|
-
"privateDecrypt", jsCallInvoker, workerQueue));
|
|
76
|
-
|
|
77
|
-
// privateEncrypt
|
|
78
|
-
this->fields.push_back(
|
|
79
|
-
getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
|
|
80
|
-
EVP_PKEY_sign_init,
|
|
81
|
-
EVP_PKEY_sign>(
|
|
82
|
-
"privateEncrypt", jsCallInvoker, workerQueue));
|
|
83
|
-
|
|
84
|
-
// publicDecrypt
|
|
85
|
-
this->fields.push_back(
|
|
86
|
-
getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
|
|
87
|
-
EVP_PKEY_verify_recover_init,
|
|
88
|
-
EVP_PKEY_verify_recover>(
|
|
89
|
-
"publicDecrypt", jsCallInvoker, workerQueue));
|
|
90
|
-
|
|
91
|
-
// generateKeyPair
|
|
92
|
-
this->fields.push_back(
|
|
93
|
-
getGenerateKeyPairFieldDefinition(jsCallInvoker, workerQueue));
|
|
94
|
-
|
|
95
|
-
// generateKeyPairSync
|
|
96
|
-
this->fields.push_back(
|
|
97
|
-
getGenerateKeyPairSyncFieldDefinition(jsCallInvoker, workerQueue));
|
|
98
|
-
|
|
99
|
-
// Pbkdf2HostObject
|
|
100
|
-
this->fields.push_back(JSI_VALUE("pbkdf2", {
|
|
101
|
-
auto hostObject =
|
|
102
|
-
std::make_shared<MGLPbkdf2HostObject>(jsCallInvoker, workerQueue);
|
|
103
|
-
return jsi::Object::createFromHostObject(runtime, hostObject);
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
// RandomHostObject
|
|
107
|
-
this->fields.push_back(JSI_VALUE("random", {
|
|
108
|
-
auto hostObject =
|
|
109
|
-
std::make_shared<MGLRandomHostObject>(jsCallInvoker, workerQueue);
|
|
110
|
-
return jsi::Object::createFromHostObject(runtime, hostObject);
|
|
111
|
-
}));
|
|
112
|
-
|
|
113
|
-
// createSign
|
|
114
|
-
this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));
|
|
115
|
-
|
|
116
|
-
// createVerify
|
|
117
|
-
this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));
|
|
118
|
-
|
|
119
|
-
// subtle API
|
|
120
|
-
this->fields.push_back(JSI_VALUE("webcrypto", {
|
|
121
|
-
auto hostObject = std::make_shared<MGLWebCryptoHostObject>(
|
|
122
|
-
jsCallInvoker, workerQueue);
|
|
123
|
-
return jsi::Object::createFromHostObject(runtime, hostObject);
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
} // namespace margelo
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 Margelo
|
|
2
|
-
#ifndef CPP_FASTCRYPTOHOSTOBJECT_H_
|
|
3
|
-
#define CPP_FASTCRYPTOHOSTOBJECT_H_
|
|
4
|
-
|
|
5
|
-
#include <ReactCommon/CallInvoker.h>
|
|
6
|
-
#include <jsi/jsi.h>
|
|
7
|
-
|
|
8
|
-
#include <memory>
|
|
9
|
-
|
|
10
|
-
#include "JSIUtils/MGLSmartHostObject.h"
|
|
11
|
-
#include "JSIUtils/MGLTypedArray.h"
|
|
12
|
-
#include "Utils/MGLDispatchQueue.h"
|
|
13
|
-
|
|
14
|
-
namespace margelo {
|
|
15
|
-
|
|
16
|
-
namespace jsi = facebook::jsi;
|
|
17
|
-
namespace react = facebook::react;
|
|
18
|
-
|
|
19
|
-
class JSI_EXPORT MGLQuickCryptoHostObject : public MGLSmartHostObject {
|
|
20
|
-
public:
|
|
21
|
-
explicit MGLQuickCryptoHostObject(
|
|
22
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
23
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
|
|
24
|
-
|
|
25
|
-
virtual ~MGLQuickCryptoHostObject() { invalidateJsiPropNameIDCache(); }
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
} // namespace margelo
|
|
29
|
-
|
|
30
|
-
#endif // CPP_FASTCRYPTOHOSTOBJECT_H_
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 25/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#include "MGLRandomHostObject.h"
|
|
6
|
-
|
|
7
|
-
#ifdef ANDROID
|
|
8
|
-
#include "JSIUtils/MGLTypedArray.h"
|
|
9
|
-
#else
|
|
10
|
-
#include "MGLTypedArray.h"
|
|
11
|
-
#endif
|
|
12
|
-
#include <openssl/bn.h>
|
|
13
|
-
#include <openssl/dsa.h>
|
|
14
|
-
#include <openssl/ec.h>
|
|
15
|
-
#include <openssl/err.h>
|
|
16
|
-
#include <openssl/evp.h>
|
|
17
|
-
#include <openssl/kdf.h>
|
|
18
|
-
#include <openssl/rand.h>
|
|
19
|
-
#include <openssl/rsa.h>
|
|
20
|
-
#include <openssl/ssl.h>
|
|
21
|
-
|
|
22
|
-
#include <memory>
|
|
23
|
-
#include <utility>
|
|
24
|
-
|
|
25
|
-
namespace margelo {
|
|
26
|
-
namespace jsi = facebook::jsi;
|
|
27
|
-
namespace react = facebook::react;
|
|
28
|
-
|
|
29
|
-
MGLRandomHostObject::MGLRandomHostObject(
|
|
30
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
31
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
|
|
32
|
-
: MGLSmartHostObject(jsCallInvoker, workerQueue) {
|
|
33
|
-
this->fields.push_back(buildPair(
|
|
34
|
-
"randomFill", JSIF([=]) {
|
|
35
|
-
if (count != 3) {
|
|
36
|
-
throw jsi::JSError(runtime,
|
|
37
|
-
"randomFill(..) expects exactly 4 arguments!");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if(!arguments[0].isObject() || !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
|
|
41
|
-
throw std::runtime_error("First argument it not an array buffer");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!arguments[0].isObject()
|
|
45
|
-
|| !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
|
|
46
|
-
throw std::runtime_error("First argument it not an array buffer");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
|
|
50
|
-
auto *resultData = result.data(runtime);
|
|
51
|
-
auto resultPreventGC =
|
|
52
|
-
std::make_shared<jsi::ArrayBuffer>(std::move(result));
|
|
53
|
-
|
|
54
|
-
auto offset = (int)arguments[1].asNumber();
|
|
55
|
-
auto size = arguments[2].asNumber();
|
|
56
|
-
|
|
57
|
-
return react::createPromiseAsJSIValue(
|
|
58
|
-
runtime, [=](jsi::Runtime &runtime,
|
|
59
|
-
std::shared_ptr<react::Promise> promise) {
|
|
60
|
-
// TODO(Szymon) implement check prime once we have bignums
|
|
61
|
-
this->runOnWorkerThread([=]() {
|
|
62
|
-
if (RAND_bytes(resultData + offset, size) != 1) {
|
|
63
|
-
this->runOnJSThread([=]() {
|
|
64
|
-
promise->reject("Sth went wrong with RAND_bytes");
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
this->runOnJSThread([=]() {
|
|
68
|
-
promise->resolve(
|
|
69
|
-
jsi::ArrayBuffer(std::move(*resultPreventGC)));
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
this->fields.push_back(buildPair(
|
|
76
|
-
"randomFillSync", JSIF([=]) {
|
|
77
|
-
if (count != 3) {
|
|
78
|
-
throw jsi::JSError(runtime,
|
|
79
|
-
"randomFillSync(..) expects exactly 4 arguments!");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
|
|
83
|
-
auto *resultData = result.data(runtime);
|
|
84
|
-
auto offset = (int)arguments[1].asNumber();
|
|
85
|
-
auto size = arguments[2].asNumber();
|
|
86
|
-
|
|
87
|
-
if (RAND_bytes(resultData + offset, size) != 1) {
|
|
88
|
-
throw jsi::JSError(runtime, "Sth went wrong with RAND_bytes" +
|
|
89
|
-
std::to_string(ERR_get_error()));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return result;
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
} // namespace margelo
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 25/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#ifndef MGL_RANDOMHOSTOBJECT_H
|
|
6
|
-
#define MGL_RANDOMHOSTOBJECT_H
|
|
7
|
-
|
|
8
|
-
#include <memory>
|
|
9
|
-
|
|
10
|
-
#ifdef ANDROID
|
|
11
|
-
#include "JSIUtils/MGLSmartHostObject.h"
|
|
12
|
-
#else
|
|
13
|
-
#include "MGLSmartHostObject.h"
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
namespace margelo {
|
|
17
|
-
namespace jsi = facebook::jsi;
|
|
18
|
-
|
|
19
|
-
class MGLRandomHostObject : public MGLSmartHostObject {
|
|
20
|
-
public:
|
|
21
|
-
MGLRandomHostObject(
|
|
22
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
23
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
} // namespace margelo
|
|
27
|
-
#endif // MGL_RANDOMHOSTOBJECT_H
|