Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Handle Auth metadata fragments and clarify clock guidance

Manav Rathi28b84cc2137e
diff --git a/rust/apps/cli-next/src/account.rs b/rust/apps/cli-next/src/account.rs
index e1fa3e39de..db27329342 100644
--- a/rust/apps/cli-next/src/account.rs
+++ b/rust/apps/cli-next/src/account.rs
@@ -317,8 +317,16 @@ pub async fn totp(
};
}
let setup = TwoFactorSetup::from_secret(secret.to_string(), &account.identity.recovery_key);
+ let incorrect_code =
+ "Code not accepted. Check the code and your computer's date and time, then try again.";
if let Some(input) = input {
- setup.enable(&client, &input.totp).await?;
+ setup
+ .enable(&client, &input.totp)
+ .await
+ .map_err(|error| match error {
+ ente_accounts::Error::IncorrectTotp => anyhow::anyhow!(incorrect_code),
+ error => error.into(),
+ })?;
} else {
eprintln!("Add this secret to your authenticator: {}", secret.as_str());
loop {
@@ -329,7 +337,7 @@ pub async fn totp(
);
match setup.enable(&client, &code).await {
Err(ente_accounts::Error::IncorrectTotp) => {
- eprintln!("Incorrect authenticator code. Try again.")
+ eprintln!("{incorrect_code}")
}
result => {
result?;
diff --git a/rust/apps/cli-next/src/args.rs b/rust/apps/cli-next/src/args.rs
index 63fe5ec133..699bac3f85 100644
--- a/rust/apps/cli-next/src/args.rs
+++ b/rust/apps/cli-next/src/args.rs
@@ -291,7 +291,8 @@ Several matches fail and list candidates; narrow the search or use an ID.
Quote queries containing spaces.
A code in Trash must be restored in Ente Auth first.
JSON fields: id, name, issuer, accountName, type, otp, validUntil (UTC).
-HOTP values are not supported yet."
+HOTP values are not supported yet.
+Codes use your computer's clock. Make sure its date and time are correct."
)]
View {
#[arg(
@@ -715,7 +716,10 @@ With --json, returns {\"recoveryKey\":\"...\"}."
pub enum TotpCommand {
#[command(about = "Print a new authenticator setup secret")]
Setup,
- #[command(about = "Confirm and enable authenticator protection")]
+ #[command(
+ about = "Confirm and enable authenticator protection",
+ after_long_help = "Verifying an authenticator code requires your computer's date and time to be correct."
+ )]
Enable {
#[arg(
long,
diff --git a/rust/apps/cli-next/tests/cli/account.rs b/rust/apps/cli-next/tests/cli/account.rs
index 47aebe3440..066d35d871 100644
--- a/rust/apps/cli-next/tests/cli/account.rs
+++ b/rust/apps/cli-next/tests/cli/account.rs
@@ -339,10 +339,11 @@ fn creation_enrollment_and_login_across_processes() -> ente_test_support::TestRe
home.json(&["account", "totp", "status"]),
json!({"enabled": false})
);
- failure(&home.with_input(
+ let error = failure(&home.with_input(
&["account", "totp", "enable", "--input", "-"],
&serde_json::to_vec(&json!({"secret": secret, "totp": "invalid"}))?,
));
+ assert!(error.contains("Code not accepted."));
let output = success(home.with_input(
&["account", "totp", "enable", "--input", "-", "--json"],
&serde_json::to_vec(&json!({"secret": secret, "totp": current_totp(secret)?}))?,
diff --git a/rust/apps/cli-next/tests/cli/account_prompt.py b/rust/apps/cli-next/tests/cli/account_prompt.py
index edaa7de2ce..83d9c45de2 100644
--- a/rust/apps/cli-next/tests/cli/account_prompt.py
+++ b/rust/apps/cli-next/tests/cli/account_prompt.py
@@ -76,7 +76,7 @@ def enable(expect, send):
text = expect(b"Authenticator code:")
secret = re.search(rb"authenticator: ([A-Z2-7]+)", text)[1]
send(b"invalid", True)
- expect(b"Incorrect authenticator code. Try again.")
+ expect(b"Code not accepted. Check the code and your computer's date and time, then try again.")
expect(b"Authenticator code:")
key = base64.b32decode(secret + b"=" * (-len(secret) % 8))
digest = hmac.new(key, (int(time.time()) // 30).to_bytes(8, "big"), hashlib.sha1).digest()
diff --git a/rust/apps/cli-next/tests/cli/auth.rs b/rust/apps/cli-next/tests/cli/auth.rs
index 8114946563..4d16c32aee 100644
--- a/rust/apps/cli-next/tests/cli/auth.rs
+++ b/rust/apps/cli-next/tests/cli/auth.rs
@@ -58,7 +58,7 @@ fn code_reads_refresh_select_and_render_without_a_backup() {
vec![
entity(1, 10, &uri("GitHub:[email protected]"), &key),
entity(2, 10, &uri("GitHub:[email protected]"), &key),
- entity(3, 10, &json!(URI), &key),
+ entity(3, 10, &json!(format!("{URI}#suffix")), &key),
entity(4, 10, &json!("otpauth://totp/Steam:alice?secret=MY"), &key),
entity(
5,
diff --git a/rust/crates/auth/src/code.rs b/rust/crates/auth/src/code.rs
index 2ae2ec9fc5..755ed9e21e 100644
--- a/rust/crates/auth/src/code.rs
+++ b/rust/crates/auth/src/code.rs
@@ -82,7 +82,9 @@ impl Code {
}
let display = query
.get("codeDisplay")
- .map(|value| serde_json::from_str::<Option<Display>>(value))
+ .map(|value| {
+ Option::<Display>::deserialize(&mut serde_json::Deserializer::from_str(value))
+ })
.transpose()
.map_err(|_| Error::InvalidRecord)?
.flatten()
@@ -164,9 +166,16 @@ mod tests {
fn saved_forms_preserve_labels_and_generate_with_stored_parameters() {
let uri = "otpauth://totp/Work:alice%2B%252C#tag?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&digits=8&period=60&algorithm=Algorithm.SHA1";
let key = Key::generate();
- for value in [
- json!(uri),
- json!({"rawData": uri, "display": {"note": "literal%2C"}}),
+ for (value, trashed) in [
+ (json!(uri), false),
+ (
+ json!({"rawData": uri, "display": {"note": "literal%2C"}}),
+ false,
+ ),
+ (
+ json!(format!("{uri}&codeDisplay={{\"trashed\":true}}#suffix")),
+ true,
+ ),
] {
let encrypted = blob::encrypt(&serde_json::to_vec(&value).unwrap(), &key).unwrap();
let line = crate::record::uri_line(
@@ -177,6 +186,7 @@ mod tests {
.unwrap();
let code = Code::from_uri(&line).unwrap();
assert_eq!(code.name(), "Work (alice+%2C#tag)");
+ assert_eq!(code.trashed, trashed);
assert_eq!(
code.generate(2_222_222_219).unwrap(),
("07081804".into(), 2_222_222_220)