obscuren il y a 10 ans
Parent
commit
629f4b1d3c
2 fichiers modifiés avec 29 ajouts et 16 suppressions
  1. 18 13
      cmd/ethereum/main.go
  2. 11 3
      cmd/utils/flags.go

+ 18 - 13
cmd/ethereum/main.go

@@ -129,6 +129,7 @@ runtime will execute the file and exit.
 		utils.RPCEnabledFlag,
 		utils.RPCListenAddrFlag,
 		utils.RPCPortFlag,
+		utils.UnencryptedKeysFlag,
 		utils.VMDebugFlag,
 		//utils.VMTypeFlag,
 	}
@@ -230,20 +231,24 @@ func accountList(ctx *cli.Context) {
 
 func accountCreate(ctx *cli.Context) {
 	am := utils.GetAccountManager(ctx)
-	fmt.Println("The new account will be encrypted with a passphrase.")
-	fmt.Println("Please enter a passphrase now.")
-	auth, err := readPassword("Passphrase: ", true)
-	if err != nil {
-		utils.Fatalf("%v", err)
-	}
-	confirm, err := readPassword("Repeat Passphrase: ", false)
-	if err != nil {
-		utils.Fatalf("%v", err)
-	}
-	if auth != confirm {
-		utils.Fatalf("Passphrases did not match.")
+	passphrase := ""
+	if !ctx.GlobalBool(utils.UnencryptedKeysFlag.Name) {
+		fmt.Println("The new account will be encrypted with a passphrase.")
+		fmt.Println("Please enter a passphrase now.")
+		auth, err := readPassword("Passphrase: ", true)
+		if err != nil {
+			utils.Fatalf("%v", err)
+		}
+		confirm, err := readPassword("Repeat Passphrase: ", false)
+		if err != nil {
+			utils.Fatalf("%v", err)
+		}
+		if auth != confirm {
+			utils.Fatalf("Passphrases did not match.")
+		}
+		passphrase = auth
 	}
-	acct, err := am.NewAccount(auth)
+	acct, err := am.NewAccount(passphrase)
 	if err != nil {
 		utils.Fatalf("Could not create the account: %v", err)
 	}

+ 11 - 3
cmd/utils/flags.go

@@ -99,6 +99,10 @@ var (
 		Name:  "mine",
 		Usage: "Enable mining",
 	}
+	UnencryptedKeysFlag = cli.BoolFlag{
+		Name:  "unencrypted-keys",
+		Usage: "disable private key disk encryption (for testing)",
+	}
 
 	LogFileFlag = cli.StringFlag{
 		Name:  "logfile",
@@ -224,9 +228,13 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.D
 
 func GetAccountManager(ctx *cli.Context) *accounts.Manager {
 	dataDir := ctx.GlobalString(DataDirFlag.Name)
-	ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
-	km := accounts.NewManager(ks)
-	return km
+	var ks crypto.KeyStore2
+	if ctx.GlobalBool(UnencryptedKeysFlag.Name) {
+		ks = crypto.NewKeyStorePlain(path.Join(dataDir, "plainkeys"))
+	} else {
+		ks = crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
+	}
+	return accounts.NewManager(ks)
 }
 
 func StartRPC(eth *eth.Ethereum, ctx *cli.Context) {