Skip to content

Commit 7a22da9

Browse files
gballetkaralabe
authored andcommitted
accounts/scwallet: flag to specify path to smartcard daemon (#19439)
* accounts/scwallet: Add a switch to enable smartcard support * 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 * accounts/scwallet: holiman's review feedback * accounts/scwallet: send the path to go-pcsclite * accounts/scwallet: add default, per platform path * accounts/scwallet: fix error log warning * accounts/scwallet: update pcsc lib to latest * accounts/scwallet: use default path from pcsclite * scwallet: forgot to change switch name * cmd: minor style cleanups (error handling first, then happy path)
1 parent 30263ad commit 7a22da9

12 files changed

Lines changed: 158 additions & 17 deletions

File tree

‎accounts/scwallet/hub.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func (hub *Hub) setPairing(wallet *Wallet, pairing *smartcardPairing) error {
152152
}
153153

154154
// NewHub creates a new hardware wallet manager for smartcards.
155-
func NewHub(scheme string, datadir string) (*Hub, error) {
156-
context, err := pcsc.EstablishContext(pcsc.ScopeSystem)
155+
func NewHub(daemonPath string, scheme string, datadir string) (*Hub, error) {
156+
context, err := pcsc.EstablishContext(daemonPath, pcsc.ScopeSystem)
157157
if err != nil {
158158
return nil, err
159159
}

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
utils.KeyStoreDirFlag,
6767
utils.ExternalSignerFlag,
6868
utils.NoUSBFlag,
69+
utils.SmartCardDaemonPathFlag,
6970
utils.DashboardEnabledFlag,
7071
utils.DashboardAddrFlag,
7172
utils.DashboardPortFlag,

‎cmd/geth/usage.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var AppHelpFlagGroups = []flagGroup{
7272
utils.AncientFlag,
7373
utils.KeyStoreDirFlag,
7474
utils.NoUSBFlag,
75+
utils.SmartCardDaemonPathFlag,
7576
utils.NetworkIdFlag,
7677
utils.TestnetFlag,
7778
utils.RinkebyFlag,

‎cmd/utils/flags.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import (
5858
"github.com/ethereum/go-ethereum/p2p/netutil"
5959
"github.com/ethereum/go-ethereum/params"
6060
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
61+
pcsclite "github.com/gballet/go-libpcsclite"
6162
cli "gopkg.in/urfave/cli.v1"
6263
)
6364

@@ -129,6 +130,11 @@ var (
129130
Name: "nousb",
130131
Usage: "Disables monitoring for and managing USB hardware wallets",
131132
}
133+
SmartCardDaemonPathFlag = cli.StringFlag{
134+
Name: "pcscdpath",
135+
Usage: "Path to the smartcard daemon (pcscd) socket file",
136+
Value: pcsclite.PCSCDSockName,
137+
}
132138
NetworkIdFlag = cli.Uint64Flag{
133139
Name: "networkid",
134140
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)",
@@ -1126,6 +1132,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
11261132
setWS(ctx, cfg)
11271133
setNodeUserIdent(ctx, cfg)
11281134
setDataDir(ctx, cfg)
1135+
setSmartCard(ctx, cfg)
11291136

11301137
if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
11311138
cfg.ExternalSigner = ctx.GlobalString(ExternalSignerFlag.Name)
@@ -1145,6 +1152,26 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
11451152
}
11461153
}
11471154

1155+
func setSmartCard(ctx *cli.Context, cfg *node.Config) {
1156+
// Skip enabling smartcards if no path is set
1157+
path := ctx.GlobalString(SmartCardDaemonPathFlag.Name)
1158+
if path == "" {
1159+
return
1160+
}
1161+
// Sanity check that the smartcard path is valid
1162+
fi, err := os.Stat(path)
1163+
if err != nil {
1164+
log.Error("Failed to verify smartcard daemon path", "path", path, "err", err)
1165+
return
1166+
}
1167+
if fi.Mode()&os.ModeType != os.ModeSocket {
1168+
log.Error("Invalid smartcard daemon path", "path", path, "type", fi.Mode().String())
1169+
return
1170+
}
1171+
// Smartcard daemon path exists and is a socket, enable it
1172+
cfg.SmartCardDaemonPath = path
1173+
}
1174+
11481175
func setDataDir(ctx *cli.Context, cfg *node.Config) {
11491176
switch {
11501177
case ctx.GlobalIsSet(DataDirFlag.Name):

‎node/config.go‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ type Config struct {
9595
// NoUSB disables hardware wallet monitoring and connectivity.
9696
NoUSB bool `toml:",omitempty"`
9797

98+
// SmartCardDaemonPath is the path to the smartcard daemon's socket
99+
SmartCardDaemonPath string `toml:",omitempty"`
100+
98101
// IPCPath is the requested location to place the IPC endpoint. If the path is
99102
// a simple file name, it is placed inside the data directory (or on the root
100103
// 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) {
505508
backends = append(backends, trezorhub)
506509
}
507510
}
508-
// Start a smart card hub
509-
if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil {
510-
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
511-
} else {
512-
backends = append(backends, schub)
511+
if len(conf.SmartCardDaemonPath) > 0 {
512+
// Start a smart card hub
513+
if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil {
514+
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
515+
} else {
516+
backends = append(backends, schub)
517+
}
513518
}
514519
}
515520

‎vendor/github.com/gballet/go-libpcsclite/doc.go‎

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gballet/go-libpcsclite/doc_bsd.go‎

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gballet/go-libpcsclite/doc_linux.go‎

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gballet/go-libpcsclite/doc_windows.go‎

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gballet/go-libpcsclite/msg.go‎

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)