check if card scp version is supported

This commit is contained in:
Andrea Franz 2019-03-06 13:39:24 +01:00
parent 9648e01c71
commit 53e3def34c
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
1 changed files with 7 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import (
"github.com/status-im/keycard-go/globalplatform/crypto"
)
const supportedSCPVersion = 2
// Session is a struct containing the keys and challenges used in the current communication with a card.
type Session struct {
keys *SCP02Keys
@ -31,6 +33,11 @@ func NewSession(cardKeys *SCP02Keys, resp *apdu.Response, hostChallenge []byte)
return nil, apdu.NewErrBadResponse(resp.Sw, fmt.Sprintf("bad data length, expected 28, got %d", len(resp.Data)))
}
scpMajorVersion := resp.Data[11]
if scpMajorVersion != supportedSCPVersion {
return nil, fmt.Errorf("scp version %d not supported", scpMajorVersion)
}
cardChallenge := resp.Data[12:20]
cardCryptogram := resp.Data[20:28]
seq := resp.Data[12:14]