forked from cerc-io/plugeth
more review feedback
This commit is contained in:
parent
d2daff4258
commit
fc3000d649
@ -36,6 +36,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -111,10 +112,11 @@ func (hub *Hub) readPairings() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hub *Hub) writePairings() error {
|
func (hub *Hub) writePairings() error {
|
||||||
pairingFile, err := os.OpenFile(filepath.Join(hub.datadir,"smartcards.json"), os.O_RDWR|os.O_CREATE, 0755)
|
pairingFile, err := os.OpenFile(filepath.Join(hub.datadir, "smartcards.json"), os.O_RDWR|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer pairingFile.Close()
|
||||||
|
|
||||||
pairings := make([]smartcardPairing, 0, len(hub.pairings))
|
pairings := make([]smartcardPairing, 0, len(hub.pairings))
|
||||||
for _, pairing := range hub.pairings {
|
for _, pairing := range hub.pairings {
|
||||||
@ -130,15 +132,11 @@ func (hub *Hub) writePairings() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairingFile.Close()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hub *Hub) pairing(wallet *Wallet) *smartcardPairing {
|
func (hub *Hub) pairing(wallet *Wallet) *smartcardPairing {
|
||||||
if pairing, ok := hub.pairings[string(wallet.PublicKey)]; ok{
|
if pairing, ok := hub.pairings[string(wallet.PublicKey)]; ok {
|
||||||
return &pairing
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
if ok {
|
|
||||||
return &pairing
|
return &pairing
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -209,6 +207,7 @@ func (hub *Hub) refreshWallets() {
|
|||||||
// want to fill the user's log with errors, so filter those out.
|
// want to fill the user's log with errors, so filter those out.
|
||||||
if err.Error() != "scard: Cannot find a smart card reader." {
|
if err.Error() != "scard: Cannot find a smart card reader." {
|
||||||
log.Error("Failed to enumerate smart card readers", "err", err)
|
log.Error("Failed to enumerate smart card readers", "err", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Transform the current list of wallets into the new one
|
// Transform the current list of wallets into the new one
|
||||||
|
@ -229,8 +229,8 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
meta := []byte{cla, ins, p1, p2, byte(len(data) + scBlockSize), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
meta := [16]byte{cla, ins, p1, p2, byte(len(data) + scBlockSize)}
|
||||||
if err = s.updateIV(meta, data); err != nil {
|
if err = s.updateIV(meta[:], data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rmeta := []byte{byte(len(response.Data)), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
rmeta := [16]byte{byte(len(response.Data))}
|
||||||
rmac := response.Data[:len(s.iv)]
|
rmac := response.Data[:len(s.iv)]
|
||||||
rdata := response.Data[len(s.iv):]
|
rdata := response.Data[len(s.iv):]
|
||||||
plainData, err := s.decryptAPDU(rdata)
|
plainData, err := s.decryptAPDU(rdata)
|
||||||
@ -257,7 +257,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.updateIV(rmeta, rdata); err != nil {
|
if err = s.updateIV(rmeta[:], rdata); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !bytes.Equal(s.iv, rmac) {
|
if !bytes.Equal(s.iv, rmac) {
|
||||||
|
Loading…
Reference in New Issue
Block a user