Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ let config = ClientConfig::builder_with_provider(arc_crypto_provider)
### Android
Some manual setup is required, outside of `cargo`, to use this crate on Android. In order to
use Android's certificate verifier, the crate needs to call into the JVM. A small Kotlin
component must be included in your app's build to support `rustls-platform-verifier`.
component must be included in your app's build to support `rustls-platform-verifier`. If distributing a library, that component will need to be bundled into your release jar
[as it is not yet available on Maven](https://github.com/rustls/rustls-platform-verifier/issues/115).

#### Gradle Setup

Expand All @@ -124,6 +125,10 @@ Kotlin scripts (`.gradle.kts`) for configuration instead, an example snippet is
Inside of your project's `build.gradle` file, add the following code and Maven repository definition. If applicable, this should only be the one "app" sub-project that
will actually be using this crate at runtime. With multiple projects running this, your Gradle configuration performance may degrade.

<details>

<summary>App Snippets</summary>

`$PATH_TO_DEPENDENT_CRATE` is the relative path to the Cargo manifest (`Cargo.toml`) of any crate in your workspace that depends on `rustls-platform-verifier` from
the location of your `build.gradle` file:

Expand Down Expand Up @@ -157,6 +162,35 @@ Then, wherever you declare your dependencies, add the following:
implementation "rustls:rustls-platform-verifier:latest.release"
```

</details>

<details>
<summary>Library Snippets</summary>

```groovy
import groovy.json.JsonSlurper

// ...Your own script code could be here...

File findRustlsPlatformVerifierClasses() {
def dependencyText = providers.exec {
it.workingDir = new File("../")
commandLine("cargo", "metadata", "--format-version", "1")
}.standardOutput.asText.get()

def dependencyJson = new JsonSlurper().parseText(dependencyText)
def manifestFile = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path)
return new File(manifestFile.parentFile, "classes.jar")
}
```

Then, wherever you declare your dependencies, add the following:
```groovy
implementation files(findRustlsPlatformVerifierClasses())
```

</details>

Cargo automatically handles finding the downloaded crate in the correct location for your project. It also handles updating the version when
new releases of `rustls-platform-verifier` are published. If you only use published releases, no extra maintenance should be required.

Expand All @@ -166,7 +200,7 @@ implementation part can be located on-disk.
##### Kotlin and Gradle

<details>
<summary>Kotlin script example</summary>
<summary>Kotlin script App example</summary>

`build.gradle.kts`:
```kotlin
Expand Down Expand Up @@ -224,6 +258,47 @@ rustls-platform-verifier = { group = "rustls", name = "rustls-platform-verifier"
```
</details>

<details>
<summary>Kotlin script Library example</summary>

`build.gradle.kts`:
```kotlin
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive

buildscript {
dependencies {
classpath(libs.kotlinx.serialization.json)
}
}

fun findRustlsPlatformVerifierClasses(): File {
val dependencyJson = providers.exec {
workingDir = File(project.rootDir, "../")
commandLine("cargo", "metadata", "--format-version", "1")
}.standardOutput.asText

val path = Json.decodeFromString<JsonObject>(dependencyJson.get())
.getValue("packages")
.jsonArray
.first { element ->
element.jsonObject.getValue("name").jsonPrimitive.content == "rustls-platform-verifier-android"
}.jsonObject.getValue("manifest_path").jsonPrimitive.content

val manifestFile = File(path)
return File(manifestFile.parentFile, "classes.jar")
}

dependencies {
implementation(files(findRustlsPlatformVerifierClasses()))
}
```
</details>

#### Proguard

If your Android application makes use of Proguard for optimizations, its important to make sure that the Android verifier component isn't optimized
Expand Down
Loading