Skip to content

Commit f8161c0

Browse files
authored
fix: cipher on android (#399)
1 parent 233ac94 commit f8161c0

File tree

18 files changed

+332
-31
lines changed

18 files changed

+332
-31
lines changed

.github/workflows/build-android.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v4
2727

28+
- name: Clear up some disk space
29+
run: |
30+
sudo rm -rf /usr/share/dotnet
31+
sudo rm -rf /opt/ghc
32+
sudo rm -rf "/usr/local/share/boost"
33+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
34+
2835
- name: Setup JDK
2936
uses: actions/setup-java@v4
3037
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,6 @@ lint/tmp/
150150

151151
# Release
152152
.npmrc
153+
154+
example0/
155+
tsconfig.tsbuildinfo

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ android {
104104
}
105105

106106
defaultConfig {
107-
minSdkVersion safeExtGet('minSdkVersion', 23)
107+
minSdkVersion safeExtGet('minSdkVersion', 28)
108108
targetSdkVersion safeExtGet('targetSdkVersion', 31)
109109
versionCode 1
110110
versionName "1.0"

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
QuickCrypto_compileSdkVersion=31
22
QuickCrypto_targetSdkVersion=31
33
QuickCrypto_ndkversion=21.4.7075529
4-
QuickCrypto_minSdkVersion=23
4+
QuickCrypto_minSdkVersion=28
55

66
android.useAndroidX=true

bun.lockb

485 KB
Binary file not shown.

cpp/Cipher/MGLPublicCipher.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ std::optional<jsi::Value> MGLPublicCipher::Cipher(jsi::Runtime& runtime,
6161
return {};
6262
}
6363

64-
if (EVP_PKEY_cipher_init(ctx.get()) <= 0) {
64+
int init_ret = EVP_PKEY_cipher_init(ctx.get());
65+
if (init_ret <= 0) {
66+
if (init_ret == -2) {
67+
throw std::runtime_error("operation is not supported by the public key algorithm");
68+
}
6569
return {};
6670
}
6771

cpp/Cipher/MGLPublicCipherInstaller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ FieldDefinition getPublicCipherFieldDefinition(
9696
runtime, pkey, padding, digest, arguments[offset + 3], buf);
9797

9898
if (!out.has_value()) {
99-
throw jsi::JSError(runtime, "Failed to decrypt");
99+
throw jsi::JSError(runtime, "Failed Cipher Operation - " + name);
100100
}
101101

102102
return out.value().getObject(runtime);

cpp/MGLQuickCryptoHostObject.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,29 @@ MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
6363
// publicEncrypt
6464
this->fields.push_back(
6565
getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
66-
EVP_PKEY_encrypt_init, EVP_PKEY_encrypt>(
66+
EVP_PKEY_encrypt_init,
67+
EVP_PKEY_encrypt>(
6768
"publicEncrypt", jsCallInvoker, workerQueue));
6869

6970
// privateDecrypt
7071
this->fields.push_back(
7172
getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
72-
EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>(
73+
EVP_PKEY_decrypt_init,
74+
EVP_PKEY_decrypt>(
7375
"privateDecrypt", jsCallInvoker, workerQueue));
7476

7577
// privateEncrypt
7678
this->fields.push_back(
7779
getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
78-
EVP_PKEY_sign_init, EVP_PKEY_sign>(
80+
EVP_PKEY_sign_init,
81+
EVP_PKEY_sign>(
7982
"privateEncrypt", jsCallInvoker, workerQueue));
8083

8184
// publicDecrypt
8285
this->fields.push_back(
8386
getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
84-
EVP_PKEY_verify_recover_init,
85-
EVP_PKEY_verify_recover>(
87+
EVP_PKEY_verify_recover_init,
88+
EVP_PKEY_verify_recover>(
8689
"publicDecrypt", jsCallInvoker, workerQueue));
8790

8891
// generateKeyPair

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
buildscript {
44
ext {
55
buildToolsVersion = "34.0.0"
6-
minSdkVersion = 23
6+
minSdkVersion = 28
77
compileSdkVersion = 34
88
targetSdkVersion = 34
99
ndkVersion = "25.1.8937393"
@@ -13,7 +13,7 @@ buildscript {
1313
mavenCentral()
1414
}
1515
dependencies {
16-
classpath("com.android.tools.build:gradle:8.3.1")
16+
classpath('com.android.tools.build:gradle:8.3.1')
1717
classpath("com.facebook.react:react-native-gradle-plugin")
1818
}
1919
}

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Fri Aug 09 17:48:30 EDT 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

0 commit comments

Comments
 (0)