From 0da1424e2ffe3a519f6294ce33ffd7d7a12c2651 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Wed, 10 Apr 2019 12:19:49 +0200 Subject: [PATCH] accounts/scwallet: Add a switch to enable smartcard support --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/swarm/run_test.go | 7 ++++--- cmd/utils/flags.go | 7 +++++++ node/config.go | 15 ++++++++++----- p2p/simulations/adapters/exec.go | 1 + p2p/simulations/adapters/inproc.go | 5 +++-- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 4f3849a41b..c9cc3564f9 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -64,6 +64,7 @@ var ( utils.KeyStoreDirFlag, utils.ExternalSignerFlag, utils.NoUSBFlag, + utils.SmartCardFlag, utils.DashboardEnabledFlag, utils.DashboardAddrFlag, utils.DashboardPortFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 7ec1ab03f5..ee5c13f13c 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -71,6 +71,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.DataDirFlag, utils.KeyStoreDirFlag, utils.NoUSBFlag, + utils.SmartCardFlag, utils.NetworkIdFlag, utils.TestnetFlag, utils.RinkebyFlag, diff --git a/cmd/swarm/run_test.go b/cmd/swarm/run_test.go index 9681c8990a..29c2f4149d 100644 --- a/cmd/swarm/run_test.go +++ b/cmd/swarm/run_test.go @@ -224,9 +224,10 @@ const testPassphrase = "swarm-test-passphrase" func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) { // create key conf = &node.Config{ - DataDir: dir, - IPCPath: "bzzd.ipc", - NoUSB: true, + DataDir: dir, + IPCPath: "bzzd.ipc", + NoUSB: true, + SmartCard: false, } n, err := node.New(conf) if err != nil { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f5f4cde5b4..8da16d235b 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -127,6 +127,10 @@ var ( Name: "nousb", Usage: "Disables monitoring for and managing USB hardware wallets", } + SmartCardFlag = cli.BoolTFlag{ + Name: "smartcard", + Usage: "Enables support for smartcard", + } NetworkIdFlag = cli.Uint64Flag{ Name: "networkid", Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)", @@ -1138,6 +1142,9 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { if ctx.GlobalIsSet(NoUSBFlag.Name) { cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name) } + if ctx.GlobalIsSet(SmartCardFlag.Name) { + cfg.SmartCard = ctx.GlobalBoolT(SmartCardFlag.Name) + } if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) { cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name) } diff --git a/node/config.go b/node/config.go index 244b15459c..55a8a05da0 100644 --- a/node/config.go +++ b/node/config.go @@ -95,6 +95,9 @@ type Config struct { // NoUSB disables hardware wallet monitoring and connectivity. NoUSB bool `toml:",omitempty"` + // SmartCard activates smartcard wallet monitoring and connectivity. + SmartCard bool `toml:",omitempty"` + // IPCPath is the requested location to place the IPC endpoint. If the path is // a simple file name, it is placed inside the data directory (or on the root // pipe path on Windows), whereas if it's a resolvable path name (absolute or @@ -505,11 +508,13 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) { backends = append(backends, trezorhub) } } - // Start a smart card hub - if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil { - log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err)) - } else { - backends = append(backends, schub) + if conf.SmartCard { + // Start a smart card hub + if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil { + log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err)) + } else { + backends = append(backends, schub) + } } } diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 106b179e43..bffbbaf5f4 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -114,6 +114,7 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) { conf.Stack.P2P.NoDiscovery = true conf.Stack.P2P.NAT = nil conf.Stack.NoUSB = true + conf.Stack.SmartCard = false // listen on a localhost port, which we set when we // initialise NodeConfig (usually a random port) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index c1cf23a175..715a40a8ba 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -105,8 +105,9 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) { Dialer: s, EnableMsgEvents: config.EnableMsgEvents, }, - NoUSB: true, - Logger: log.New("node.id", id.String()), + NoUSB: true, + SmartCard: false, + Logger: log.New("node.id", id.String()), }) if err != nil { return nil, err