Skip to content

Commit b8ca3cb

Browse files
gballetholiman
authored andcommitted
cmd/clef: enable smartcard hub (#19649)
* cmd/clef: Enable smartcard hub * clef: don't error is pcsc is not installed
1 parent 7c9307c commit b8ca3cb

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎cmd/clef/main.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func init() {
194194
chainIdFlag,
195195
utils.LightKDFFlag,
196196
utils.NoUSBFlag,
197+
utils.SmartCardDaemonPathFlag,
197198
utils.RPCListenAddrFlag,
198199
utils.RPCVirtualHostsFlag,
199200
utils.IPCDisabledFlag,
@@ -419,10 +420,11 @@ func signer(c *cli.Context) error {
419420
lightKdf = c.GlobalBool(utils.LightKDFFlag.Name)
420421
advanced = c.GlobalBool(advancedMode.Name)
421422
nousb = c.GlobalBool(utils.NoUSBFlag.Name)
423+
scpath = c.GlobalString(utils.SmartCardDaemonPathFlag.Name)
422424
)
423425
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
424426
"light-kdf", lightKdf, "advanced", advanced)
425-
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf)
427+
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf, scpath)
426428
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)
427429

428430
// Establish the bidirectional communication, by creating a new UI backend and registering

‎signer/core/api.go‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"errors"
2323
"fmt"
2424
"math/big"
25+
"os"
2526
"reflect"
2627
"strings"
2728

2829
"github.com/ethereum/go-ethereum/accounts"
2930
"github.com/ethereum/go-ethereum/accounts/keystore"
31+
"github.com/ethereum/go-ethereum/accounts/scwallet"
3032
"github.com/ethereum/go-ethereum/accounts/usbwallet"
3133
"github.com/ethereum/go-ethereum/common"
3234
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -124,7 +126,7 @@ type Metadata struct {
124126
Origin string `json:"Origin"`
125127
}
126128

127-
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool) *accounts.Manager {
129+
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath string) *accounts.Manager {
128130
var (
129131
backends []accounts.Backend
130132
n, p = keystore.StandardScryptN, keystore.StandardScryptP
@@ -159,6 +161,26 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool) *accounts.
159161
log.Debug("Trezor support enabled via WebUSB")
160162
}
161163
}
164+
165+
// Start a smart card hub
166+
if len(scpath) > 0 {
167+
// Sanity check that the smartcard path is valid
168+
fi, err := os.Stat(scpath)
169+
if err != nil {
170+
log.Info("Smartcard socket file missing, disabling", "err", err)
171+
} else {
172+
if fi.Mode()&os.ModeType != os.ModeSocket {
173+
log.Error("Invalid smartcard socket file type", "path", scpath, "type", fi.Mode().String())
174+
} else {
175+
if schub, err := scwallet.NewHub(scpath, scwallet.Scheme, ksLocation); err != nil {
176+
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
177+
} else {
178+
backends = append(backends, schub)
179+
}
180+
}
181+
}
182+
}
183+
162184
// Clef doesn't allow insecure http account unlock.
163185
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, backends...)
164186
}

‎signer/core/api_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func setup(t *testing.T) (*core.SignerAPI, *headlessUi) {
125125
t.Fatal(err.Error())
126126
}
127127
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
128-
am := core.StartClefAccountManager(tmpDirName(t), true, true)
128+
am := core.StartClefAccountManager(tmpDirName(t), true, true, "")
129129
api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{})
130130
return api, ui
131131

0 commit comments

Comments
 (0)