Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Our SDK is available on Maven Central.

```groovy
implementation 'de.contentpass:contentpass-android:2.2.7'
implementation 'de.contentpass:contentpass-android:2.2.8'
```

Add this to your app's `build.gradle` file's `dependencies` element.
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ kapt {
extra.apply{
set("PUBLISH_GROUP_ID", "de.contentpass")
set("PUBLISH_ARTIFACT_ID", "contentpass-android")
set("PUBLISH_VERSION", "2.2.7")
set("PUBLISH_VERSION", "2.2.8")
}

apply("${rootProject.projectDir}/scripts/publish-module.gradle")
19 changes: 14 additions & 5 deletions lib/src/main/java/de/contentpass/lib/KeyStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,27 @@ internal class KeyStore(private val context: Context, private val propertyId: St
if (!keystore.containsAlias(keyPairAlias)) {
createKeyPair()
}
val pair = try {
keystore.getEntry(keyPairAlias, null) as? VendorKeyStore.PrivateKeyEntry
val recovered = try {
val key = keystore.getKey(keyPairAlias, null) as? PrivateKey
val cert = keystore.getCertificate(keyPairAlias)
if (key != null && cert != null) {
key to cert.publicKey
} else {
null
}
} catch (e: Exception) {
null
} ?: run {
// Android 8 can throw when the entry is invalidated/corrupted; recreate it.
keystore.deleteEntry(keyPairAlias)
createKeyPair()
keystore.getEntry(keyPairAlias, null) as VendorKeyStore.PrivateKeyEntry
val key = keystore.getKey(keyPairAlias, null) as PrivateKey
val cert = keystore.getCertificate(keyPairAlias)
?: throw IllegalStateException("Failed to load keystore certificate after regeneration.")
key to cert.publicKey
}
privateKey = pair.privateKey
publicKey = pair.certificate.publicKey
privateKey = recovered.first
publicKey = recovered.second
}

private fun createKeyPair(): KeyPair {
Expand Down