Pin : some clean up and fixes
This commit is contained in:
@@ -16,13 +16,17 @@
|
||||
|
||||
package io.element.android.libraries.cryptography.impl
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.cryptography.api.AESEncryptionSpecs
|
||||
import io.element.android.libraries.cryptography.api.SecretKeyProvider
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import java.security.KeyStore
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val ANDROID_KEYSTORE = "AndroidKeyStore"
|
||||
|
||||
@@ -30,8 +34,11 @@ private const val ANDROID_KEYSTORE = "AndroidKeyStore"
|
||||
* Default implementation of [SecretKeyProvider] that uses the Android Keystore to store the keys.
|
||||
* The generated key uses AES algorithm, with a key size of 128 bits, and the GCM block mode.
|
||||
*/
|
||||
class KeyStoreSecretKeyProvider : SecretKeyProvider {
|
||||
@ContributesBinding(AppScope::class)
|
||||
class KeyStoreSecretKeyProvider @Inject constructor() : SecretKeyProvider {
|
||||
|
||||
// False positive lint issue
|
||||
@SuppressLint("WrongConstant")
|
||||
override fun getOrCreateKey(alias: String): SecretKey {
|
||||
val keyStore = KeyStore.getInstance(ANDROID_KEYSTORE)
|
||||
val secretKeyEntry = (keyStore.getEntry(alias, null) as? KeyStore.SecretKeyEntry)
|
||||
|
||||
@@ -28,7 +28,7 @@ class AESEncryptionDecryptionServiceTest {
|
||||
private val encryptionDecryptionService = AESEncryptionDecryptionService()
|
||||
|
||||
@Test
|
||||
fun given_a_valid_key_then_encrypt_decrypt_work() {
|
||||
fun `given a valid key then encrypt decrypt work`() {
|
||||
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES)
|
||||
keyGenerator.init(128)
|
||||
val key = keyGenerator.generateKey()
|
||||
@@ -39,7 +39,7 @@ class AESEncryptionDecryptionServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun given_a_wrong_key_then_decrypt_fail() {
|
||||
fun `given a wrong key then decrypt fail`() {
|
||||
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES)
|
||||
keyGenerator.init(128)
|
||||
val encryptionKey = keyGenerator.generateKey()
|
||||
|
||||
Reference in New Issue
Block a user