use SCP02Keys instead of KeyProvider
This commit is contained in:
parent
6e8ec0271b
commit
53689712e6
|
@ -178,14 +178,14 @@ func (i *Initializer) initializeUpdate() (*globalplatform.Session, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify cryptogram and initialize session keys
|
// 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)
|
session, err := globalplatform.NewSession(keys, resp, hostChallenge)
|
||||||
|
|
||||||
return session, err
|
return session, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Initializer) externalAuthenticate(session *globalplatform.Session) error {
|
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())
|
extAuth, err := globalplatform.NewCommandExternalAuthenticate(encKey, session.CardChallenge(), session.HostChallenge())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewSecureChannel(session *Session, c Channel) *SecureChannel {
|
||||||
return &SecureChannel{
|
return &SecureChannel{
|
||||||
session: session,
|
session: session,
|
||||||
c: c,
|
c: c,
|
||||||
w: NewSCP02Wrapper(session.KeyProvider().Mac()),
|
w: NewSCP02Wrapper(session.Keys().Mac()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// Session is a struct containing the keys and challenges used in the current communication with a card.
|
// Session is a struct containing the keys and challenges used in the current communication with a card.
|
||||||
type Session struct {
|
type Session struct {
|
||||||
keyProvider *KeyProvider
|
keys *SCP02Keys
|
||||||
cardChallenge []byte
|
cardChallenge []byte
|
||||||
hostChallenge []byte
|
hostChallenge []byte
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ type Session struct {
|
||||||
var errBadCryptogram = errors.New("bad card cryptogram")
|
var errBadCryptogram = errors.New("bad card cryptogram")
|
||||||
|
|
||||||
// NewSession returns a new session after validating the cryptogram received from the card.
|
// 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 {
|
if resp.Sw == SwSecurityConditionNotSatisfied {
|
||||||
return nil, apdu.NewErrBadResponse(resp.Sw, "security condition not satisfied")
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionKeys := NewKeyProvider(sessionEncKey, sessionMacKey)
|
sessionKeys := NewSCP02Keys(sessionEncKey, sessionMacKey)
|
||||||
verified, err := crypto.VerifyCryptogram(sessionKeys.Enc(), hostChallenge, cardChallenge, cardCryptogram)
|
verified, err := crypto.VerifyCryptogram(sessionKeys.Enc(), hostChallenge, cardChallenge, cardCryptogram)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -56,7 +56,7 @@ func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &Session{
|
s := &Session{
|
||||||
keyProvider: sessionKeys,
|
keys: sessionKeys,
|
||||||
cardChallenge: cardChallenge,
|
cardChallenge: cardChallenge,
|
||||||
hostChallenge: hostChallenge,
|
hostChallenge: hostChallenge,
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ func NewSession(cardKeys *KeyProvider, resp *apdu.Response, hostChallenge []byte
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyProvider return the current KeyProvider.
|
// Keys return the current SCP02Keys.
|
||||||
func (s *Session) KeyProvider() *KeyProvider {
|
func (s *Session) Keys() *SCP02Keys {
|
||||||
return s.keyProvider
|
return s.keys
|
||||||
}
|
}
|
||||||
|
|
||||||
// CardChallenge returns the current card challenge.
|
// CardChallenge returns the current card challenge.
|
||||||
|
|
Loading…
Reference in New Issue