Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage BOLOS default APDUs #152

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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