From d2ae535bb99d3cc71e5537936a98d3b53c63a03e Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Thu, 18 Apr 2019 11:27:07 +0200 Subject: [PATCH] accounts: change the meaning of the switch * disable card support in windows until tested * only activate account if pcscd socket file is present * the switch is now the path to the socket file --- cmd/utils/flags.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8da16d235b..d433e73bb2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -25,6 +25,7 @@ import ( "math/big" "os" "path/filepath" + "runtime" "strconv" "strings" "time" @@ -127,9 +128,10 @@ var ( Name: "nousb", Usage: "Disables monitoring for and managing USB hardware wallets", } - SmartCardFlag = cli.BoolTFlag{ - Name: "smartcard", - Usage: "Enables support for smartcard", + SmartCardFlag = cli.StringFlag{ + Name: "pcscd-sock", + Usage: "Path to the smartcard daemon (pcscd) socket file", + Value: "/run/pcscd/pcscd.comm", } NetworkIdFlag = cli.Uint64Flag{ Name: "networkid", @@ -1128,6 +1130,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { setWS(ctx, cfg) setNodeUserIdent(ctx, cfg) setDataDir(ctx, cfg) + setSmartCard(ctx, cfg) if ctx.GlobalIsSet(ExternalSignerFlag.Name) { cfg.ExternalSigner = ctx.GlobalString(ExternalSignerFlag.Name) @@ -1142,14 +1145,24 @@ 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) } } +func setSmartCard(ctx *cli.Context, cfg *node.Config) { + // No support for windows, currently + if runtime.GOOS != "windows" { + // Check for the existence of the PCSCD socket file. If it exists, then + // the smartcard wallet will be enabled. There might still be some issues + // e.g. when the daemon is not running. Those issues are meant to be + // caught at the daemon initialization level, though. + if fi, err := os.Stat(ctx.GlobalString(SmartCardFlag.Name)); err == nil { + cfg.SmartCard = fi.Mode()&os.ModeType == os.ModeSocket + } + } +} + func setDataDir(ctx *cli.Context, cfg *node.Config) { switch { case ctx.GlobalIsSet(DataDirFlag.Name):