use SCP02Keys instead of KeyProvider

This commit is contained in:
Andrea Franz 2019-03-06 10:43:37 +01:00
parent 6e8ec0271b
commit 53689712e6
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
3 changed files with 10 additions and 10 deletions

View File

@ -178,14 +178,14 @@ func (i *Initializer) initializeUpdate() (*globalplatform.Session, error) {
}
// verify cryptogram and initialize session keys
keys := globalplatform.NewKeyProvider(lightwallet.CardTestKey, lightwallet.CardTestKey)
keys := globalplatform.NewSCP02Keys(lightwallet.CardTestKey, lightwallet.CardTestKey)
session, err := globalplatform.NewSession(keys, resp, hostChallenge)
return session, err
}
func (i *Initializer) externalAuthenticate(session *globalplatform.Session) error {
encKey := session.KeyProvider().Enc()
encKey := session.Keys().Enc()
extAuth, err := globalplatform.NewCommandExternalAuthenticate(encKey, session.CardChallenge(), session.HostChallenge())
if err != nil {
return err

View File

@ -17,7 +17,7 @@ func NewSecureChannel(session *Session, c Channel) *SecureChannel {
return &SecureChannel{
session: session,
c: c,
w: NewSCP02Wrapper(session.KeyProvider().Mac()),
w: NewSCP02Wrapper(session.Keys().Mac()),
}
}

View File

@ -10,7 +10,7 @@ import (
// Session is a struct containing the keys and challenges used in the current communication with a card.
type Session struct {
keyProvider *KeyProvider
keys *SCP02Keys
cardChallenge []byte
hostChallenge []byte
}
@ -18,7 +18,7 @@ type Session struct {
var errBadCryptogram = errors.New("bad card cryptogram")
// NewSession returns a new session after validating the cryptogram received from the card.
func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte) (*Session, error) {
func NewSession(cardKeys *SCP02Keys, resp *apdu.Response, hostChallenge []byte) (*Session, error) {
if resp.Sw == SwSecurityConditionNotSatisfied {
return nil, apdu.NewErrBadResponse(resp.Sw, "security condition not satisfied")
}
@ -45,7 +45,7 @@ func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte
return nil, err
}
sessionKeys := NewKeyProvider(sessionEncKey, sessionMacKey)
sessionKeys := NewSCP02Keys(sessionEncKey, sessionMacKey)
verified, err := crypto.VerifyCryptogram(sessionKeys.Enc(), hostChallenge, cardChallenge, cardCryptogram)
if err != nil {
return nil, err
@ -56,7 +56,7 @@ func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte
}
s := &Session{
keyProvider: sessionKeys,
keys: sessionKeys,
cardChallenge: cardChallenge,
hostChallenge: hostChallenge,
}
@ -64,9 +64,9 @@ func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte
return s, nil
}
// KeyProvider return the current KeyProvider.
func (s *Session) KeyProvider() *KeyProvider {
return s.keyProvider
// Keys return the current SCP02Keys.
func (s *Session) Keys() *SCP02Keys {
return s.keys
}
// CardChallenge returns the current card challenge.