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
This commit is contained in:
Guillaume Ballet 2019-04-18 11:27:07 +02:00
parent 0da1424e2f
commit d2ae535bb9

View file

@ -25,6 +25,7 @@ import (
"math/big" "math/big"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -127,9 +128,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{ SmartCardFlag = cli.StringFlag{
Name: "smartcard", Name: "pcscd-sock",
Usage: "Enables support for smartcard", Usage: "Path to the smartcard daemon (pcscd) socket file",
Value: "/run/pcscd/pcscd.comm",
} }
NetworkIdFlag = cli.Uint64Flag{ NetworkIdFlag = cli.Uint64Flag{
Name: "networkid", Name: "networkid",
@ -1128,6 +1130,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setWS(ctx, cfg) setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg) setNodeUserIdent(ctx, cfg)
setDataDir(ctx, cfg) setDataDir(ctx, cfg)
setSmartCard(ctx, cfg)
if ctx.GlobalIsSet(ExternalSignerFlag.Name) { if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
cfg.ExternalSigner = ctx.GlobalString(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) { 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)
} }
} }
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) { func setDataDir(ctx *cli.Context, cfg *node.Config) {
switch { switch {
case ctx.GlobalIsSet(DataDirFlag.Name): case ctx.GlobalIsSet(DataDirFlag.Name):