fix(lite): lock/unlock parity — shared attempt-lockout, immediate unlock state, no dead PIN, surfaced encrypt failure

Lite-parity audit, FIX C (gating/validation/presentation only — no encrypt/unlock/send backend call changed):
- Lite unlock went straight to the backend with no lockout. New App::unlockLiteWallet() runs the SAME
  escalating, persisted attempt-lockout as the full node (restoreLockoutState/applyUnlockFailure), wired into
  the Settings unlock, the send-time prompt and the lock screen. A wrong-passphrase failure counts; an
  already-unlocked/not-encrypted result does not.
- state_.locked is now cleared immediately on a successful unlock (the ~2s status poll lagged, so the UI
  stayed "locked" after a correct passphrase).
- PIN quick-unlock controls are hidden in lite Settings — lite has no PIN vault, so they were dead.
- A create/restore whose passphrase encryption FAILS now raises a one-shot visible error
  (takeEncryptionFailureNotice -> lite_encrypt_failed_unencrypted) instead of only a log line; the wallet is
  left open but unencrypted. Fixed the flag on BOTH the lifecycle and the direct create/restore encrypt paths.
- A background sync save is skipped while an encrypted wallet is unlocked (the backend save re-locks it),
  resuming once locked.

Compile- and unit-verified (testLiteWalletControllerLockUnlockParity covers the save-deferral + encrypt-failure
notice, run twice for the flaky guard); the lock-screen lockout/PIN-hiding UX itself is runtime/GUI-only and
not exercised here — worth a manual lite GUI pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 15:33:28 -05:00
co-authored by Claude Opus 4.8
parent 0cb1df3bfe
commit 16a1ca02e8
10 changed files with 199 additions and 10 deletions
+63
View File
@@ -5427,6 +5427,69 @@ bool App::lockLiteWallet()
return ok;
}
bool App::unlockLiteWallet(std::string passphrase, std::string* err)
{
const auto fail = [&](const std::string& m) { if (err) *err = m; };
const auto waitMsg = [](long long secs) {
char msg[128];
snprintf(msg, sizeof(msg), TR("sec_too_many_attempts_wait"), (double)secs);
return std::string(msg);
};
if (!lite_wallet_ || !lite_wallet_->walletOpen() || passphrase.empty()) {
wallet::secureWipeLiteSecret(passphrase);
fail(TR("lite_unlock_failed"));
return false; // nothing to attempt: not a wrong-credential failure, not counted
}
// Restore the persisted attempt count once per session (the full-node lock screen does the same).
if (!lock_state_restored_) {
lock_state_restored_ = true;
restoreLockoutState();
}
// Enforce the lockout from the persisted wall-clock expiry: lite has no per-frame lockout timer.
if (settings_ && settings_->getLockStateWallet() == settings_->getActiveWalletFile()) {
const long long remaining = settings_->getLockoutUntilEpoch() - (long long)std::time(nullptr);
if (remaining > 0) {
wallet::secureWipeLiteSecret(passphrase);
fail(waitMsg(remaining));
return false;
}
}
lock_lockout_timer_ = 0.0f; // expired: don't let a stale in-memory value re-arm the curve
const bool ok = lite_wallet_->unlockWallet(std::move(passphrase)); // wipes the passphrase
if (!ok) {
const auto st = lite_wallet_->encryptionStatus();
if (st.ok && !(st.encrypted && st.locked)) {
// Not a wrong credential: already unlocked (e.g. a racing prompt) or not encrypted. Don't count it.
state_.encrypted = st.encrypted;
state_.locked = false;
if (st.encrypted) { idle_.noteActivity(); return true; }
fail(TR("lite_unlock_failed"));
return false;
}
applyUnlockFailure(TR("lite_unlock_failed")); // bump counter, arm lockout curve, persist
fail(lock_lockout_timer_ > 0.0f ? waitMsg((long long)std::ceil(lock_lockout_timer_))
: std::string(TR("lite_unlock_failed")));
return false;
}
// Success: clear the attempt state (and its persisted copy) and reflect the unlock NOW — the next poll lags.
lock_unlock_in_progress_ = false;
lock_error_msg_.clear();
lock_attempts_ = 0;
lock_lockout_timer_ = 0.0f;
if (settings_ && settings_->getLockFailedAttempts() != 0) {
settings_->setLockFailedAttempts(0);
settings_->setLockoutUntilEpoch(0);
settings_->save();
}
memset(lock_passphrase_buf_, 0, sizeof(lock_passphrase_buf_));
idle_.noteActivity();
state_.encrypted = true;
state_.locked = false;
return true;
}
bool App::seedChatDemoData()
{
if (!chat::hushChatFeatureEnabledAtBuild()) return false;