From dd1d19d727f24f276b4eba60d682741ce84c8dc7 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Thu, 20 Feb 2020 14:58:07 +0000 Subject: [PATCH] go/oasis-node/cmd/node: Dynamically configure the signer backend --- go/oasis-node/cmd/common/common.go | 4 ++-- go/oasis-node/cmd/common/signer/signer.go | 6 +++--- go/oasis-node/cmd/node/node.go | 13 +++++++++---- go/oasis-node/cmd/registry/entity/entity.go | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/go/oasis-node/cmd/common/common.go b/go/oasis-node/cmd/common/common.go index d37938770eb..6ad5f1d5ad9 100644 --- a/go/oasis-node/cmd/common/common.go +++ b/go/oasis-node/cmd/common/common.go @@ -253,7 +253,7 @@ func LoadEntity(signerBackend string, entityDir string) (*entity.Entity, signatu return entity.TestEntity() } - factory, err := cmdSigner.NewFactory(signerBackend, entityDir) + factory, err := cmdSigner.NewFactory(signerBackend, entityDir, signature.SignerEntity) if err != nil { return nil, nil, err } @@ -264,7 +264,7 @@ func LoadEntity(signerBackend string, entityDir string) (*entity.Entity, signatu // ExportEntity creates an empty entity from the public key of the signer // generated with the specified backend, and writes it to a file in entityDir. func ExportEntity(signerBackend string, entityDir string) error { - factory, err := cmdSigner.NewFactory(signerBackend, entityDir) + factory, err := cmdSigner.NewFactory(signerBackend, entityDir, signature.SignerEntity) if err != nil { return err } diff --git a/go/oasis-node/cmd/common/signer/signer.go b/go/oasis-node/cmd/common/signer/signer.go index 907ee8bd9bd..f2317270389 100644 --- a/go/oasis-node/cmd/common/signer/signer.go +++ b/go/oasis-node/cmd/common/signer/signer.go @@ -54,16 +54,16 @@ func LedgerIndex() uint32 { } // NewFactory returns the appropriate SignerFactory based on flags. -func NewFactory(signerBackend string, signerDir string) (signature.SignerFactory, error) { +func NewFactory(signerBackend string, signerDir string, roles ...signature.SignerRole) (signature.SignerFactory, error) { switch signerBackend { case ledgerSigner.SignerName: config := ledgerSigner.FactoryConfig{ Address: LedgerAddress(), Index: LedgerIndex(), } - return ledgerSigner.NewFactory(&config, signature.SignerEntity), nil + return ledgerSigner.NewFactory(&config, roles...), nil case fileSigner.SignerName: - return fileSigner.NewFactory(signerDir, signature.SignerEntity), nil + return fileSigner.NewFactory(signerDir, roles...), nil default: return nil, fmt.Errorf("unsupported signer backend: %s", signerBackend) } diff --git a/go/oasis-node/cmd/node/node.go b/go/oasis-node/cmd/node/node.go index e0a2ff61804..7fe3eb719d8 100644 --- a/go/oasis-node/cmd/node/node.go +++ b/go/oasis-node/cmd/node/node.go @@ -15,7 +15,6 @@ import ( "github.com/oasislabs/oasis-core/go/common" "github.com/oasislabs/oasis-core/go/common/crash" "github.com/oasislabs/oasis-core/go/common/crypto/signature" - fileSigner "github.com/oasislabs/oasis-core/go/common/crypto/signature/signers/file" "github.com/oasislabs/oasis-core/go/common/grpc" "github.com/oasislabs/oasis-core/go/common/identity" "github.com/oasislabs/oasis-core/go/common/logging" @@ -40,6 +39,7 @@ import ( cmdGrpc "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/grpc" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/metrics" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/pprof" + cmdSigner "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/signer" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/tracing" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/debug/supplementarysanity" registryAPI "github.com/oasislabs/oasis-core/go/registry/api" @@ -462,7 +462,7 @@ func NewTestNode() (*Node, error) { return newNode(true) } -func newNode(testNode bool) (*Node, error) { +func newNode(testNode bool) (*Node, error) { // nolint: gocyclo logger := cmdCommon.Logger() node := &Node{ @@ -519,8 +519,13 @@ func newNode(testNode bool) (*Node, error) { } // Generate/Load the node identity. - // TODO/hsm: Configure factory dynamically. - signerFactory := fileSigner.NewFactory(dataDir, signature.SignerNode, signature.SignerP2P, signature.SignerConsensus) + signerFactory, err := cmdSigner.NewFactory(cmdSigner.Backend(), dataDir, signature.SignerNode, signature.SignerP2P, signature.SignerConsensus) + if err != nil { + logger.Error("failed to initialize signer backend", + "err", err, + ) + return nil, err + } node.Identity, err = identity.LoadOrGenerate(dataDir, signerFactory) if err != nil { logger.Error("failed to load/generate identity", diff --git a/go/oasis-node/cmd/registry/entity/entity.go b/go/oasis-node/cmd/registry/entity/entity.go index 0acfe84b9ad..ad96552606e 100644 --- a/go/oasis-node/cmd/registry/entity/entity.go +++ b/go/oasis-node/cmd/registry/entity/entity.go @@ -367,7 +367,7 @@ func loadOrGenerateEntity(dataDir string, generate bool) (*entity.Entity, signat ) os.Exit(1) } - entitySignerFactory, err := cmdSigner.NewFactory(cmdSigner.Backend(), entityDir) + entitySignerFactory, err := cmdSigner.NewFactory(cmdSigner.Backend(), entityDir, signature.SignerEntity) if err != nil { return nil, nil, err }