Skip to content

Commit

Permalink
Log out the keystore level also
Browse files Browse the repository at this point in the history
  • Loading branch information
harri35 committed Nov 29, 2022
1 parent 755b36c commit 5c915c1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.math.RoundingMode

@Suppress("LongParameterList")
class StorageSpeedMeasurementResults(
val keyStoreLevelForEncrypted: KeyStoreLevel,
val dataSizeBytes: Int,
val writeClearText: StorageSpeedMeasurement,
val writeEncrypted: StorageSpeedMeasurement,
Expand All @@ -30,7 +31,8 @@ class StorageSpeedMeasurementResults(
roundAndFormatToSec(deleteClearText.standardDeviationSec),
roundAndFormatToSec(deleteEncrypted.averageSec),
roundAndFormatToSec(deleteEncrypted.standardDeviationSec),
dataSizeBytes.toString()
dataSizeBytes.toString(),
keyStoreLevelForEncrypted.toString()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -15,4 +16,6 @@ interface StorageGateway {
fun removeData(tag: String)

fun getTypeName(): String

fun getKeyStoreLevel(): KeyStoreLevel
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class StorageTestUseCase @Inject constructor(
}

return StorageSpeedMeasurementResults(
keyStoreLevelForEncrypted = encryptedStorageGateway.getKeyStoreLevel(),
writeClearText = writeClearText,
writeEncrypted = writeEncrypted,
readClearText = readClearText,
Expand Down
1 change: 1 addition & 0 deletions app-domain/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<string name="text_measurement_log_line">
"
KeyStoreLevel: %14$s
Write %13$s bytes (sec)
cleartxt %1$s avg %2$s stdev
encrypt %3$s avg %4$s stdev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 5c915c1

Please sign in to comment.