diff --git a/Cargo.lock b/Cargo.lock index 512c28c5..ee45ca7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "ledger_device_sdk" -version = "1.8.0" +version = "1.8.1" dependencies = [ "include_gif", "ledger_device_sdk", diff --git a/ledger_device_sdk/Cargo.toml b/ledger_device_sdk/Cargo.toml index 82a942b9..dfd44f46 100644 --- a/ledger_device_sdk/Cargo.toml +++ b/ledger_device_sdk/Cargo.toml @@ -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 diff --git a/ledger_device_sdk/src/io.rs b/ledger_device_sdk/src/io.rs index 0c86b08e..cc6e481f 100644 --- a/ledger_device_sdk/src/io.rs +++ b/ledger_device_sdk/src/io.rs @@ -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 { @@ -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 for Comm { type Output = u8; fn index(&self, idx: usize) -> &Self::Output {