Skip to content

Commit

Permalink
feat: ledger version check (#6541)
Browse files Browse the repository at this point in the history
Description
---
Changed the ledger app version check from an explicit check to a min
version check
Uses semver for checking

Closes: #6439
  • Loading branch information
SWvheerden authored Sep 10, 2024
1 parent f696fd3 commit 611f226
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/minotari_ledger_wallet/comms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tari_common_types = { path = "../../../base_layer/common_types" }
tari_script = { path = "../../../infrastructure/tari_script" }

minotari_ledger_wallet_common = { path = "../common" }

semver = "1.0"
borsh = "1.2"
dialoguer = { version = "0.11" }
ledger-transport = { git = "https://github.com/Zondax/ledger-rs", rev = "20e2a20" }
Expand Down
25 changes: 15 additions & 10 deletions applications/minotari_ledger_wallet/comms/src/accessor_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use log::debug;
use minotari_ledger_wallet_common::common_types::{AppSW, Instruction};
use once_cell::sync::Lazy;
use rand::{rngs::OsRng, RngCore};
use semver::Version;
use tari_common::configuration::Network;
use tari_common_types::{
key_branches::TransactionKeyManagerBranch,
Expand All @@ -38,7 +39,7 @@ use tari_utilities::{hex::Hex, ByteArray};

use crate::{
error::LedgerDeviceError,
ledger_wallet::{Command, EXPECTED_NAME, EXPECTED_VERSION},
ledger_wallet::{Command, EXPECTED_NAME, MIN_LEDGER_APP_VERSION},
};

const LOG_TARGET: &str = "ledger_wallet::accessor_methods";
Expand Down Expand Up @@ -91,16 +92,20 @@ fn verify() -> Result<(), LedgerDeviceError> {

match ledger_get_version() {
Ok(version) => {
if version != EXPECTED_VERSION {
let req = Version::parse(MIN_LEDGER_APP_VERSION)
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?;
let ledger_version =
Version::parse(&version).map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?;
if ledger_version < req {
return Err(LedgerDeviceError::Processing(format!(
"'Minotari Wallet' application version mismatch: expected '{}', running '{}'.",
EXPECTED_VERSION, version
"'Minotari Wallet' application version check failed: min version '{}', running '{}'.",
MIN_LEDGER_APP_VERSION, version
)));
}
},
Err(e) => {
return Err(LedgerDeviceError::Processing(format!(
"'Minotari Wallet' application version mismatch ({})",
"'Minotari Wallet' application version check ({})",
e
)))
},
Expand Down Expand Up @@ -601,15 +606,15 @@ pub fn ledger_get_one_sided_metadata_signature(
let data = result.data();
Ok(ComAndPubSignature::new(
Commitment::from_canonical_bytes(&data[1..33])
.map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?,
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?,
PublicKey::from_canonical_bytes(&data[33..65])
.map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?,
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?,
PrivateKey::from_canonical_bytes(&data[65..97])
.map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?,
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?,
PrivateKey::from_canonical_bytes(&data[97..129])
.map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?,
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?,
PrivateKey::from_canonical_bytes(&data[129..161])
.map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?,
.map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?,
))
},
Err(e) => Err(LedgerDeviceError::Instruction(format!(
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_ledger_wallet/comms/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum LedgerDeviceError {
Processing(String),
/// Conversion error to or from ledger
#[error("Conversion failed: {0}")]
ByteArrayError(String),
ConversionError(String),
/// Not yet supported
#[error("Ledger is not fully supported")]
NotSupported,
Expand All @@ -60,7 +60,7 @@ pub enum LedgerDeviceError {

impl From<ByteArrayError> for LedgerDeviceError {
fn from(e: ByteArrayError) -> Self {
LedgerDeviceError::ByteArrayError(e.to_string())
LedgerDeviceError::ConversionError(e.to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use tari_utilities::ByteArray;
use crate::error::LedgerDeviceError;

pub const EXPECTED_NAME: &str = "minotari_ledger_wallet";
pub const EXPECTED_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const MIN_LEDGER_APP_VERSION: &str = "1.4.0";
const WALLET_CLA: u8 = 0x80;

struct HidManager {
Expand Down

0 comments on commit 611f226

Please sign in to comment.