Skip to content

Commit 3853090

Browse files
authored
Merge pull request #17 from contentpass/CHORE-android-8-corrupt-keystore-entry
Handle corrupt KeyStore entry on Android 8
2 parents dfe35ac + f071fa5 commit 3853090

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Our SDK is available on Maven Central.
1515

1616
```groovy
17-
implementation 'de.contentpass:contentpass-android:2.2.6'
17+
implementation 'de.contentpass:contentpass-android:2.2.7'
1818
```
1919

2020
Add this to your app's `build.gradle` file's `dependencies` element.

lib/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ kapt {
5858
extra.apply{
5959
set("PUBLISH_GROUP_ID", "de.contentpass")
6060
set("PUBLISH_ARTIFACT_ID", "contentpass-android")
61-
set("PUBLISH_VERSION", "2.2.6")
61+
set("PUBLISH_VERSION", "2.2.7")
6262
}
6363

6464
apply("${rootProject.projectDir}/scripts/publish-module.gradle")

lib/src/main/java/de/contentpass/lib/KeyStore.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ internal class KeyStore(private val context: Context, private val propertyId: St
5050
if (!keystore.containsAlias(keyPairAlias)) {
5151
createKeyPair()
5252
}
53-
val pair = keystore.getEntry(keyPairAlias, null) as VendorKeyStore.PrivateKeyEntry
53+
val pair = try {
54+
keystore.getEntry(keyPairAlias, null) as? VendorKeyStore.PrivateKeyEntry
55+
} catch (e: Exception) {
56+
null
57+
} ?: run {
58+
// Android 8 can throw when the entry is invalidated/corrupted; recreate it.
59+
keystore.deleteEntry(keyPairAlias)
60+
createKeyPair()
61+
keystore.getEntry(keyPairAlias, null) as VendorKeyStore.PrivateKeyEntry
62+
}
5463
privateKey = pair.privateKey
5564
publicKey = pair.certificate.publicKey
5665
}

0 commit comments

Comments
 (0)