Skip to content

armgit / ente

Public Imported from GitHub
0

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

Split rate limit variants, restore original guidance

Manav Rathi7859cf082250
diff --git a/rust/bindings/wasm/ente-wasm/src/auth.rs b/rust/bindings/wasm/ente-wasm/src/auth.rs
index ad1fcba5f4..33a9edf394 100644
--- a/rust/bindings/wasm/ente-wasm/src/auth.rs
+++ b/rust/bindings/wasm/ente-wasm/src/auth.rs
@@ -39,7 +39,8 @@ impl From<ente_accounts::Error> for AccountsError {
E::InvalidKey(_) => "invalid_key",
E::Srp(_) => "srp",
E::InvalidInput(_) => "invalid_input",
- E::RateLimited => "rate_limited",
+ E::EmailVerificationRateLimited => "email_verification_rate_limited",
+ E::TotpRateLimited => "totp_rate_limited",
E::SecondFactorSessionExpired => "second_factor_session_expired",
E::MissingKeyAttributes => "missing_key_attributes",
E::AccountAlreadyExists => "account_already_exists",
@@ -164,6 +165,8 @@ impl GeneratedSrpSetup {
}
}
+/// `srp_attrs` must match the shape returned by the Ente API's
+/// `/users/srp/attributes` endpoint (i.e. camelCased fields).
#[wasm_bindgen]
pub fn auth_derive_srp_credentials(
password: &str,
@@ -241,6 +244,8 @@ pub fn auth_recovery_key_to_mnemonic(recovery_key_b64: &str) -> Result<String, A
auth::recovery_key_to_mnemonic(recovery_key_b64).map_err(Into::into)
}
+/// `key_attrs` should be the `keyAttributes` object from the auth response.
+/// `encrypted_token_b64` is the `encryptedToken` string from the auth response.
#[wasm_bindgen]
pub fn auth_decrypt_secrets(
kek_b64: &str,
diff --git a/rust/crates/accounts/src/error.rs b/rust/crates/accounts/src/error.rs
index c5910c493b..4c48a52063 100644
--- a/rust/crates/accounts/src/error.rs
+++ b/rust/crates/accounts/src/error.rs
@@ -41,16 +41,21 @@ pub enum Error {
#[error("Invalid input: {0}")]
InvalidInput(String),
- #[error("Too many attempts, please wait before retrying")]
- RateLimited,
+ #[error("Too many incorrect email verification attempts. Please wait and request a new code.")]
+ EmailVerificationRateLimited,
- #[error("Second factor session expired, restart login")]
+ #[error("Too many incorrect TOTP attempts. Please restart login.")]
+ TotpRateLimited,
+
+ #[error("Second factor session expired. Please restart login.")]
SecondFactorSessionExpired,
#[error("Account key attributes are not available")]
MissingKeyAttributes,
- #[error("Email already has server-side key state; log in to the existing account instead")]
+ #[error(
+ "Email already has server-side key state; use the existing account or recover the incomplete signup instead of creating a new account."
+ )]
AccountAlreadyExists,
#[error("{0}")]
diff --git a/rust/crates/accounts/src/flow.rs b/rust/crates/accounts/src/flow.rs
index d2b5c8dc48..86eec7339b 100644
--- a/rust/crates/accounts/src/flow.rs
+++ b/rust/crates/accounts/src/flow.rs
@@ -367,8 +367,7 @@ where
.ok_or(Error::MissingKeyAttributes)?
};
- let recovery_key =
- get_recovery_key(&params.master_key, &key_attributes)?;
+ let recovery_key = get_recovery_key(&params.master_key, &key_attributes)?;
let secret = self.client.setup_two_factor().await?;
self.ui
@@ -737,7 +736,7 @@ where
resent = false;
}
Err(error) if error.is_http_status(&[429]) => {
- return Err(Error::RateLimited);
+ return Err(Error::EmailVerificationRateLimited);
}
Err(error) if error.is_http_status(&[410]) => {
self.client
@@ -783,7 +782,7 @@ where
.report_retryable_error("Incorrect TOTP code. Try again.")?;
}
Err(error) if error.is_http_status(&[429]) => {
- return Err(Error::RateLimited);
+ return Err(Error::TotpRateLimited);
}
Err(error) if error.is_http_status(&[404, 410]) => {
return Err(Error::SecondFactorSessionExpired);
@@ -1358,7 +1357,7 @@ mod tests {
.unwrap_err();
match error {
- Error::RateLimited => {}
+ Error::EmailVerificationRateLimited => {}
other => panic!("unexpected error: {other:?}"),
}
assert!(ui.retryable_errors.is_empty());
@@ -1526,7 +1525,7 @@ mod tests {
.unwrap_err();
match error {
- Error::RateLimited => {}
+ Error::TotpRateLimited => {}
other => panic!("unexpected error: {other:?}"),
}
assert!(ui.retryable_errors.is_empty());