accounts/scwallet: Add a switch to enable smartcard support

This commit is contained in:
Guillaume Ballet 2019-04-10 12:19:49 +02:00
parent f0b878d56d
commit 0da1424e2f
7 changed files with 27 additions and 10 deletions

View file

@ -64,6 +64,7 @@ var (
utils.KeyStoreDirFlag, utils.KeyStoreDirFlag,
utils.ExternalSignerFlag, utils.ExternalSignerFlag,
utils.NoUSBFlag, utils.NoUSBFlag,
utils.SmartCardFlag,
utils.DashboardEnabledFlag, utils.DashboardEnabledFlag,
utils.DashboardAddrFlag, utils.DashboardAddrFlag,
utils.DashboardPortFlag, utils.DashboardPortFlag,

View file

@ -71,6 +71,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.DataDirFlag, utils.DataDirFlag,
utils.KeyStoreDirFlag, utils.KeyStoreDirFlag,
utils.NoUSBFlag, utils.NoUSBFlag,
utils.SmartCardFlag,
utils.NetworkIdFlag, utils.NetworkIdFlag,
utils.TestnetFlag, utils.TestnetFlag,
utils.RinkebyFlag, utils.RinkebyFlag,

View file

@ -224,9 +224,10 @@ const testPassphrase = "swarm-test-passphrase"
func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) { func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) {
// create key // create key
conf = &node.Config{ conf = &node.Config{
DataDir: dir, DataDir: dir,
IPCPath: "bzzd.ipc", IPCPath: "bzzd.ipc",
NoUSB: true, NoUSB: true,
SmartCard: false,
} }
n, err := node.New(conf) n, err := node.New(conf)
if err != nil { if err != nil {

View file

@ -127,6 +127,10 @@ var (
Name: "nousb", Name: "nousb",
Usage: "Disables monitoring for and managing USB hardware wallets", Usage: "Disables monitoring for and managing USB hardware wallets",
} }
SmartCardFlag = cli.BoolTFlag{
Name: "smartcard",
Usage: "Enables support for smartcard",
}
NetworkIdFlag = cli.Uint64Flag{ NetworkIdFlag = cli.Uint64Flag{
Name: "networkid", Name: "networkid",
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)", 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) { if ctx.GlobalIsSet(NoUSBFlag.Name) {
cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name) cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name)
} }
if ctx.GlobalIsSet(SmartCardFlag.Name) {
cfg.SmartCard = ctx.GlobalBoolT(SmartCardFlag.Name)
}
if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) { if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) {
cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name) cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name)
} }

View file

@ -95,6 +95,9 @@ 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"`
// IPCPath is the requested location to place the IPC endpoint. If the path is // 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 // 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 // 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) backends = append(backends, trezorhub)
} }
} }
// Start a smart card hub if conf.SmartCard {
if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil { // Start a smart card hub
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err)) if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil {
} else { log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
backends = append(backends, schub) } else {
backends = append(backends, schub)
}
} }
} }

View file

@ -114,6 +114,7 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) {
conf.Stack.P2P.NoDiscovery = true conf.Stack.P2P.NoDiscovery = true
conf.Stack.P2P.NAT = nil conf.Stack.P2P.NAT = nil
conf.Stack.NoUSB = true conf.Stack.NoUSB = true
conf.Stack.SmartCard = false
// listen on a localhost port, which we set when we // listen on a localhost port, which we set when we
// initialise NodeConfig (usually a random port) // initialise NodeConfig (usually a random port)

View file

@ -105,8 +105,9 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) {
Dialer: s, Dialer: s,
EnableMsgEvents: config.EnableMsgEvents, EnableMsgEvents: config.EnableMsgEvents,
}, },
NoUSB: true, NoUSB: true,
Logger: log.New("node.id", id.String()), SmartCard: false,
Logger: log.New("node.id", id.String()),
}) })
if err != nil { if err != nil {
return nil, err return nil, err