Skip to content

Commit

Permalink
go/oasis-node/cmd/node: Dynamically configure the signer backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Yawning committed Feb 21, 2020
1 parent 857b410 commit dd1d19d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go/oasis-node/cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions go/oasis-node/cmd/common/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 9 additions & 4 deletions go/oasis-node/cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-node/cmd/registry/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit dd1d19d

Please sign in to comment.