From 5c915c1de21297ab3afa8e9f2e79d554c339e108 Mon Sep 17 00:00:00 2001 From: Harri Kirik Date: Tue, 29 Nov 2022 16:27:22 +0200 Subject: [PATCH] Log out the keystore level also --- .../domain/entities/KeyStoreLevel.kt | 21 +++++++++++++++++++ .../StorageSpeedMeasurementResults.kt | 4 +++- .../domain/gateway/StorageGateway.kt | 3 +++ .../usecases/storage/StorageTestUseCase.kt | 1 + app-domain/src/main/res/values/strings.xml | 1 + .../storage/StorageClearTextImpl.kt | 5 +++++ .../storage/StorageEncryptedImpl.kt | 12 +++++++++++ app/build.gradle | 2 +- 8 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/KeyStoreLevel.kt diff --git a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/KeyStoreLevel.kt b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/KeyStoreLevel.kt new file mode 100644 index 0000000..d883373 --- /dev/null +++ b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/KeyStoreLevel.kt @@ -0,0 +1,21 @@ +package mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities + +sealed class KeyStoreLevel { + object None : KeyStoreLevel() { + override fun toString(): String { + return "None" + } + } + + object TEE : KeyStoreLevel() { + override fun toString(): String { + return "TEE hardware" + } + } + + object Strongbox : KeyStoreLevel() { + override fun toString(): String { + return "Strongbox Keymaster hardware" + } + } +} diff --git a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/StorageSpeedMeasurementResults.kt b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/StorageSpeedMeasurementResults.kt index b86f61e..a661511 100644 --- a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/StorageSpeedMeasurementResults.kt +++ b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/entities/StorageSpeedMeasurementResults.kt @@ -6,6 +6,7 @@ import java.math.RoundingMode @Suppress("LongParameterList") class StorageSpeedMeasurementResults( + val keyStoreLevelForEncrypted: KeyStoreLevel, val dataSizeBytes: Int, val writeClearText: StorageSpeedMeasurement, val writeEncrypted: StorageSpeedMeasurement, @@ -30,7 +31,8 @@ class StorageSpeedMeasurementResults( roundAndFormatToSec(deleteClearText.standardDeviationSec), roundAndFormatToSec(deleteEncrypted.averageSec), roundAndFormatToSec(deleteEncrypted.standardDeviationSec), - dataSizeBytes.toString() + dataSizeBytes.toString(), + keyStoreLevelForEncrypted.toString() ) } diff --git a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/gateway/StorageGateway.kt b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/gateway/StorageGateway.kt index e9d443e..a3f99c5 100644 --- a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/gateway/StorageGateway.kt +++ b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/gateway/StorageGateway.kt @@ -1,5 +1,6 @@ package mobi.lab.hardwarekeybasedencryptedstoragetester.domain.gateway +import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.KeyStoreLevel import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.StorageException import java.lang.reflect.Type @@ -15,4 +16,6 @@ interface StorageGateway { fun removeData(tag: String) fun getTypeName(): String + + fun getKeyStoreLevel(): KeyStoreLevel } diff --git a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/usecases/storage/StorageTestUseCase.kt b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/usecases/storage/StorageTestUseCase.kt index bc80498..b2d1fbb 100644 --- a/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/usecases/storage/StorageTestUseCase.kt +++ b/app-domain/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/domain/usecases/storage/StorageTestUseCase.kt @@ -63,6 +63,7 @@ class StorageTestUseCase @Inject constructor( } return StorageSpeedMeasurementResults( + keyStoreLevelForEncrypted = encryptedStorageGateway.getKeyStoreLevel(), writeClearText = writeClearText, writeEncrypted = writeEncrypted, readClearText = readClearText, diff --git a/app-domain/src/main/res/values/strings.xml b/app-domain/src/main/res/values/strings.xml index b739cdb..7555687 100644 --- a/app-domain/src/main/res/values/strings.xml +++ b/app-domain/src/main/res/values/strings.xml @@ -2,6 +2,7 @@ " +KeyStoreLevel: %14$s Write %13$s bytes (sec) cleartxt %1$s avg %2$s stdev encrypt %3$s avg %4$s stdev diff --git a/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageClearTextImpl.kt b/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageClearTextImpl.kt index 762a78d..67e1a76 100644 --- a/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageClearTextImpl.kt +++ b/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageClearTextImpl.kt @@ -7,6 +7,7 @@ import android.text.TextUtils import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.JsonSyntaxException +import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.KeyStoreLevel import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.StorageException import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.gateway.ClearTextStorageGateway import java.lang.reflect.Type @@ -81,6 +82,10 @@ class StorageClearTextImpl @Inject constructor(private val appContext: Context) override fun getTypeName() = "Clear text storage" + override fun getKeyStoreLevel(): KeyStoreLevel { + return KeyStoreLevel.None + } + private fun getSharedPrefsFor(tag: String): SharedPreferences { return appContext.getSharedPreferences(getStoragePrefix(tag), Context.MODE_PRIVATE) } diff --git a/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageEncryptedImpl.kt b/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageEncryptedImpl.kt index 4de138d..16bd6ca 100644 --- a/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageEncryptedImpl.kt +++ b/app-infrastructure/src/main/java/mobi/lab/hardwarekeybasedencryptedstoragetester/infrastructure/storage/StorageEncryptedImpl.kt @@ -9,6 +9,7 @@ import androidx.security.crypto.MasterKey import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.JsonSyntaxException +import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.KeyStoreLevel import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.entities.StorageException import mobi.lab.hardwarekeybasedencryptedstoragetester.domain.gateway.EncryptedStorageGateway import java.lang.reflect.Type @@ -83,6 +84,17 @@ class StorageEncryptedImpl @Inject constructor(private val appContext: Context) override fun getTypeName() = "Encrypted storage" + override fun getKeyStoreLevel(): KeyStoreLevel { + val masterKey = createOrGetMasterKey() + return if (masterKey.isStrongBoxBacked) { + KeyStoreLevel.Strongbox + } else if (masterKey.isKeyStoreBacked) { + KeyStoreLevel.TEE + } else { + KeyStoreLevel.None + } + } + private fun getEncryptedSharedPreferencesFor(tag: String): SharedPreferences { val masterKey: MasterKey = createOrGetMasterKey() diff --git a/app/build.gradle b/app/build.gradle index 73b1c9b..3f79b99 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ ext { */ versionMajor = 1 versionMinor = 0 - versionPatch = 1 + versionPatch = 2 versionBuild = 0 // Use this when builds with the same version are needed. Change to 0 once done initVersioning() }