diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index f3c88c62cf..12e2e3042d 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2910,6 +2910,16 @@ dependencies = [ "librocksdb-sys 5.17.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rpassword" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.14" @@ -3912,6 +3922,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5787,6 +5798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" "checksum ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a" "checksum rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1651697fefd273bfb4fd69466cc2a9d20de557a0213b97233b22b5e95924b5e" +"checksum rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34fa7bcae7fca3c8471e8417088bbc3ad9af8066b0ecf4f3c0d98a0d772716e" "checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" diff --git a/substrate/core/cli/Cargo.toml b/substrate/core/cli/Cargo.toml index dbc9fc0aae..2482323c80 100644 --- a/substrate/core/cli/Cargo.toml +++ b/substrate/core/cli/Cargo.toml @@ -33,6 +33,7 @@ substrate-telemetry = { path = "../../core/telemetry" } keyring = { package = "substrate-keyring", path = "../keyring" } names = "0.11.0" structopt = "0.2" +rpassword = "3.0" [dev-dependencies] tempdir = "0.3" diff --git a/substrate/core/cli/src/lib.rs b/substrate/core/cli/src/lib.rs index fd03f5b646..4bdaaee8e5 100644 --- a/substrate/core/cli/src/lib.rs +++ b/substrate/core/cli/src/lib.rs @@ -365,6 +365,11 @@ fn fill_network_configuration( Ok(()) } +fn input_keystore_password() -> Result { + rpassword::read_password_from_tty(Some("Keystore password: ")) + .map_err(|e| format!("{:?}", e)) +} + fn create_run_node_config( cli: RunCmd, spec_factory: S, impl_name: &'static str, version: &VersionInfo ) -> error::Result> @@ -374,6 +379,9 @@ where { let spec = load_spec(&cli.shared_params, spec_factory)?; let mut config = service::Configuration::default_with_spec(spec.clone()); + if cli.interactive_password { + config.password = input_keystore_password()? + } config.impl_name = impl_name; config.impl_commit = version.commit; diff --git a/substrate/core/cli/src/params.rs b/substrate/core/cli/src/params.rs index 6cb4a6068a..503d8fca32 100644 --- a/substrate/core/cli/src/params.rs +++ b/substrate/core/cli/src/params.rs @@ -395,6 +395,10 @@ pub struct RunCmd { /// Enable authoring even when offline. #[structopt(long = "force-authoring")] pub force_authoring: bool, + + /// Interactive password for validator key. + #[structopt(short = "i")] + pub interactive_password: bool, } /// Stores all required Cli values for a keyring test account. diff --git a/substrate/core/service/src/config.rs b/substrate/core/service/src/config.rs index 20134c788d..c9e8e4662d 100644 --- a/substrate/core/service/src/config.rs +++ b/substrate/core/service/src/config.rs @@ -78,6 +78,8 @@ pub struct Configuration { pub force_authoring: bool, /// Disable GRANDPA when running in validator mode pub disable_grandpa: bool, + /// Node keystore's password + pub password: String, } impl Configuration { @@ -108,6 +110,7 @@ impl Configuration Service { let public_key = match keystore.contents()?.get(0) { Some(public_key) => public_key.clone(), None => { - let key = keystore.generate("")?; + let key = keystore.generate(&config.password)?; let public_key = key.public(); info!("Generated a new keypair: {:?}", public_key); @@ -382,7 +382,7 @@ impl Service { if self.config.roles != Roles::AUTHORITY { return None } let keystore = &self.keystore; if let Ok(Some(Ok(key))) = keystore.contents().map(|keys| keys.get(0) - .map(|k| keystore.load(k, ""))) + .map(|k| keystore.load(k, &self.config.password))) { Some(key) } else { diff --git a/substrate/core/service/test/src/lib.rs b/substrate/core/service/test/src/lib.rs index 95cd0173b4..b0ed0c0fc1 100644 --- a/substrate/core/service/test/src/lib.rs +++ b/substrate/core/service/test/src/lib.rs @@ -127,6 +127,7 @@ fn node_config ( offchain_worker: false, force_authoring: false, disable_grandpa: false, + password: "".to_string(), } }