Skip to content
Snippets Groups Projects
Commit bf617a35 authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Updated SessionKeystore constructor and factory method

parent abdf8875
Branches
No related tags found
No related merge requests found
......@@ -5,12 +5,12 @@ import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyInfo
import android.security.keystore.KeyProperties
import bindings.Bindings
import io.elixxir.dapp.DappSdk.Companion.defaultDispatcher
import io.elixxir.dapp.preferences.KeyStorePreferences
import io.elixxir.dapp.session.model.SessionPassword
import io.elixxir.dapp.util.fromBase64toByteArray
import io.elixxir.dapp.util.toBase64String
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.security.*
......@@ -35,11 +35,11 @@ class SecureHardwareException : Exception() {
class DappSessionKeystore private constructor(
private val preferences: KeyStorePreferences,
private val defaultDispatcher: CoroutineDispatcher = Dispatchers.IO
private val dispatcher: CoroutineDispatcher
) : SessionKeyStore {
override suspend fun createSessionPassword(requireSecureHardware: Boolean): Result<Unit> =
withContext(defaultDispatcher) {
withContext(dispatcher) {
if (requireSecureHardware && !isHardwareBackedKeyStore()) {
return@withContext Result.failure(SecureHardwareException())
}
......@@ -190,7 +190,7 @@ class DappSessionKeystore private constructor(
IllegalBlockSizeException::class,
BadPaddingException::class
)
override suspend fun rsaDecryptPassword(): SessionPassword = withContext(defaultDispatcher) {
override suspend fun rsaDecryptPassword(): SessionPassword = withContext(dispatcher) {
val encryptedBytes = preferences.userSecret.fromBase64toByteArray()
val key = getPrivateKey()
val cipher1 = Cipher.getInstance(KEYSTORE_ALGORITHM)
......@@ -234,8 +234,11 @@ class DappSessionKeystore private constructor(
)
private const val PASSWORD_LENGTH = 64L
internal fun newInstance(
preferences: KeyStorePreferences,
): DappSessionKeystore = DappSessionKeystore(preferences)
internal fun newInstance(preferences: KeyStorePreferences): DappSessionKeystore {
return DappSessionKeystore(
preferences,
defaultDispatcher
)
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment