From 49da5f36dcfe5d93bee9213d54539e3e078044b9 Mon Sep 17 00:00:00 2001 From: Oscar Franco Date: Tue, 17 Feb 2026 11:33:59 +0100 Subject: [PATCH] Load rustls-platform-verifier --- OpacityCore/build.gradle | 1 + OpacityCore/consumer-rules.pro | 3 ++- OpacityCore/proguard-rules.pro | 5 ++++- OpacityCore/src/main/cpp/OpacityCore.cpp | 14 ++++++++---- OpacityCore/src/main/jni/include/sdk.h | 2 ++ .../opacitylabs/opacitycore/OpacityCore.kt | 3 ++- gradle/libs.versions.toml | 1 + settings.gradle.kts | 22 +++++++++++++++++++ 8 files changed, 44 insertions(+), 7 deletions(-) diff --git a/OpacityCore/build.gradle b/OpacityCore/build.gradle index f6f7b05..52237be 100644 --- a/OpacityCore/build.gradle +++ b/OpacityCore/build.gradle @@ -64,6 +64,7 @@ dependencies { implementation libs.geckoview implementation libs.androidx.security.crypto implementation libs.kotlinx.serialization.json + implementation libs.rustls.platform.verifier testImplementation libs.junit androidTestImplementation libs.androidx.junit androidTestImplementation libs.androidx.espresso.core diff --git a/OpacityCore/consumer-rules.pro b/OpacityCore/consumer-rules.pro index 52f3c80..0c82663 100644 --- a/OpacityCore/consumer-rules.pro +++ b/OpacityCore/consumer-rules.pro @@ -1,2 +1,3 @@ -keep class com.opacitylabs.opacitycore.** { *; } --keepclassmembers class com.opacitylabs.opacitycore.** { *; } \ No newline at end of file +-keepclassmembers class com.opacitylabs.opacitycore.** { *; } +-keep, includedescriptorclasses class org.rustls.platformverifier.** { *; } \ No newline at end of file diff --git a/OpacityCore/proguard-rules.pro b/OpacityCore/proguard-rules.pro index 25b25c7..36fd2df 100644 --- a/OpacityCore/proguard-rules.pro +++ b/OpacityCore/proguard-rules.pro @@ -90,4 +90,7 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +# Keeps rustls-platform-verifier deps from being stripped +-keep, includedescriptorclasses class org.rustls.platformverifier.** { *; } diff --git a/OpacityCore/src/main/cpp/OpacityCore.cpp b/OpacityCore/src/main/cpp/OpacityCore.cpp index 2879c86..0bd4860 100644 --- a/OpacityCore/src/main/cpp/OpacityCore.cpp +++ b/OpacityCore/src/main/cpp/OpacityCore.cpp @@ -383,14 +383,20 @@ android_get_browser_cookies_for_domain(const char *domain) { extern "C" JNIEXPORT jint JNICALL Java_com_opacitylabs_opacitycore_OpacityCore_init( - JNIEnv *env, jobject thiz, jstring api_key, jboolean dry_run, - jint environment_enum, jboolean show_errors_in_webview) { + JNIEnv *env, jobject thiz, jobject context, jstring api_key, + jboolean dry_run, jint environment_enum, + jboolean show_errors_in_webview) { java_object = env->NewGlobalRef(thiz); char *err; const char *api_key_str = env->GetStringUTFChars(api_key, nullptr); + int android_init_result = + opacity_core::android_init((void *)env, (void *)context); + __android_log_print(ANDROID_LOG_DEBUG, "OpacityCore", + "android_init_result: %d", android_init_result); + int result = opacity_core::opacity_init(api_key_str, dry_run, - static_cast(environment_enum), - show_errors_in_webview, &err); + static_cast(environment_enum), + show_errors_in_webview, &err); if (result != opacity_core::OPACITY_OK) { jclass exceptionClass = env->FindClass("java/lang/Exception"); env->ThrowNew(exceptionClass, err); diff --git a/OpacityCore/src/main/jni/include/sdk.h b/OpacityCore/src/main/jni/include/sdk.h index 716e189..628c52f 100644 --- a/OpacityCore/src/main/jni/include/sdk.h +++ b/OpacityCore/src/main/jni/include/sdk.h @@ -166,6 +166,8 @@ extern const int32_t OPACITY_ENVIRONMENT_STAGING; extern const int32_t OPACITY_ENVIRONMENT_PRODUCTION; +int32_t android_init(void *raw_env, void *raw_context); + int32_t opacity_init(const char *api_key_str, bool dry_run, int32_t backend_environment, diff --git a/OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/OpacityCore.kt b/OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/OpacityCore.kt index 77f8096..d879eaf 100644 --- a/OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/OpacityCore.kt +++ b/OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/OpacityCore.kt @@ -46,7 +46,7 @@ object OpacityCore { environment: Environment, showErrorsInWebView: Boolean ): Int { - return init(apiKey, dryRun, environment.code, showErrorsInWebView) + return init(appContext, apiKey, dryRun, environment.code, showErrorsInWebView) } @JvmStatic @@ -287,6 +287,7 @@ object OpacityCore { } private external fun init( + context: Context, apiKey: String, dryRun: Boolean, environment: Int, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2e1d369..3114131 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -41,6 +41,7 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx- androidx-espresso-intents = { group = "androidx.test.espresso", name = "espresso-intents", version.ref = "espressoIntents" } compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "compose-compiler" } work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" } +rustls-platform-verifier = { group = "rustls", name = "rustls-platform-verifier", version = "latest.release" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5384f96..fb4da09 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,9 +20,31 @@ dependencyResolutionManagement { mavenCentral() maven("https://maven.mozilla.org/maven2/") maven("https://jitpack.io") + maven { + url = uri(findRustlsPlatformVerifierMaven()) + metadataSources.artifact() + } } } +@Suppress("UNCHECKED_CAST") +fun findRustlsPlatformVerifierMaven(): String { + val result = providers.exec { + workingDir = File(rootDir, "../") + commandLine( + "cargo", "metadata", "--format-version", "1", + "--filter-platform", "aarch64-linux-android", + "--manifest-path", "sdk/Cargo.toml" + ) + }.standardOutput.asText.get() + + val json = groovy.json.JsonSlurper().parseText(result) as Map + val packages = json["packages"] as List> + val pkg = packages.first { it["name"] == "rustls-platform-verifier-android" } + val manifestPath = File(pkg["manifest_path"] as String) + return File(manifestPath.parentFile, "maven").path +} + rootProject.name = "OpacityAndroid" include(":app")