Merge pull request #887 from LeoHChen/wallet_fix_empty_passphrase

Wallet fix empty passphrase
pull/862/head
Leo Chen 6 years ago committed by GitHub
commit 9dcb3d740b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 65
      cmd/client/wallet/main.go
  2. 6
      cmd/harmony/main.go
  3. 12
      scripts/go_executable_build.sh

@ -63,7 +63,10 @@ var (
// List subcommands
listCommand = flag.NewFlagSet("list", flag.ExitOnError)
listCommandNoPassPtr = listCommand.Bool("nopass", false, "The account has no pass phrase")
// Export subcommands
exportCommand = flag.NewFlagSet("export", flag.ExitOnError)
exportCommandAccountPtr = exportCommand.String("account", "", "The account to be exported")
// Account subcommands
accountImportCommand = flag.NewFlagSet("import", flag.ExitOnError)
@ -116,7 +119,6 @@ func main() {
fmt.Println(" 1. new - Generates a new account and store the private key locally")
fmt.Println(" --nopass - The private key has no passphrase (for test only)")
fmt.Println(" 2. list - Lists all accounts in local keystore")
fmt.Println(" --nopass - The private key has no passphrase (for test only)")
fmt.Println(" 3. removeAll - Removes all accounts in local keystore")
fmt.Println(" 4. import - Imports a new account by private key")
fmt.Println(" --pass - The passphrase of the private key to import")
@ -132,6 +134,8 @@ func main() {
fmt.Println(" --shardID - The shard Id for the transfer")
fmt.Println(" --inputData - Base64-encoded input data to embed in the transaction")
fmt.Println(" --pass - Passphrase of sender's private key")
fmt.Println(" 8. export - Export account key to a new file")
fmt.Println(" --account - Specify the account to export. Empty will export every key.")
os.Exit(1)
}
@ -173,6 +177,8 @@ ARG:
processNewCommnad()
case "list":
processListCommand()
case "export":
processExportCommand()
case "removeAll":
clearKeystore()
case "import":
@ -248,7 +254,7 @@ func processNewCommnad() {
password := ""
if !noPass {
password := utils.AskForPassphrase("Passphrase: ")
password = utils.AskForPassphrase("Passphrase: ")
password2 := utils.AskForPassphrase("Passphrase again: ")
if password != password2 {
fmt.Printf("Passphrase doesn't match. Please try again!\n")
@ -264,23 +270,16 @@ func processNewCommnad() {
fmt.Printf("URL: %s\n", account.URL)
}
func processListCommand() {
listCommand.Parse(os.Args[2:])
noPass := *listCommandNoPassPtr
allAccounts := ks.Accounts()
for _, account := range allAccounts {
func _exportAccount(account accounts.Account) {
fmt.Printf("account: %s\n", account.Address.Hex())
fmt.Printf("URL: %s\n", account.URL)
password := ""
newpass := ""
if !noPass {
password = utils.AskForPassphrase("Passphrase: ")
newpass = utils.AskForPassphrase("Export Passphrase: ")
}
data, err := ks.Export(account, password, newpass)
pass := utils.AskForPassphrase("Original Passphrase: ")
newpass := utils.AskForPassphrase("Export Passphrase: ")
data, err := ks.Export(account, pass, newpass)
if err == nil {
f, err := os.OpenFile(fmt.Sprintf(".hmy/%s.key", account.Address.Hex()), os.O_CREATE|os.O_WRONLY, 0644)
filename := fmt.Sprintf(".hmy/%s.key", account.Address.Hex())
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
panic("Failed to open keystore")
}
@ -289,7 +288,8 @@ func processListCommand() {
panic("Failed to write to keystore")
}
f.Close()
continue
fmt.Printf("Exported keyfile to: %v\n", filename)
return
}
switch err {
case accounts.ErrInvalidPassphrase:
@ -297,6 +297,27 @@ func processListCommand() {
default:
fmt.Printf("export error: %v\n", err)
}
}
func processListCommand() {
listCommand.Parse(os.Args[2:])
allAccounts := ks.Accounts()
for _, account := range allAccounts {
fmt.Printf("account: %s\n", account.Address.Hex())
fmt.Printf("URL: %s\n", account.URL)
}
}
func processExportCommand() {
exportCommand.Parse(os.Args[2:])
acc := *exportCommandAccountPtr
allAccounts := ks.Accounts()
for _, account := range allAccounts {
if acc == "" || acc == account.Address.Hex() {
_exportAccount(account)
}
}
}
@ -432,7 +453,13 @@ func processTransferCommand() {
return
}
ks.Unlock(account, senderPass)
err = ks.Unlock(account, senderPass)
if err != nil {
fmt.Printf("Unlock account failed! %v\n", err)
return
}
fmt.Printf("Unlock account succeeded! '%v'\n", senderPass)
tx, err = ks.SignTx(account, tx, nil)
if err != nil {

@ -87,7 +87,7 @@ var (
// Key file to store the private key of staking account.
stakingKeyFile = flag.String("staking_key", "./.stakingkey", "the private key file of the harmony node")
// Key file to store the private key
keyFile = flag.String("key", "./.hmykey", "the private key file of the harmony node")
keyFile = flag.String("key", "./.hmykey", "the p2p key file of the harmony node")
// isGenesis indicates this node is a genesis node
isGenesis = flag.Bool("is_genesis", false, "true means this node is a genesis node")
// isArchival indicates this node is an archival node that will save and archive current blockchain
@ -99,10 +99,10 @@ var (
// logConn logs incoming/outgoing connections
logConn = flag.Bool("log_conn", false, "log incoming/outgoing connections")
keystoreDir = flag.String(".hmy/keystore", hmykey.DefaultKeyStoreDir, "The default keystore directory")
keystoreDir = flag.String("keystore", hmykey.DefaultKeyStoreDir, "The default keystore directory")
// true by default for now. will be switch to false once have full support.
hmyNoPass = flag.Bool("nopass", true, "No passphrase for the key (testing only)")
hmyNoPass = flag.Bool("nopass", false, "No passphrase for the key (testing only)")
ks *keystore.KeyStore
myAccount accounts.Account

@ -11,6 +11,7 @@ SRC[wallet]="cmd/client/wallet/main.go cmd/client/wallet/generated_wallet.ini.go
BINDIR=bin
BUCKET=unique-bucket-bin
PUBBUCKET=pub.harmony.one
REL=cello
GOOS=linux
GOARCH=amd64
FOLDER=/${WHOAMI:-$USER}
@ -144,22 +145,19 @@ function upload_wallet
case "$OS" in
"Linux")
DEST=wallet/wallet
DESTDIR=wallet ;;
FOLDER=release/$REL/linux-x86_64 ;;
"Darwin")
DEST=wallet.osx/wallet
DESTDIR=wallet.osx ;;
FOLDER=release/$REL/darwin-x86_64 ;;
*)
echo "Unsupported OS: $OS"
return ;;
esac
$AWSCLI s3 cp $BINDIR/wallet s3://$PUBBUCKET/$DEST
$AWSCLI s3api put-object-acl --bucket $PUBBUCKET --key $DEST --acl public-read
$AWSCLI s3 cp $BINDIR/wallet s3://$PUBBUCKET/$FOLDER/wallet --acl public-read
for lib in "${!LIB[@]}"; do
if [ -e ${LIB[$lib]} ]; then
$AWSCLI s3 cp ${LIB[$lib]} s3://${PUBBUCKET}/$DESTDIR/$lib --acl public-read
$AWSCLI s3 cp ${LIB[$lib]} s3://${PUBBUCKET}/$FOLDER/$lib --acl public-read
else
echo "!! MISSING ${LIB[$lib]} !!"
fi

Loading…
Cancel
Save