Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ class CloudSecureAreaTest {
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData = keyUnlockData
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.multipaz.securearea

import org.multipaz.crypto.Algorithm
import org.multipaz.prompt.AndroidPromptModel
import org.multipaz.prompt.PromptModelNotAvailableException
import org.multipaz.prompt.Reason
Expand All @@ -9,6 +10,7 @@ object AndroidKeystoreDefaultKeyUnlockDataProvider: KeyUnlockDataProvider {
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData {
check(secureArea is AndroidKeystoreSecureArea)
Expand All @@ -21,7 +23,13 @@ object AndroidKeystoreDefaultKeyUnlockDataProvider: KeyUnlockDataProvider {
}
val humanReadable = promptModel.toHumanReadable(unlockReason, null)
if (!promptModel.showBiometricPrompt(
cryptoObject = unlockData.getCryptoObjectForSigning(),
cryptoObject = if (algorithm.isSigning) {
unlockData.getCryptoObjectForSigning()
} else if (algorithm.isKeyAgreement) {
unlockData.cryptoObjectForKeyAgreement
} else {
throw IllegalArgumentException("Algorithm isn't for signing or key agreement")
},
reason = unlockReason,
userAuthenticationTypes = keyInfo.userAuthenticationTypes,
requireConfirmation = humanReadable.requireConfirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ class AndroidKeystoreSecureArea private constructor(
} catch (_: KeyLockedException) {
val unlockDataProvider = coroutineContext[KeyUnlockDataProvider.Key]
?: AndroidKeystoreDefaultKeyUnlockDataProvider
val unlockData = unlockDataProvider.getKeyUnlockData(this, alias, unlockReason)
val unlockData = unlockDataProvider.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason
)
signNonInteractive(alias, dataToSign, unlockData)
}

Expand Down Expand Up @@ -522,7 +527,11 @@ class AndroidKeystoreSecureArea private constructor(
} catch (_: KeyLockedException) {
val unlockDataProvider = coroutineContext[KeyUnlockDataProvider.Key]
?: AndroidKeystoreDefaultKeyUnlockDataProvider
unlockDataProvider.getKeyUnlockData(this, alias, unlockReason)
unlockDataProvider.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason)
}
} while (true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.multipaz.securearea

import org.multipaz.crypto.Algorithm
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.coroutineContext
import org.multipaz.prompt.PromptModel
Expand Down Expand Up @@ -34,11 +35,13 @@ interface KeyUnlockDataProvider : CoroutineContext.Element {
*
* @param secureArea Secure Area where the locked key resides
* @param alias locked key's alias
* @param algorithm the algorithm to use for the key,
* @param unlockReason conveys the reason for the operation (e.g. credential presentment)
*/
suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData
}
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ open class CloudSecureArea protected constructor(
val unlockData = unlockDataProvider.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason
)
op.invoke(unlockData)
Expand Down Expand Up @@ -971,6 +972,7 @@ open class CloudSecureArea protected constructor(
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData {
check(secureArea is CloudSecureArea)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class SoftwareSecureArea private constructor(private val storageTable: StorageTa
val unlockData = unlockDataProvider.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason
)
op.invoke(unlockData)
Expand Down Expand Up @@ -298,6 +299,7 @@ class SoftwareSecureArea private constructor(private val storageTable: StorageTa
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData {
secureArea as SoftwareSecureArea
Expand All @@ -318,7 +320,6 @@ class SoftwareSecureArea private constructor(private val storageTable: StorageTa
PassphraseEvaluation.OK
} catch (e: Exception) {
if (e is CancellationException) throw e
// TODO: translations
PassphraseEvaluation.TryAgain
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class SoftwareSecureAreaTest {
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData = keyUnlockData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ class SecureEnclaveSecureArea private constructor(
// TODO: implement default KeyUnlockDataProvider by converting
// OperationReason to OperationReason.HumanReadable using PromptModel
// and the creating LAContext with title/subtitle from OperationReason.HumanReadable
val unlockData = unlockDataProvider?.getKeyUnlockData(this, alias, unlockReason)
val unlockData = unlockDataProvider?.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason
)
check(unlockData is SecureEnclaveKeyUnlockData?)
return Crypto.secureEnclaveEcSign(keyBlob, dataToSign, unlockData)
}
Expand All @@ -188,7 +193,12 @@ class SecureEnclaveSecureArea private constructor(
// TODO: implement default KeyUnlockDataProvider by converting
// OperationReason to OperationReason.HumanReadable using PromptModel
// and the creating LAContext with title/subtitle from OperationReason.HumanReadable
val unlockData = unlockDataProvider?.getKeyUnlockData(this, alias, unlockReason)
val unlockData = unlockDataProvider?.getKeyUnlockData(
secureArea = this,
alias = alias,
algorithm = getKeyInfo(alias).algorithm,
unlockReason = unlockReason
)
check(unlockData is SecureEnclaveKeyUnlockData?)
return Crypto.secureEnclaveEcKeyAgreement(keyBlob, otherKey, unlockData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private class TestKeyUnlockDataProvider(
override suspend fun getKeyUnlockData(
secureArea: SecureArea,
alias: String,
algorithm: Algorithm,
unlockReason: Reason
): KeyUnlockData = keyUnlockData
}
Loading