From 4cff6ec596c974ff0e5bf76b575a8dc99b3284f7 Mon Sep 17 00:00:00 2001 From: Hinton Date: Thu, 12 Sep 2024 17:43:55 +0200 Subject: [PATCH] Bundle platform-verifier --- crates/bitwarden-uniffi/src/lib.rs | 14 ++++++++++- languages/kotlin/sdk/build.gradle | 39 ++++++++++++++++++++++-------- languages/kotlin/settings.gradle | 18 +------------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/crates/bitwarden-uniffi/src/lib.rs b/crates/bitwarden-uniffi/src/lib.rs index d0209de01..0d89ffdb8 100644 --- a/crates/bitwarden-uniffi/src/lib.rs +++ b/crates/bitwarden-uniffi/src/lib.rs @@ -28,7 +28,7 @@ use vault::ClientVault; #[derive(uniffi::Object)] pub struct Client(bitwarden::Client); -#[uniffi::export] +#[uniffi::export(async_runtime = "tokio")] impl Client { /// Initialize a new instance of the SDK client #[uniffi::constructor] @@ -79,6 +79,18 @@ impl Client { pub fn echo(&self, msg: String) -> String { msg } + + /// Test method, calls http endpoint + pub async fn http_get(&self, url: String) -> Result { + let client = self.0.internal.get_http_client(); + let res = client + .get(&url) + .send() + .await + .map_err(bitwarden::Error::Reqwest)?; + + Ok(res.text().await.map_err(bitwarden::Error::Reqwest)?) + } } fn init_logger() { diff --git a/languages/kotlin/sdk/build.gradle b/languages/kotlin/sdk/build.gradle index c41bccac1..d3ea098e3 100644 --- a/languages/kotlin/sdk/build.gradle +++ b/languages/kotlin/sdk/build.gradle @@ -12,8 +12,8 @@ android { minSdk 28 targetSdk 34 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + consumerProguardFiles 'consumer-rules.pro' } buildTypes { @@ -31,7 +31,7 @@ android { } lint { - baseline = file("lint-baseline.xml") + baseline = file('lint-baseline.xml') } publishing { @@ -52,9 +52,9 @@ publishing { // PRs: use the branch name. // Main: Grab it from `crates/bitwarden/Cargo.toml` - def branchName = "git branch --show-current".execute().text.trim() + def branchName = 'git branch --show-current'.execute().text.trim() - if (branchName == "main") { + if (branchName == 'main') { def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim() def match = ~/version = "(.*)"/ def matcher = match.matcher(content) @@ -73,19 +73,38 @@ publishing { } repositories { maven { - name = "GitHubPackages" - url = "https://maven.pkg.github.com/bitwarden/sdk" + name = 'GitHubPackages' + url = 'https://maven.pkg.github.com/bitwarden/sdk' credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") + username = System.getenv('GITHUB_ACTOR') + password = System.getenv('GITHUB_TOKEN') } } } } +// Find and include the classes.jar from platform-verifier. +// +// Based on the instructions from the readme in https://github.com/rustls/rustls-platform-verifier +// and issue details from https://github.com/rustls/rustls-platform-verifier/issues/115. +File findRustlsPlatformVerifierClassesJar() { + def dependencyText = providers.exec { + it.workingDir = new File('../../') + commandLine('cargo', 'metadata', '--format-version', '1', '--manifest-path', 'crates/bitwarden-uniffi/Cargo.toml') + }.standardOutput.asText.get() + + def dependencyJson = new groovy.json.JsonSlurper().parseText(dependencyText) + def manifestPath = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path) + + def aar = fileTree(manifestPath.parentFile).matching { + include "maven/rustls/rustls-platform-verifier/*/rustls-platform-verifier-*.aar" + }.getSingleFile() + return zipTree(aar).matching { include 'classes.jar'}.getSingleFile() +} + dependencies { implementation 'net.java.dev.jna:jna:5.14.0@aar' - implementation 'rustls:rustls-platform-verifier:latest.release' + implementation files(findRustlsPlatformVerifierClassesJar()) implementation 'androidx.core:core-ktx:1.13.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' diff --git a/languages/kotlin/settings.gradle b/languages/kotlin/settings.gradle index e82ac3727..fac8f3fae 100644 --- a/languages/kotlin/settings.gradle +++ b/languages/kotlin/settings.gradle @@ -10,25 +10,9 @@ dependencyResolutionManagement { repositories { google() mavenCentral() - - maven { - url = findRustlsPlatformVerifierProject() - metadataSources.artifact() - } } } -String findRustlsPlatformVerifierProject() { - def dependencyText = providers.exec { - it.workingDir = new File("../../") - commandLine("cargo", "metadata", "--format-version", "1", "--manifest-path", "crates/bitwarden-uniffi/Cargo.toml") - }.standardOutput.asText.get() - - def dependencyJson = new groovy.json.JsonSlurper().parseText(dependencyText) - def manifestPath = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path) - return new File(manifestPath.parentFile, "maven").path -} - -rootProject.name = "My Application" +rootProject.name = 'My Application' include ':app' include ':sdk'