Add flag to confirm key on device (#8478)

This commit is contained in:
Tyera Eulberg
2020-02-26 15:24:44 -07:00
committed by GitHub
parent d47a47924a
commit f6f0f94e17
5 changed files with 28 additions and 7 deletions

View File

@ -86,6 +86,7 @@ pub fn signer_from_path(
path, path,
derivation_of(matches, "derivation_path"), derivation_of(matches, "derivation_path"),
wallet_manager, wallet_manager,
matches.is_present("confirm_key"),
)?)) )?))
} else { } else {
Err(RemoteWalletError::NoDeviceFound.into()) Err(RemoteWalletError::NoDeviceFound.into())

View File

@ -620,7 +620,7 @@ pub fn parse_command(
), ),
("vote-account", Some(matches)) => parse_vote_get_account_command(matches), ("vote-account", Some(matches)) => parse_vote_get_account_command(matches),
// Wallet Commands // Wallet Commands
("address", Some(_matches)) => Ok(CliCommandInfo { ("address", Some(matches)) => Ok(CliCommandInfo {
command: CliCommand::Address, command: CliCommand::Address,
signers: vec![signer_from_path( signers: vec![signer_from_path(
matches, matches,
@ -2064,7 +2064,16 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.about(about) .about(about)
.version(version) .version(version)
.setting(AppSettings::SubcommandRequiredElseHelp) .setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("address").about("Get your public key")) .subcommand(
SubCommand::with_name("address")
.about("Get your public key")
.arg(
Arg::with_name("confirm_key")
.long("confirm-key")
.takes_value(false)
.help("Confirm key on device; only relevant if using remote wallet"),
),
)
.cluster_query_subcommands() .cluster_query_subcommands()
.nonce_subcommands() .nonce_subcommands()
.stake_subcommands() .stake_subcommands()

View File

@ -261,7 +261,7 @@ impl RemoteWallet for LedgerWallet {
.serial_number .serial_number
.clone() .clone()
.unwrap_or_else(|| "Unknown".to_owned()); .unwrap_or_else(|| "Unknown".to_owned());
self.get_pubkey(&DerivationPath::default()) self.get_pubkey(&DerivationPath::default(), false)
.map(|pubkey| RemoteWalletInfo { .map(|pubkey| RemoteWalletInfo {
model, model,
manufacturer, manufacturer,
@ -270,12 +270,16 @@ impl RemoteWallet for LedgerWallet {
}) })
} }
fn get_pubkey(&self, derivation_path: &DerivationPath) -> Result<Pubkey, RemoteWalletError> { fn get_pubkey(
&self,
derivation_path: &DerivationPath,
confirm_key: bool,
) -> Result<Pubkey, RemoteWalletError> {
let derivation_path = extend_and_serialize(derivation_path); let derivation_path = extend_and_serialize(derivation_path);
let key = self.send_apdu( let key = self.send_apdu(
commands::GET_PUBKEY, commands::GET_PUBKEY,
0, // In the naive implementation, default request is for no device confirmation if confirm_key { 1 } else { 0 },
0, 0,
&derivation_path, &derivation_path,
)?; )?;

View File

@ -20,9 +20,10 @@ impl RemoteKeypair {
pub fn new( pub fn new(
wallet_type: RemoteWalletType, wallet_type: RemoteWalletType,
derivation_path: DerivationPath, derivation_path: DerivationPath,
confirm_key: bool,
) -> Result<Self, RemoteWalletError> { ) -> Result<Self, RemoteWalletError> {
let pubkey = match &wallet_type { let pubkey = match &wallet_type {
RemoteWalletType::Ledger(wallet) => wallet.get_pubkey(&derivation_path)?, RemoteWalletType::Ledger(wallet) => wallet.get_pubkey(&derivation_path, confirm_key)?,
}; };
Ok(Self { Ok(Self {
@ -51,6 +52,7 @@ pub fn generate_remote_keypair(
path: String, path: String,
explicit_derivation_path: Option<DerivationPath>, explicit_derivation_path: Option<DerivationPath>,
wallet_manager: &RemoteWalletManager, wallet_manager: &RemoteWalletManager,
confirm_key: bool,
) -> Result<RemoteKeypair, RemoteWalletError> { ) -> Result<RemoteKeypair, RemoteWalletError> {
let (remote_wallet_info, mut derivation_path) = RemoteWalletInfo::parse_path(path)?; let (remote_wallet_info, mut derivation_path) = RemoteWalletInfo::parse_path(path)?;
if let Some(derivation) = explicit_derivation_path { if let Some(derivation) = explicit_derivation_path {
@ -61,6 +63,7 @@ pub fn generate_remote_keypair(
Ok(RemoteKeypair::new( Ok(RemoteKeypair::new(
RemoteWalletType::Ledger(ledger), RemoteWalletType::Ledger(ledger),
derivation_path, derivation_path,
confirm_key,
)?) )?)
} else { } else {
Err(RemoteWalletError::DeviceTypeMismatch) Err(RemoteWalletError::DeviceTypeMismatch)

View File

@ -174,7 +174,11 @@ pub trait RemoteWallet {
) -> Result<RemoteWalletInfo, RemoteWalletError>; ) -> Result<RemoteWalletInfo, RemoteWalletError>;
/// Get solana pubkey from a RemoteWallet /// Get solana pubkey from a RemoteWallet
fn get_pubkey(&self, derivation_path: &DerivationPath) -> Result<Pubkey, RemoteWalletError>; fn get_pubkey(
&self,
derivation_path: &DerivationPath,
confirm_key: bool,
) -> Result<Pubkey, RemoteWalletError>;
/// Sign transaction data with wallet managing pubkey at derivation path m/44'/501'/<account>'/<change>'. /// Sign transaction data with wallet managing pubkey at derivation path m/44'/501'/<account>'/<change>'.
fn sign_message( fn sign_message(