check if card is already initialized

This commit is contained in:
Andrea Franz 2018-10-23 12:06:00 +02:00
parent 61bc1a2764
commit 41c186951c
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 7 additions and 2 deletions

View File

@ -7,6 +7,8 @@ import (
const ( const (
InsInit = uint8(0xFE) InsInit = uint8(0xFE)
tagSelectResponsePreInitialized = uint8(0x80)
) )
func NewCommandInit(data []byte) *apdu.Command { func NewCommandInit(data []byte) *apdu.Command {

View File

@ -74,6 +74,11 @@ func (i *Installer) Init() (*Secrets, error) {
return nil, err 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:] cardKeyData := resp.Data[2:]
secureChannel, err := NewSecureChannel(i.c, cardKeyData) secureChannel, err := NewSecureChannel(i.c, cardKeyData)
if err != nil { if err != nil {
@ -91,8 +96,6 @@ func (i *Installer) Init() (*Secrets, error) {
return nil, err return nil, err
} }
fmt.Printf("RESP: %+v\n", resp)
return secrets, nil return secrets, nil
} }