Skip to content

Commit

Permalink
Merge pull request #263 from evanlinjin/feature/visor-gen-config-sk-flag
Browse files Browse the repository at this point in the history
Added --secret-key,-s flag to gen-config.
  • Loading branch information
志宇 authored Mar 27, 2020
2 parents a6dab23 + a183cfe commit 4f4e4fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/skywire-cli/commands/visor/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
}

var (
sk cipher.SecKey
output string
replace bool
retainKeys bool
Expand All @@ -32,6 +33,7 @@ var (
)

func init() {
genConfigCmd.Flags().VarP(&sk, "secret-key", "s", "if unspecified, a random key pair will be generated.")
genConfigCmd.Flags().StringVarP(&output, "output", "o", "", "path of output config file. Uses default of 'type' flag if unspecified.")
genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "whether to allow rewrite of a file that already exists.")
genConfigCmd.Flags().BoolVar(&retainKeys, "retain-keys", false, "retain current keys")
Expand Down Expand Up @@ -107,7 +109,11 @@ func localConfig() *visor.Config {
func defaultConfig() *visor.Config {
conf := &visor.Config{}

conf.KeyPair = visor.NewKeyPair()
if sk.Null() {
conf.KeyPair = visor.NewKeyPair()
} else {
conf.KeyPair = visor.RestoreKeyPair(sk)
}

stcp, err := visor.DefaultSTCPConfig()
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/visor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ func NewKeyPair() *KeyPair {
}
}

// RestoreKeyPair generates a key pair using just the secret key.
func RestoreKeyPair(sk cipher.SecKey) *KeyPair {
pk, err := sk.PubKey()
if err != nil {
panic(fmt.Errorf("failed to restore key pair: %v", err))
}
return &KeyPair{PubKey: pk, SecKey: sk}
}

// DefaultSTCPConfig returns default STCP config.
func DefaultSTCPConfig() (*snet.STCPConfig, error) {
lIPaddr, err := getLocalIPAddress()
Expand Down

0 comments on commit 4f4e4fb

Please sign in to comment.