use legacy key alias for keystore aliases

This commit is contained in:
Adam Velebil 2022-08-25 17:50:22 +02:00
parent ab0e76d24c
commit 7d20d8bc96
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084

View File

@ -14,7 +14,7 @@ class KeyStoreProvider : KeyProvider {
keystore.load(null)
}
override fun hasKey(deviceId: String): Boolean = keystore.containsAlias(deviceId)
override fun hasKey(deviceId: String): Boolean = keystore.containsAlias(getAlias(deviceId))
override fun getKey(deviceId: String): AccessKey? =
if (hasKey(deviceId)) {
@ -35,7 +35,7 @@ class KeyStoreProvider : KeyProvider {
override fun removeKey(deviceId: String) {
keystore.deleteEntry(deviceId)
keystore.deleteEntry(getAlias(deviceId))
}
override fun clearAll() {
@ -45,9 +45,13 @@ class KeyStoreProvider : KeyProvider {
private inner class KeyStoreStoredSigner(val deviceId: String) :
AccessKey {
val mac: Mac = Mac.getInstance(KeyProperties.KEY_ALGORITHM_HMAC_SHA1).apply {
init(keystore.getKey(deviceId, null))
init(keystore.getKey(getAlias(deviceId), null), null)
}
override fun calculateResponse(challenge: ByteArray): ByteArray = mac.doFinal(challenge)
}
// return key alias used in legacy app
private fun getAlias(deviceId: String) = "$deviceId,0"
}