From 775bb152fc94a5fa1d815f50026c13aad06fdedd Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 2 Jul 2018 14:54:35 -0700 Subject: [PATCH 1/4] Report error when an invalid confirmation signature or public key is provided --- src/bin/wallet.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index d290de898373e8..d189461ca1682c 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -35,6 +35,7 @@ enum WalletCommand { #[derive(Debug, Clone)] enum WalletError { CommandNotRecognized(String), + BadParameter(String), } impl fmt::Display for WalletError { @@ -173,6 +174,11 @@ fn parse_args() -> Result> { let pubkey_vec = bs58::decode(pay_matches.value_of("to").unwrap()) .into_vec() .expect("base58-encoded public key"); + + if pubkey_vec.len() != std::mem::size_of::() { + display_actions(); + Err(WalletError::BadParameter("Invalid public key".to_string()))?; + } to = PublicKey::clone_from_slice(&pubkey_vec); } else { to = id.pubkey(); @@ -187,8 +193,14 @@ fn parse_args() -> Result> { let sig_vec = bs58::decode(confirm_matches.value_of("signature").unwrap()) .into_vec() .expect("base58-encoded signature"); - let sig = Signature::clone_from_slice(&sig_vec); - Ok(WalletCommand::Confirm(sig)) + + if sig_vec.len() == std::mem::size_of::() { + let sig = Signature::clone_from_slice(&sig_vec); + Ok(WalletCommand::Confirm(sig)) + } else { + display_actions(); + Err(WalletError::BadParameter("Invalid signature".to_string())) + } } ("balance", Some(_balance_matches)) => Ok(WalletCommand::Balance), ("address", Some(_address_matches)) => Ok(WalletCommand::Address), From 70a3f0bd4506c24539d292cff01091b846f61849 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 2 Jul 2018 15:17:12 -0700 Subject: [PATCH 2/4] Support testnet.solana.com as first argument --- multinode-demo/wallet.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multinode-demo/wallet.sh b/multinode-demo/wallet.sh index 049abc5c9a7fc6..4e737513829b39 100755 --- a/multinode-demo/wallet.sh +++ b/multinode-demo/wallet.sh @@ -8,8 +8,8 @@ here=$(dirname "$0") source "$here"/common.sh SOLANA_CONFIG_DIR=config-client -# if $1 isn't host:path or some local path -if [[ ${1%:} != "$1" || -d $1 ]]; then +# if $1 isn't host:path, something.com, or a valid local path +if [[ ${1%:} != "$1" || "$1" =~ [^.].[^.] || -d $1 ]]; then leader=$1 # interpret shift else From b8b3c73210fb445b4149792ea3213943ea475617 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 2 Jul 2018 15:22:25 -0700 Subject: [PATCH 3/4] Abort nicer on drone connection failure --- src/bin/wallet.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index d189461ca1682c..0afc2689f5cbca 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -250,7 +250,7 @@ fn process_command( WalletCommand::AirDrop(tokens) => { println!("Airdrop requested..."); println!("Airdropping {:?} tokens", tokens); - let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64); + let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64)?; // TODO: return airdrop Result from Drone sleep(Duration::from_millis(100)); println!( @@ -313,8 +313,12 @@ fn mk_client(r: &ReplicatedData) -> io::Result { )) } -fn request_airdrop(drone_addr: &SocketAddr, id: &Mint, tokens: u64) { - let mut stream = TcpStream::connect(drone_addr).unwrap(); +fn request_airdrop( + drone_addr: &SocketAddr, + id: &Mint, + tokens: u64, +) -> Result<(), Box> { + let mut stream = TcpStream::connect(drone_addr)?; let req = DroneRequest::GetAirdrop { airdrop_request_amount: tokens, client_public_key: id.pubkey(), @@ -322,6 +326,7 @@ fn request_airdrop(drone_addr: &SocketAddr, id: &Mint, tokens: u64) { let tx = serialize(&req).expect("serialize drone request"); stream.write_all(&tx).unwrap(); // TODO: add timeout to this function, in case of unresponsive drone + Ok(()) } fn main() -> Result<(), Box> { From 17ca9f2ec356376d07892664908e1dee5a453a36 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 2 Jul 2018 15:34:13 -0700 Subject: [PATCH 4/4] Correct locate rsync when running as a Snap --- multinode-demo/client.sh | 4 ++-- multinode-demo/common.sh | 2 ++ multinode-demo/drone.sh | 4 ++-- multinode-demo/validator.sh | 2 +- multinode-demo/wallet.sh | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/multinode-demo/client.sh b/multinode-demo/client.sh index 0e6e8ff739d773..d3d9ebb7f11e8c 100755 --- a/multinode-demo/client.sh +++ b/multinode-demo/client.sh @@ -15,8 +15,8 @@ rsync_leader_url=$(rsync_url "$leader") set -ex mkdir -p $SOLANA_CONFIG_DIR -rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ -rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/ +$rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ +$rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/ # shellcheck disable=SC2086 # $solana_client_demo should not be quoted exec $solana_client_demo \ diff --git a/multinode-demo/common.sh b/multinode-demo/common.sh index 03f97ca2a713b8..dbd0ab9ab0f349 100644 --- a/multinode-demo/common.sh +++ b/multinode-demo/common.sh @@ -3,11 +3,13 @@ # Disable complaints about unused variables in this file: # shellcheck disable=2034 +rsync=rsync if [[ -d "$SNAP" ]]; then # Running inside a Linux Snap? solana_program() { declare program="$1" printf "%s/command-%s.wrapper" "$SNAP" "$program" } + rsync="$SNAP"/bin/rsync SOLANA_CUDA="$(snapctl get enable-cuda)" elif [[ -n "$USE_SNAP" ]]; then # Use the Linux Snap binaries diff --git a/multinode-demo/drone.sh b/multinode-demo/drone.sh index d2677dd113edaf..74f7dcdfac701a 100755 --- a/multinode-demo/drone.sh +++ b/multinode-demo/drone.sh @@ -27,8 +27,8 @@ fi rsync_leader_url=$(rsync_url "$leader") set -ex mkdir -p $SOLANA_CONFIG_DIR -rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ -rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/ +$rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ +$rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/ # shellcheck disable=SC2086 # $solana_drone should not be quoted exec $solana_drone \ diff --git a/multinode-demo/validator.sh b/multinode-demo/validator.sh index 5735895800a4f0..2c40c03a4c1afb 100755 --- a/multinode-demo/validator.sh +++ b/multinode-demo/validator.sh @@ -68,7 +68,7 @@ rsync_leader_url=$(rsync_url "$leader") set -ex SOLANA_LEADER_CONFIG_DIR="$SOLANA_CONFIG_DIR"/leader-config rm -rf "$SOLANA_LEADER_CONFIG_DIR" -rsync -vPrz "$rsync_leader_url"/config/ "$SOLANA_LEADER_CONFIG_DIR" +$rsync -vPrz "$rsync_leader_url"/config/ "$SOLANA_LEADER_CONFIG_DIR" ls -lh "$SOLANA_LEADER_CONFIG_DIR" # shellcheck disable=SC2086 # $program should not be quoted diff --git a/multinode-demo/wallet.sh b/multinode-demo/wallet.sh index 4e737513829b39..efab71fd065e8d 100755 --- a/multinode-demo/wallet.sh +++ b/multinode-demo/wallet.sh @@ -21,7 +21,7 @@ rsync_leader_url=$(rsync_url "$leader") set -e mkdir -p $SOLANA_CONFIG_DIR if [[ ! -r $SOLANA_CONFIG_DIR/leader.json ]]; then - rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ + $rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/ fi client_json=$SOLANA_CONFIG_DIR/client.json