draft of key loading

This commit is contained in:
Michele Balistreri 2019-11-04 15:55:05 +03:00
parent 9c1f4fb612
commit 97f7b9256a
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
5 changed files with 36 additions and 3 deletions

View File

@ -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

View File

@ -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 }
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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())