cmd/clef: enable smartcard hub (#19649)
* cmd/clef: Enable smartcard hub * clef: don't error is pcsc is not installed
This commit is contained in:
parent
7c9307c683
commit
b8ca3cb7d2
@ -194,6 +194,7 @@ func init() {
|
|||||||
chainIdFlag,
|
chainIdFlag,
|
||||||
utils.LightKDFFlag,
|
utils.LightKDFFlag,
|
||||||
utils.NoUSBFlag,
|
utils.NoUSBFlag,
|
||||||
|
utils.SmartCardDaemonPathFlag,
|
||||||
utils.RPCListenAddrFlag,
|
utils.RPCListenAddrFlag,
|
||||||
utils.RPCVirtualHostsFlag,
|
utils.RPCVirtualHostsFlag,
|
||||||
utils.IPCDisabledFlag,
|
utils.IPCDisabledFlag,
|
||||||
@ -419,10 +420,11 @@ func signer(c *cli.Context) error {
|
|||||||
lightKdf = c.GlobalBool(utils.LightKDFFlag.Name)
|
lightKdf = c.GlobalBool(utils.LightKDFFlag.Name)
|
||||||
advanced = c.GlobalBool(advancedMode.Name)
|
advanced = c.GlobalBool(advancedMode.Name)
|
||||||
nousb = c.GlobalBool(utils.NoUSBFlag.Name)
|
nousb = c.GlobalBool(utils.NoUSBFlag.Name)
|
||||||
|
scpath = c.GlobalString(utils.SmartCardDaemonPathFlag.Name)
|
||||||
)
|
)
|
||||||
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
|
log.Info("Starting signer", "chainid", chainId, "keystore", ksLoc,
|
||||||
"light-kdf", lightKdf, "advanced", advanced)
|
"light-kdf", lightKdf, "advanced", advanced)
|
||||||
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf)
|
am := core.StartClefAccountManager(ksLoc, nousb, lightKdf, scpath)
|
||||||
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)
|
apiImpl := core.NewSignerAPI(am, chainId, nousb, ui, db, advanced, pwStorage)
|
||||||
|
|
||||||
// Establish the bidirectional communication, by creating a new UI backend and registering
|
// Establish the bidirectional communication, by creating a new UI backend and registering
|
||||||
|
@ -22,11 +22,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
||||||
"github.com/ethereum/go-ethereum/accounts/usbwallet"
|
"github.com/ethereum/go-ethereum/accounts/usbwallet"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
@ -124,7 +126,7 @@ type Metadata struct {
|
|||||||
Origin string `json:"Origin"`
|
Origin string `json:"Origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool) *accounts.Manager {
|
func StartClefAccountManager(ksLocation string, nousb, lightKDF bool, scpath string) *accounts.Manager {
|
||||||
var (
|
var (
|
||||||
backends []accounts.Backend
|
backends []accounts.Backend
|
||||||
n, p = keystore.StandardScryptN, keystore.StandardScryptP
|
n, p = keystore.StandardScryptN, keystore.StandardScryptP
|
||||||
@ -159,6 +161,26 @@ func StartClefAccountManager(ksLocation string, nousb, lightKDF bool) *accounts.
|
|||||||
log.Debug("Trezor support enabled via WebUSB")
|
log.Debug("Trezor support enabled via WebUSB")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start a smart card hub
|
||||||
|
if len(scpath) > 0 {
|
||||||
|
// Sanity check that the smartcard path is valid
|
||||||
|
fi, err := os.Stat(scpath)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Smartcard socket file missing, disabling", "err", err)
|
||||||
|
} else {
|
||||||
|
if fi.Mode()&os.ModeType != os.ModeSocket {
|
||||||
|
log.Error("Invalid smartcard socket file type", "path", scpath, "type", fi.Mode().String())
|
||||||
|
} else {
|
||||||
|
if schub, err := scwallet.NewHub(scpath, scwallet.Scheme, ksLocation); err != nil {
|
||||||
|
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
|
||||||
|
} else {
|
||||||
|
backends = append(backends, schub)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clef doesn't allow insecure http account unlock.
|
// Clef doesn't allow insecure http account unlock.
|
||||||
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, backends...)
|
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, backends...)
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ func setup(t *testing.T) (*core.SignerAPI, *headlessUi) {
|
|||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
|
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
|
||||||
am := core.StartClefAccountManager(tmpDirName(t), true, true)
|
am := core.StartClefAccountManager(tmpDirName(t), true, true, "")
|
||||||
api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{})
|
api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{})
|
||||||
return api, ui
|
return api, ui
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user