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

Implemented BindingsAdapter

parent 0807a85f
No related branches found
No related tags found
No related merge requests found
package io.elixxir.dapp.bindings.data
interface Bindings {
import io.elixxir.dapp.session.model.SessionPassword
internal interface Bindings {
fun generateSecret(byteLength: Long): SessionPassword
}
package io.elixxir.dapp.bindings.data
import io.elixxir.dapp.session.model.SessionPassword
import bindings.Bindings as CoreBindings
@JvmInline
value class BindingsAdapter(private val bindings: CoreBindings): Bindings
\ No newline at end of file
internal class BindingsAdapter: Bindings {
override fun generateSecret(byteLength: Long): SessionPassword {
return SessionPassword(CoreBindings.generateSecret(byteLength))
}
}
\ No newline at end of file
......@@ -4,8 +4,8 @@ import android.os.Build
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyInfo
import android.security.keystore.KeyProperties
import bindings.Bindings
import io.elixxir.dapp.api.model.CommonProperties
import io.elixxir.dapp.bindings.data.Bindings
import io.elixxir.dapp.preferences.KeyStorePreferences
import io.elixxir.dapp.session.model.SecureHardwareException
import io.elixxir.dapp.session.model.SessionPassword
......@@ -31,6 +31,7 @@ internal interface SessionKeyStore {
internal class DappSessionKeystore private constructor(
properties: CommonProperties,
private val preferences: KeyStorePreferences,
private val bindings: Bindings
) : SessionKeyStore, CommonProperties by properties {
override suspend fun createSessionPassword(requireSecureHardware: Boolean): Result<Unit> =
......@@ -52,23 +53,23 @@ internal class DappSessionKeystore private constructor(
private fun generatePassword() {
val encryptionTime = measureTimeMillis {
val bytesNumber: Long = PASSWORD_LENGTH
val passwordLength = PASSWORD_LENGTH
log("Generating a password...")
log("Generating a password with $bytesNumber bytes")
log("Generating a password with $passwordLength bytes")
var secret: ByteArray
var secret: SessionPassword
val generationTime = measureTimeMillis {
do {
secret = Bindings.generateSecret(bytesNumber)
secret = bindings.generateSecret(passwordLength)
log("Password (Bytearray): $secret")
log("Password (String64): ${secret.toBase64String()}")
log("Password (String64): ${secret.value.toBase64String()}")
val isAllZeroes = byteArrayOf(bytesNumber.toByte()).contentEquals(secret)
val isAllZeroes = byteArrayOf(passwordLength.toByte()).contentEquals(secret.value)
log("IsAllZeroes: $isAllZeroes")
} while (isAllZeroes)
}
log("Total generation time: $generationTime ms")
rsaEncryptPwd(secret)
rsaEncryptPwd(secret.value)
}
log("Total encryption time: $encryptionTime ms")
}
......@@ -228,7 +229,10 @@ internal class DappSessionKeystore private constructor(
)
private const val PASSWORD_LENGTH = 64L
internal fun newInstance(properties: CommonProperties, preferences: KeyStorePreferences) =
DappSessionKeystore(properties, preferences)
internal fun newInstance(
properties: CommonProperties,
preferences: KeyStorePreferences,
bindings: Bindings
) = DappSessionKeystore(properties, preferences, bindings)
}
}
\ 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