draft of key loading
This commit is contained in:
parent
9c1f4fb612
commit
97f7b9256a
|
@ -4,7 +4,7 @@ import android.content.Intent
|
|||
|
||||
interface CardCommand {
|
||||
enum class Result {
|
||||
OK, CANCEL, RETRY, UX_ONGOING
|
||||
OK, CANCEL, RETRY, UX_ONGOING, STOP
|
||||
}
|
||||
|
||||
fun run(context: CardScriptExecutor.ScriptContext): Result
|
||||
|
|
|
@ -35,7 +35,8 @@ class CardScriptExecutor(private val activity: Activity, private val listener: S
|
|||
script@for (cmd in runningScript) {
|
||||
when (cmd.run(executionContext)) {
|
||||
CardCommand.Result.OK -> {}
|
||||
CardCommand.Result.CANCEL -> { success = false; break@script}
|
||||
CardCommand.Result.STOP -> { break@script }
|
||||
CardCommand.Result.CANCEL -> { success = false; break@script }
|
||||
CardCommand.Result.UX_ONGOING -> { waitingCmd = cmd; return }
|
||||
CardCommand.Result.RETRY -> { return }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package im.status.keycard.connect.card
|
||||
|
||||
class CheckMasterKeyCommand : CardCommand {
|
||||
override fun run(context: CardScriptExecutor.ScriptContext): CardCommand.Result {
|
||||
return if (context.cmdSet.applicationInfo.hasMasterKey()) CardCommand.Result.STOP else CardCommand.Result.OK
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package im.status.keycard.connect.card
|
||||
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
|
||||
class LoadKeyCommand : CardCommand {
|
||||
|
||||
override fun run(context: CardScriptExecutor.ScriptContext): CardCommand.Result {
|
||||
/* TODO: this should instead prompt and ask if
|
||||
* 1. You want to generate keys on card with no backup (most secure)
|
||||
* 2. You want to generate a new key with backup phrase
|
||||
* 3. You want to import an existing key
|
||||
*/
|
||||
|
||||
try {
|
||||
context.cmdSet.generateKey().checkOK()
|
||||
} catch(e: IOException) {
|
||||
return CardCommand.Result.RETRY
|
||||
} catch (e: Exception) {
|
||||
return CardCommand.Result.CANCEL
|
||||
}
|
||||
|
||||
return CardCommand.Result.OK
|
||||
}
|
||||
}
|
|
@ -2,5 +2,5 @@ package im.status.keycard.connect.card
|
|||
|
||||
fun scriptWithSecureChannel(): List<CardCommand> = listOf(SelectCommand(), InitCommand(), OpenSecureChannelCommand())
|
||||
fun scriptWithAuthentication(): List<CardCommand> = scriptWithSecureChannel().plus(VerifyPINCommand())
|
||||
fun cardCheckupScript(): List<CardCommand> = scriptWithAuthentication()
|
||||
fun cardCheckupScript(): List<CardCommand> = scriptWithSecureChannel().plus(CheckMasterKeyCommand()).plus(VerifyPINCommand()).plus(LoadKeyCommand())
|
||||
|
||||
|
|
Loading…
Reference in New Issue