accounts/scwallet: use default path from pcsclite

This commit is contained in:
Guillaume Ballet 2019-05-28 13:22:44 +02:00
parent 3b73f1a6d9
commit b8a964dfcf
2 changed files with 11 additions and 21 deletions

View file

@ -25,7 +25,6 @@ import (
"math/big" "math/big"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -58,6 +57,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/netutil" "github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
pcsclite "github.com/gballet/go-libpcsclite"
cli "gopkg.in/urfave/cli.v1" cli "gopkg.in/urfave/cli.v1"
) )
@ -131,7 +131,7 @@ var (
SmartCardFlag = cli.StringFlag{ SmartCardFlag = cli.StringFlag{
Name: "pcscd-sock", Name: "pcscd-sock",
Usage: "Path to the smartcard daemon (pcscd) socket file (unix only, leave empty for platform default)", Usage: "Path to the smartcard daemon (pcscd) socket file (unix only, leave empty for platform default)",
Value: "", Value: pcsclite.PCSCDSockName,
} }
NetworkIdFlag = cli.Uint64Flag{ NetworkIdFlag = cli.Uint64Flag{
Name: "networkid", Name: "networkid",
@ -1151,24 +1151,17 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
} }
func setSmartCard(ctx *cli.Context, cfg *node.Config) { func setSmartCard(ctx *cli.Context, cfg *node.Config) {
// No support for windows, currently // Use the platform default unless specified on the command line
if runtime.GOOS != "windows" { if len(ctx.GlobalString(SmartCardFlag.Name)) > 0 {
cfg.SmartCard = true if fi, err := os.Stat(ctx.GlobalString(SmartCardFlag.Name)); err == nil {
if fi.Mode()&os.ModeType == os.ModeSocket {
// Use the platform default unless specified on the command line cfg.SmartCardDaemonPath = ctx.GlobalString(SmartCardFlag.Name)
if len(ctx.GlobalString(SmartCardFlag.Name)) > 0 {
if fi, err := os.Stat(ctx.GlobalString(SmartCardFlag.Name)); err == nil {
if fi.Mode()&os.ModeType == os.ModeSocket {
cfg.SmartCardDaemonPath = ctx.GlobalString(SmartCardFlag.Name)
} else {
log.Error(fmt.Sprintf("%s doesn't seem to be a socket file", ctx.GlobalString(SmartCardFlag.Name)))
}
} else { } else {
log.Error(fmt.Sprintf("%s doesn't exist", ctx.GlobalString(SmartCardFlag.Name))) log.Error(fmt.Sprintf("%s doesn't seem to be a socket file", ctx.GlobalString(SmartCardFlag.Name)))
} }
} else {
log.Error(fmt.Sprintf("%s doesn't exist", ctx.GlobalString(SmartCardFlag.Name)))
} }
} else {
log.Info("Smartcard support disabled on this platform")
} }
} }

View file

@ -95,9 +95,6 @@ type Config struct {
// NoUSB disables hardware wallet monitoring and connectivity. // NoUSB disables hardware wallet monitoring and connectivity.
NoUSB bool `toml:",omitempty"` NoUSB bool `toml:",omitempty"`
// SmartCard activates smartcard wallet monitoring and connectivity.
SmartCard bool `toml:",omitempty"`
// SmartCardDaemonPath is the path to the smartcard daemon's socket // SmartCardDaemonPath is the path to the smartcard daemon's socket
SmartCardDaemonPath string `toml:",omitempty"` SmartCardDaemonPath string `toml:",omitempty"`
@ -511,7 +508,7 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
backends = append(backends, trezorhub) backends = append(backends, trezorhub)
} }
} }
if conf.SmartCard { if len(conf.SmartCardDaemonPath) > 0 {
// Start a smart card hub // Start a smart card hub
if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil { if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil {
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err)) log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))