keycardExportKey returns priv/pub key

This commit is contained in:
Andrea Franz 2021-10-06 10:59:16 +02:00 committed by Michele Balistreri
parent 089413e6bf
commit b602caf727
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
5 changed files with 14 additions and 6 deletions

View File

@ -19,7 +19,7 @@ method keycardOpenSecureChannel*(self: Backend, index: int, key: string) =
method keycardVerifyPin*(self: Backend, pin: string) =
raise newException(ValueError, "No implementation available")
method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey =
raise newException(ValueError, "No implementation available")
method keycardGetStatusApplication*(self: Backend): KeycardStatus =

View File

@ -15,8 +15,8 @@ method keycardOpenSecureChannel*(self: MockBackend, index: int, key: string) = d
method keycardVerifyPin*(self: MockBackend, pin: string) = discard
method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
result = "0x00"
method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey =
result = KeycardExportedKey()
method keycardGetStatusApplication*(self: MockBackend): KeycardStatus =
result = KeycardStatus()

View File

@ -67,7 +67,7 @@ method keycardVerifyPin*(self: StatusGoBackend, pin: string) =
if not parsedResponse{"ok"}.getBool():
raise KeycardVerifyPINException(error: parsedResponse{"error"}.getStr())
method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey =
let inputJSON = %* {
"derive": derive,
"makeCurrent": makeCurrent,
@ -79,7 +79,10 @@ method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool,
if not parsedResponse{"ok"}.getBool():
raise KeycardSelectException(error: parsedResponse{"error"}.getStr())
result = parsedResponse["key"].getStr()
result = KeycardExportedKey(
privKey: parsedResponse["privateKey"].getStr(),
pubKey: parsedResponse["publicKey"].getStr()
)
method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus =
let response = keycard_go.getStatusApplication()

View File

@ -47,7 +47,7 @@ proc verifyPin*(self: KeycardModel, pin: string) =
except:
raise
proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey =
try:
result = self.backend.keycardExportKey(derive, makeCurrent, onlyPublic, path)
except:

View File

@ -41,3 +41,8 @@ type KeycardStatus* = ref object
pukRetryCount *: int64
keyInitialized*: bool
path*: string
type KeycardExportedKey* = ref object
privKey*: string
pubKey*: string