Skip to content
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
6 changes: 5 additions & 1 deletion src/i18n/locales/de/firmware.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@
"passphrase": {
"confirm": "Bestätigen",
"confirmEmpty": "Leere Passphrase\nverwenden?",
"confirmHost": "Passphrase auf\nHost eingeben?",
"doubleCheck": "Bitte prüfe gleich\ndie angezeigte\nPassphrase erneut.",
"enterOnHost": "Passphrase auf\nHost eingeben",
"title": "Optionale Passphrase",
"tryAgain": "Bitte erneut\nversuchen"
"tooLong": "Passphrase\nzu lang",
"tryAgain": "Bitte erneut\nversuchen",
"unsupportedCharacters": "Ungültige\nZeichen"
},
"remainingAttempts": {
"last": "LETZTER Versuch.\nBei falschem\nPasswort wird das\nGerät zurückgesetzt.",
Expand Down
6 changes: 5 additions & 1 deletion src/i18n/locales/en/firmware.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@
"passphrase": {
"confirm": "Confirm",
"confirmEmpty": "Use empty\npassphrase?",
"confirmHost": "Enter passphrase\non host?",
"doubleCheck": "You will be asked to\nvisually confirm your\npassphrase now.",
"enterOnHost": "Enter passphrase\non host",
"title": "Optional passphrase",
"tryAgain": "Please try again"
"tooLong": "Passphrase too\nlong",
"tryAgain": "Please try again",
"unsupportedCharacters": "Unsupported\ncharacters"
},
"remainingAttempts": {
"last": "This is your LAST\npassword attempt.\nDevice will reset\nif password is wrong.",
Expand Down
31 changes: 23 additions & 8 deletions src/rust/bitbox02-rust/src/hww/api/unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use super::error::Error;
use crate::hal::ui::ConfirmParams;
use crate::hal::{Memory, Ui};
use crate::i18n::I18n as _;
use crate::pb;
use crate::pb::request::Request;
use crate::pb::response::Response;
Expand Down Expand Up @@ -64,16 +65,21 @@ async fn device_entry(hal: &mut impl crate::hal::Hal) -> Result<Option<Zeroizing
}
}

fn validate_host_passphrase(passphrase: &str) -> Result<(), &'static str> {
enum HostPassphraseError {
TooLong,
UnsupportedCharacters,
}

fn validate_host_passphrase(passphrase: &str) -> Result<(), HostPassphraseError> {
// Restrict host input to values that can also be entered again on the device.
if passphrase.len() > MAX_PASSPHRASE_LEN {
return Err("Passphrase too\nlong");
return Err(HostPassphraseError::TooLong);
}
if !passphrase
.bytes()
.all(|c| c.is_ascii_alphanumeric() || SPECIAL.contains(&c))
{
return Err("Unsupported\ncharacters");
return Err(HostPassphraseError::UnsupportedCharacters);
}
Ok(())
}
Expand All @@ -94,11 +100,12 @@ async fn passphrase(hal: &mut impl crate::hal::Hal) -> Result<Zeroizing<String>,
None => {
// Entry was interrupted by the host button. Rejection/cancellation always starts a
// fresh device-entry screen, without preserving a partially entered passphrase.
let body = crate::tr!(hal, "Enter passphrase\non host?");
if hal
.ui()
.confirm(&ConfirmParams {
title: "",
body: "Enter passphrase\non host?",
body: &body,
..Default::default()
})
.await
Expand All @@ -109,7 +116,8 @@ async fn passphrase(hal: &mut impl crate::hal::Hal) -> Result<Zeroizing<String>,

let request = {
let waiting = async {
hal.ui().waiting("Enter passphrase\non host").await;
let message = crate::tr!(hal, "Enter passphrase\non host");
hal.ui().waiting(&message).await;
unreachable!()
};
// Poll the waiting screen first so it is visible before HOST_ENTRY_READY. This
Expand All @@ -126,10 +134,16 @@ async fn passphrase(hal: &mut impl crate::hal::Hal) -> Result<Zeroizing<String>,
let Some(passphrase) = request.passphrase.take().map(Zeroizing::new) else {
continue;
};
if let Err(message) = validate_host_passphrase(&passphrase) {
if let Err(error) = validate_host_passphrase(&passphrase) {
// Invalid user input restarts entry just like rejection; malformed protocol
// messages still fail in next_request.
hal.ui().status(message, false).await;
let message = match error {
HostPassphraseError::TooLong => crate::tr!(hal, "Passphrase too\nlong"),
HostPassphraseError::UnsupportedCharacters => {
crate::tr!(hal, "Unsupported\ncharacters")
}
};
hal.ui().status(&message, false).await;
continue;
}
(passphrase, true)
Expand All @@ -141,7 +155,8 @@ async fn passphrase(hal: &mut impl crate::hal::Hal) -> Result<Zeroizing<String>,
{
return Ok(passphrase);
}
hal.ui().status("Please try again", false).await;
let status = crate::tr!(hal, "Please try again");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between crate::tr!() and hal.tr()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crate::tr!() throws an error during compilation if the source string is missing from the English lang file. hal.tr() just falls back to the supplied text.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Made a PR to your PR to use tr!() so we can have static checks: sutterseba#2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent PR on master to enforce static checks everywhere (except in C)

#2198

hal.ui().status(&status, false).await;
}
}

Expand Down
Loading