remove unnecessary workarounds, fix secure channel
This commit is contained in:
parent
5e261398ed
commit
059bc140ce
|
@ -345,7 +345,7 @@ func NewCommandGetData(typ uint8) *apdu.Command {
|
||||||
InsGetData,
|
InsGetData,
|
||||||
typ,
|
typ,
|
||||||
0,
|
0,
|
||||||
[]byte{0xCA},
|
[]byte{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,18 +92,18 @@ func (sc *SecureChannel) Send(cmd *apdu.Command) (*apdu.Response, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sc.open {
|
||||||
if resp.Sw != globalplatform.SwOK {
|
if resp.Sw != globalplatform.SwOK {
|
||||||
return nil, apdu.NewErrBadResponse(resp.Sw, "unexpected sw in secure channel")
|
return nil, apdu.NewErrBadResponse(resp.Sw, "unexpected sw in secure channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
var plainData []byte
|
|
||||||
|
|
||||||
if sc.open {
|
|
||||||
rmeta := []byte{byte(len(resp.Data)), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
rmeta := []byte{byte(len(resp.Data)), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
rmac := resp.Data[:len(sc.iv)]
|
rmac := resp.Data[:len(sc.iv)]
|
||||||
rdata := resp.Data[len(sc.iv):]
|
rdata := resp.Data[len(sc.iv):]
|
||||||
|
|
||||||
if plainData, err = crypto.DecryptData(rdata, sc.encKey, sc.iv); err != nil {
|
plainData, err := crypto.DecryptData(rdata, sc.encKey, sc.iv)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,11 +116,11 @@ func (sc *SecureChannel) Send(cmd *apdu.Command) (*apdu.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug("apdu response decrypted", "hex", hexutils.BytesToHexWithSpaces(plainData))
|
logger.Debug("apdu response decrypted", "hex", hexutils.BytesToHexWithSpaces(plainData))
|
||||||
|
return apdu.ParseResponse(plainData)
|
||||||
} else {
|
} else {
|
||||||
plainData = resp.Data
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return apdu.ParseResponse(plainData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SecureChannel) updateIV(meta, data []byte) error {
|
func (sc *SecureChannel) updateIV(meta, data []byte) error {
|
||||||
|
|
Loading…
Reference in New Issue