-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Suggestion] Fetch supported hashes and ciphers from OpenSSL #357
Comments
Probably needs to happen ASAP. Getting them from |
I managed to get the ciphers from the underlying OpenSSL library. (on Patch for the test codediff -u original/MGLCipherHostObject.cpp patched/MGLCipherHostObject.cpp
--- original/MGLCipherHostObject.cpp 2024-06-28 01:18:00.852205300 +0800
+++ patched/MGLCipherHostObject.cpp 2024-06-28 01:18:00.868096200 +0800
@@ -78,6 +78,27 @@
installMethods();
}
+void MGLCipherHostObject::cipherCallback(const EVP_CIPHER *cipher, const char *name, const char *unused, void *arg) {
+ std::vector<std::string> *ciphers = static_cast<std::vector<std::string>*>(arg);
+ if (name != nullptr) {
+ ciphers->push_back(name);
+ }
+}
+
+void MGLCipherHostObject::printSupportedCiphers(jsi::Runtime &runtime) {
+ char messagee[4096] = { '\0' };
+ std::vector<std::string> ciphers;
+ EVP_CIPHER_do_all_sorted(cipherCallback, static_cast<void*>(&ciphers));
+ int offset = 0;
+ for (const auto& cipher : ciphers) {
+ sprintf(messagee + offset, "%s, ", cipher.c_str());
+ offset += cipher.length() + 2;
+ if (offset > 4000)
+ break;
+ }
+ throw jsi::JSError(runtime, messagee);
+}
+
MGLCipherHostObject::MGLCipherHostObject(
const std::string &cipher_type, jsi::ArrayBuffer *cipher_key, bool isCipher,
unsigned int auth_tag_len, jsi::Runtime &runtime,
@@ -98,6 +119,8 @@
// FIPS mode.");
// }
+ printSupportedCiphers(runtime);
+
const EVP_CIPHER *const cipher = EVP_get_cipherbyname(cipher_type.c_str());
if (cipher == nullptr) {
throw jsi::JSError(runtime, "Invalid Cipher Algorithm!");
@@ -151,6 +174,8 @@
// FIPS mode.");
// }
+ printSupportedCiphers(runtime);
+
const EVP_CIPHER *const cipher = EVP_get_cipherbyname(cipher_type.c_str());
if (cipher == nullptr) {
throw jsi::JSError(runtime, "Invalid Cipher Algorithm!");
diff -u original/MGLCipherHostObject.h patched/MGLCipherHostObject.h
--- original/MGLCipherHostObject.h 2024-06-28 01:18:00.852205300 +0800
+++ patched/MGLCipherHostObject.h 2024-06-28 01:18:00.868096200 +0800
@@ -83,6 +83,9 @@
AuthTagState auth_tag_state_;
unsigned int auth_tag_len_;
int max_message_size_;
+
+ static void cipherCallback(const EVP_CIPHER *cipher, const char *name, const char *unused, void *arg);
+ void printSupportedCiphers(jsi::Runtime &runtime);
};
} // namespace margelo And here are the results iOS emulator iOS 17.2
iOS device iOS 16.5.1
Android emulator API 23
Android emulator API 26
Android device API 27
Android device API 31
Notes:
Maybe we can add some common supported ciphers to the hard-coded list first. However, considering the different OpenSSL versions between iOS and Android and the different supported ciphers between Android devices and Android emulators, I think it's better to fetch the result by native code. |
It looks like the supported hashes and ciphers are hard-coded in the source code.
https://github.com/margelo/react-native-quick-crypto/blob/v0.7.0-rc.10/src/Utils.ts#L668
https://github.com/margelo/react-native-quick-crypto/blob/v0.7.0-rc.10/src/Utils.ts#L710
Would it be possible to fetch the result from OpenSSL?
The text was updated successfully, but these errors were encountered: