Catch AssertionError when loading certificates/private key (mTLS) (#4456)

This commit is contained in:
Joris Pelgröm 2024-06-14 19:05:14 +02:00 committed by GitHub
parent d516018dc4
commit 4e9c958232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -63,16 +63,24 @@ class KeyChainRepositoryImpl @Inject constructor(
if (chain == null) {
chain = try {
KeyChain.getCertificateChain(context, alias!!)
} catch (e: Exception) {
Log.e(TAG, "Exception getting certificate chain", e)
} catch (t: Throwable) {
when (t) {
is AssertionError,
is Exception -> Log.e(TAG, "Issue getting certificate chain", t)
else -> throw t
}
null
}
}
if (key == null) {
key = try {
KeyChain.getPrivateKey(context, alias!!)
} catch (e: Exception) {
Log.e(TAG, "Exception getting private key", e)
} catch (t: Throwable) {
when (t) {
is AssertionError,
is Exception -> Log.e(TAG, "Issue getting private key", t)
else -> throw t
}
null
}
}