Skip to content

Commit

Permalink
Merge pull request #152 from LedgerHQ/151-bolos-specific-apdus-are-no…
Browse files Browse the repository at this point in the history
…t-managed

Manage BOLOS default APDUs
  • Loading branch information
yogh333 authored Apr 10, 2024
2 parents a882f1d + 79a718d commit dfa0725
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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 ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.8.0"
version = "1.8.1"
authors = ["yhql", "yogh333"]
edition = "2021"
license.workspace = true
Expand Down
46 changes: 46 additions & 0 deletions ledger_device_sdk/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ impl Comm {
return None;
}

// Manage BOLOS specific APDUs B0xx0000
if self.apdu_buffer[0] == 0xB0
&& self.apdu_buffer[2] == 0x00
&& self.apdu_buffer[3] == 0x00
{
handle_bolos_apdu(self, self.apdu_buffer[1]);
return None;
}

// If CLA filtering is enabled, automatically reject APDUs with wrong CLA
if let Some(cla) = self.expected_cla {
if self.apdu_buffer[0] != cla {
Expand Down Expand Up @@ -467,6 +476,43 @@ impl Comm {
}
}

// BOLOS APDU Handling (see https://developers.ledger.com/docs/connectivity/ledgerJS/open-close-info-on-apps)
fn handle_bolos_apdu(com: &mut Comm, ins: u8) {
match ins {
// Get Information INS: retrieve App name and version
0x01 => {
unsafe {
com.apdu_buffer[0] = 0x01;
com.tx += 1;
let len = os_registry_get_current_app_tag(
BOLOS_TAG_APPNAME,
&mut com.apdu_buffer[com.tx + 1] as *mut u8,
(260 - com.tx - 1) as u32,
);
com.apdu_buffer[com.tx] = len as u8;
com.tx += (1 + len) as usize;

let len = os_registry_get_current_app_tag(
BOLOS_TAG_APPVERSION,
&mut com.apdu_buffer[com.tx + 1] as *mut u8,
(260 - com.tx - 1) as u32,
);
com.apdu_buffer[com.tx] = len as u8;
com.tx += (1 + len) as usize;
}
com.reply_ok();
}
// Quit Application INS
0xa7 => {
com.reply_ok();
crate::exit_app(0);
}
_ => {
com.reply(StatusWords::BadIns);
}
}
}

impl Index<usize> for Comm {
type Output = u8;
fn index(&self, idx: usize) -> &Self::Output {
Expand Down

0 comments on commit dfa0725

Please sign in to comment.