Skip to content

Commit a1b08fc

Browse files
Add warning screens when user reviews transaction in blind mode.
1 parent 7798a1d commit a1b08fc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

ledger_device_sdk/src/nbgl.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use alloc::ffi::CString;
66
use alloc::vec::Vec;
77
use core::ffi::{c_char, c_int};
88
use core::mem::transmute;
9+
use include_gif::include_gif;
910
use ledger_secure_sdk_sys::*;
1011

1112
#[no_mangle]
@@ -332,6 +333,35 @@ impl<'a> NbglHomeAndSettings<'a> {
332333
}
333334
}
334335

336+
/// Private helper function to display a warning screen when a transaction
337+
/// is reviewed in "blind" mode. The user can choose to go back to safety
338+
/// or review the risk. If the user chooses to review the risk, a second screen
339+
/// is displayed with the option to accept the risk or reject the transaction.
340+
/// Used in NbglReview and NbglStreamingReview.
341+
fn show_blind_warning() -> bool {
342+
const WARNING: NbglGlyph =
343+
NbglGlyph::from_include(include_gif!("icons/Warning_64px.gif", NBGL));
344+
345+
let back_to_safety = NbglChoice::new().glyph(&WARNING).show(
346+
"Security risk detected",
347+
"It may not be safe to sign this transaction. To continue, you'll need to review the risk.",
348+
"Back to safety",
349+
"Review risk",
350+
);
351+
352+
if !back_to_safety {
353+
NbglChoice::new()
354+
.show(
355+
"The transaction cannot be trusted",
356+
"Your Ledger cannot decode this transaction. If you sign it, you could be authorizing malicious actions that can drain your wallet.\n\nLearn more: ledger.com/e8",
357+
"I accept the risk",
358+
"Reject transaction"
359+
)
360+
} else {
361+
false
362+
}
363+
}
364+
335365
/// A wrapper around the synchronous NBGL ux_sync_review C API binding.
336366
/// Used to display transaction review screens.
337367
pub struct NbglReview<'a> {
@@ -420,6 +450,13 @@ impl<'a> NbglReview<'a> {
420450
None => nbgl_icon_details_t::default(),
421451
};
422452

453+
if self.blind {
454+
if !show_blind_warning() {
455+
ledger_secure_sdk_sys::ux_sync_reviewStatus(self.tx_type.to_message(false));
456+
return false;
457+
}
458+
}
459+
423460
// Show the review on the device.
424461
let sync_ret = ledger_secure_sdk_sys::ux_sync_review(
425462
self.tx_type.to_c_type(self.blind, false),
@@ -929,6 +966,13 @@ impl NbglStreamingReview {
929966
let title = CString::new(title).unwrap();
930967
let subtitle = CString::new(subtitle).unwrap();
931968

969+
if self.blind {
970+
if !show_blind_warning() {
971+
ux_sync_reviewStatus(self.tx_type.to_message(false));
972+
return false;
973+
}
974+
}
975+
932976
let sync_ret = ux_sync_reviewStreamingStart(
933977
self.tx_type.to_c_type(self.blind, false),
934978
&self.icon as *const nbgl_icon_details_t,

0 commit comments

Comments
 (0)