From 9a1230b2efff36077f95e77fc5989066db3c675a Mon Sep 17 00:00:00 2001 From: David Yan Date: Tue, 28 Jan 2020 15:13:28 -0800 Subject: [PATCH] Add changelog, move extract command outside of ledger --- .changelog/2609.feature.md | 5 ++++ go/oasis-node/cmd/signer/ledger/ledger.go | 34 ---------------------- go/oasis-node/cmd/signer/signer.go | 35 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 .changelog/2609.feature.md diff --git a/.changelog/2609.feature.md b/.changelog/2609.feature.md new file mode 100644 index 00000000000..dca21c7b81d --- /dev/null +++ b/.changelog/2609.feature.md @@ -0,0 +1,5 @@ +Extract Ledger entities + +We added a command to extract entities from existing signers, and a check to ensure +that the entity and signer public keys match. +This makes it so that a dummy entity cannot be used for signers backed by Ledger. diff --git a/go/oasis-node/cmd/signer/ledger/ledger.go b/go/oasis-node/cmd/signer/ledger/ledger.go index 9455ea9f288..15faf6e4fc5 100644 --- a/go/oasis-node/cmd/signer/ledger/ledger.go +++ b/go/oasis-node/cmd/signer/ledger/ledger.go @@ -2,14 +2,10 @@ package ledger import ( - "os" - "github.com/spf13/cobra" ledgerCommon "github.com/oasislabs/oasis-core/go/common/ledger" - "github.com/oasislabs/oasis-core/go/common/logging" cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common" - cmdFlags "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags" ) var ( @@ -23,14 +19,6 @@ var ( Short: "list available devices by address", Run: doLedgerList, } - - extractCmd = &cobra.Command{ - Use: "extract", - Short: "extract entity from device", - Run: doLedgerExtract, - } - - logger = logging.GetLogger("cmd/signer/ledger") ) func doLedgerList(cmd *cobra.Command, args []string) { @@ -40,34 +28,12 @@ func doLedgerList(cmd *cobra.Command, args []string) { ledgerCommon.ListDevices() } -func doLedgerExtract(cmd *cobra.Command, args []string) { - if err := cmdCommon.Init(); err != nil { - cmdCommon.EarlyLogAndExit(err) - } - entityDir, err := cmdFlags.SignerDirOrPwd() - if err != nil { - logger.Error("failed to retrieve signer dir", - "err", err, - ) - os.Exit(1) - } - if err := cmdCommon.ExtractEntity(cmdFlags.Signer(), entityDir); err != nil { - logger.Error("failed to extract entity", - "err", err, - ) - os.Exit(1) - } -} - func Register(parentCmd *cobra.Command) { for _, v := range []*cobra.Command{ listCmd, - extractCmd, } { ledgerCmd.AddCommand(v) } - extractCmd.Flags().AddFlagSet(cmdFlags.SignerFlags) - parentCmd.AddCommand(ledgerCmd) } diff --git a/go/oasis-node/cmd/signer/signer.go b/go/oasis-node/cmd/signer/signer.go index b97d4dcc0a5..6c70394b4b4 100644 --- a/go/oasis-node/cmd/signer/signer.go +++ b/go/oasis-node/cmd/signer/signer.go @@ -2,8 +2,13 @@ package signer import ( + "os" + "github.com/spf13/cobra" + "github.com/oasislabs/oasis-core/go/common/logging" + cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common" + cmdFlags "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/signer/ledger" ) @@ -12,8 +17,35 @@ var ( Use: "signer", Short: "signer backend utilities", } + + extractCmd = &cobra.Command{ + Use: "extract", + Short: "extract entity from signer", + Run: doEntityExtract, + } + + logger = logging.GetLogger("cmd/signer") ) +func doEntityExtract(cmd *cobra.Command, args []string) { + if err := cmdCommon.Init(); err != nil { + cmdCommon.EarlyLogAndExit(err) + } + entityDir, err := cmdFlags.SignerDirOrPwd() + if err != nil { + logger.Error("failed to retrieve signer dir", + "err", err, + ) + os.Exit(1) + } + if err := cmdCommon.ExtractEntity(cmdFlags.Signer(), entityDir); err != nil { + logger.Error("failed to extract entity", + "err", err, + ) + os.Exit(1) + } +} + func Register(parentCmd *cobra.Command) { for _, v := range []func(*cobra.Command){ ledger.Register, @@ -21,5 +53,8 @@ func Register(parentCmd *cobra.Command) { v(signerCmd) } + extractCmd.Flags().AddFlagSet(cmdFlags.SignerFlags) + + signerCmd.AddCommand(extractCmd) parentCmd.AddCommand(signerCmd) }