From 41c186951c154ddd5b901e1779dd9a3d13e51a7a Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Tue, 23 Oct 2018 12:06:00 +0200 Subject: [PATCH] check if card is already initialized --- lightwallet/commands.go | 2 ++ lightwallet/installer.go | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lightwallet/commands.go b/lightwallet/commands.go index 88dcb97..a2c8392 100644 --- a/lightwallet/commands.go +++ b/lightwallet/commands.go @@ -7,6 +7,8 @@ import ( const ( InsInit = uint8(0xFE) + + tagSelectResponsePreInitialized = uint8(0x80) ) func NewCommandInit(data []byte) *apdu.Command { diff --git a/lightwallet/installer.go b/lightwallet/installer.go index 857d376..173c4bb 100644 --- a/lightwallet/installer.go +++ b/lightwallet/installer.go @@ -74,6 +74,11 @@ func (i *Installer) Init() (*Secrets, error) { return nil, err } + if resp.Data[0] != tagSelectResponsePreInitialized { + err := fmt.Errorf("card already initialized (%x).", resp.Data[0]) + return nil, err + } + cardKeyData := resp.Data[2:] secureChannel, err := NewSecureChannel(i.c, cardKeyData) if err != nil { @@ -91,8 +96,6 @@ func (i *Installer) Init() (*Secrets, error) { return nil, err } - fmt.Printf("RESP: %+v\n", resp) - return secrets, nil }