Skip to content

Commit

Permalink
Merge pull request #42 from TRON-US/v0.5.3
Browse files Browse the repository at this point in the history
BTFS-1971 Ensure config show and config set cannot read or change user wallet credentials
  • Loading branch information
Eric Chen authored May 18, 2020
2 parents 6ffd94c + 423d03d commit 254b8fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import (

const IdentityTag = "Identity"
const PrivKeyTag = "PrivKey"
const MnemonicTag = "Mnemonic"
const Password = "Password"
const PrivKeySelector = IdentityTag + "." + PrivKeyTag
const MnemonicSelector = IdentityTag + "." + MnemonicTag
const PasswordSelector = IdentityTag + "." + Password

// Identity tracks the configuration of the local node's identity.
type Identity struct {
PeerID string
PrivKey string `json:",omitempty"`
PeerID string
PrivKey string `json:",omitempty"`
Mnemonic string `json:",omitempty"`
Password string `json:",omitempty"`
}

// DecodePrivateKey is a helper to decode the users PrivateKey
Expand Down
7 changes: 4 additions & 3 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
peer "github.com/libp2p/go-libp2p-core/peer"
)

func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, rmOnUnpin bool) (*Config, error) {
identity, err := identityConfig(out, nBitsForKeypair, keyType, importKey)
func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string, mnemonic string, rmOnUnpin bool) (*Config, error) {
identity, err := identityConfig(out, nBitsForKeypair, keyType, importKey, mnemonic)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func DefaultServicesConfigTestnet() Services {
}

// identityConfig initializes a new identity.
func identityConfig(out io.Writer, nbits int, keyType string, importKey string) (Identity, error) {
func identityConfig(out io.Writer, nbits int, keyType string, importKey string, mnemonic string) (Identity, error) {
// TODO guard higher up
ident := Identity{}

Expand Down Expand Up @@ -298,6 +298,7 @@ func identityConfig(out io.Writer, nbits int, keyType string, importKey string)
return ident, err
}
ident.PrivKey = base64.StdEncoding.EncodeToString(skbytes)
ident.Mnemonic = mnemonic

id, err := peer.IDFromPublicKey(pk)
if err != nil {
Expand Down

0 comments on commit 254b8fb

Please sign in to comment.