aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/scwallet
diff options
context:
space:
mode:
authorGuillaume Ballet <gballet@gmail.com>2019-04-05 02:06:40 +0800
committerGuillaume Ballet <gballet@gmail.com>2019-04-08 19:21:22 +0800
commitfc3000d649d8df77d21b2dc297f069715e08f5eb (patch)
tree05a9495761da74f3135f47956f67915019ecbc4d /accounts/scwallet
parentd2daff4258a66b8d0e1904095b5ebaffcb46c49e (diff)
downloadgo-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar.gz
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar.bz2
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar.lz
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar.xz
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.tar.zst
go-tangerine-fc3000d649d8df77d21b2dc297f069715e08f5eb.zip
more review feedback
Diffstat (limited to 'accounts/scwallet')
-rw-r--r--accounts/scwallet/hub.go13
-rw-r--r--accounts/scwallet/securechannel.go8
2 files changed, 10 insertions, 11 deletions
diff --git a/accounts/scwallet/hub.go b/accounts/scwallet/hub.go
index 475305101..c259f711f 100644
--- a/accounts/scwallet/hub.go
+++ b/accounts/scwallet/hub.go
@@ -36,6 +36,7 @@ import (
"encoding/json"
"io/ioutil"
"os"
+ "path/filepath"
"sort"
"sync"
"time"
@@ -111,10 +112,11 @@ func (hub *Hub) readPairings() 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 {
return err
}
+ defer pairingFile.Close()
pairings := make([]smartcardPairing, 0, len(hub.pairings))
for _, pairing := range hub.pairings {
@@ -130,15 +132,11 @@ func (hub *Hub) writePairings() error {
return err
}
- return pairingFile.Close()
+ return nil
}
func (hub *Hub) pairing(wallet *Wallet) *smartcardPairing {
- if pairing, ok := hub.pairings[string(wallet.PublicKey)]; ok{
- return &pairing
- }
- return nil
- if ok {
+ if pairing, ok := hub.pairings[string(wallet.PublicKey)]; ok {
return &pairing
}
return nil
@@ -209,6 +207,7 @@ func (hub *Hub) refreshWallets() {
// want to fill the user's log with errors, so filter those out.
if err.Error() != "scard: Cannot find a smart card reader." {
log.Error("Failed to enumerate smart card readers", "err", err)
+ return
}
}
// Transform the current list of wallets into the new one
diff --git a/accounts/scwallet/securechannel.go b/accounts/scwallet/securechannel.go
index 3c9732198..fad876a01 100644
--- a/accounts/scwallet/securechannel.go
+++ b/accounts/scwallet/securechannel.go
@@ -229,8 +229,8 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
if err != nil {
return nil, err
}
- meta := []byte{cla, ins, p1, p2, byte(len(data) + scBlockSize), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- if err = s.updateIV(meta, data); err != nil {
+ meta := [16]byte{cla, ins, p1, p2, byte(len(data) + scBlockSize)}
+ if err = s.updateIV(meta[:], data); err != nil {
return nil, err
}
@@ -249,7 +249,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
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)]
rdata := response.Data[len(s.iv):]
plainData, err := s.decryptAPDU(rdata)
@@ -257,7 +257,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
return nil, err
}
- if err = s.updateIV(rmeta, rdata); err != nil {
+ if err = s.updateIV(rmeta[:], rdata); err != nil {
return nil, err
}
if !bytes.Equal(s.iv, rmac) {