add keycard pair and generateKey methods

This commit is contained in:
Andrea Franz 2021-10-06 09:56:17 +02:00
parent 35ba848127
commit 4bafb4bb6b
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
6 changed files with 48 additions and 2 deletions

View File

@ -5,9 +5,11 @@ from base/bookmarks as bookmarks_methods import storeBookmark, updateBookmark, g
export storeBookmark, updateBookmark, getBookmarks, deleteBookmark
from base/keycard as keycard_methods import keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication,
keycardUnpair, keycardGenerateKey
export keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication,
keycardUnpair, keycardGenerateKey
import statusgo/bookmarks as statusgo_bookmarks
import mock/bookmarks as mock_bookmarks

View File

@ -24,3 +24,10 @@ method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPub
method keycardGetStatusApplication*(self: Backend): KeycardStatus =
raise newException(ValueError, "No implementation available")
method keycardUnpair*(self: Backend, index: int) =
raise newException(ValueError, "No implementation available")
method keycardGenerateKey*(self: Backend): string =
raise newException(ValueError, "No implementation available")

View File

@ -20,3 +20,8 @@ method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onl
method keycardGetStatusApplication*(self: MockBackend): KeycardStatus =
result = KeycardStatus()
method keycardUnpair*(self: MockBackend, index: int) = discard
method keycardGenerateKey*(self: MockBackend): string =
result = "0x00"

View File

@ -91,3 +91,19 @@ method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus =
pukRetryCount: parsedResponse["status"]["pukRetryCount"].getInt(),
keyInitialized: parsedResponse["status"]["keyInitialized"].getBool()
)
method keycardUnpair*(self: StatusGoBackend, index: int) =
let inputJSON = %* {
"index": index,
}
let response = keycard_go.unpair($inputJSON)
let parsedResponse = parseJson(response)
if not parsedResponse{"ok"}.getBool():
raise KeycardUnpairException(error: parsedResponse{"error"}.getStr())
method keycardGenerateKey*(self: StatusGoBackend): string =
let response = keycard_go.generateKey()
let parsedResponse = parseJson(response)
if not parsedResponse{"ok"}.getBool():
raise KeycardGenerateKeyException(error: parsedResponse{"error"}.getStr())
result = parsedResponse["keyUID"].getStr()

View File

@ -58,3 +58,15 @@ proc getStatusApplication*(self: KeycardModel): KeycardStatus =
result = self.backend.keycardGetStatusApplication()
except:
raise
proc unpair*(self: KeycardModel, index: int) =
try:
self.backend.keycardUnpair(index)
except:
raise
proc generateKey*(self: KeycardModel): string =
try:
result = self.backend.keycardGenerateKey()
except:
raise

View File

@ -13,6 +13,10 @@ type KeycardOpenSecureChannelException* = ref object of KeycardException
type KeycardGetStatusException* = ref object of KeycardException
type KeycardUnpairException* = ref object of KeycardException
type KeycardGenerateKeyException* = ref object of KeycardException
type KeycardVerifyPINException* = ref object of KeycardException
pinRetry*: int64