Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

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

File tree

12 files changed

+158
-17
lines changed

12 files changed

+158
-17
lines changed

accounts/scwallet/hub.go

+2-2
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

+1
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

+1
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

+27
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

+10-5
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

-2
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

+35
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

+35
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

+35
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

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gballet/go-libpcsclite/winscard.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@
135135
"revisionTime": "2018-04-18T12:24:29Z"
136136
},
137137
{
138-
"checksumSHA1": "GXqHzd0XkPLX/iulpOncaxbxzZo=",
138+
"checksumSHA1": "+fiJGimxPPRSfi9sED4Lp6ytBeo=",
139139
"path": "github.com/gballet/go-libpcsclite",
140-
"revision": "312b5175032f98274685a4dd81935a92ad2412a5",
141-
"revisionTime": "2019-04-03T18:15:18Z"
140+
"revision": "2fd9b619dd3c5d74acbd975f997a6441984d74a7",
141+
"revisionTime": "2019-05-28T10:50:17Z"
142142
},
143143
{
144144
"checksumSHA1": "gxV/cPPLkByTdY8y172t7v4qcZA=",

0 commit comments

Comments
 (0)