fix(keys): new passwords have at least 12 characters

The register can't check a password it never sees, and should its
database leak, the verifier and the keys wrapped under the password fall
to guessing at Argon2id's cost (the second reading's M8). Devices now
refuse a new password shorter than 12 characters, counted as code points
once normalised (halkyon_keys' checkNewPassword), at sign-up, a reset
keeping the keys and a change alike, before anything is derived; the new
password's field says so, and the refusal has its own text (en, de).
Signing in takes any length, so a password set before keeps working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-20 21:25:47 +02:00
commit b33b99a50a
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
13 changed files with 216 additions and 29 deletions

View file

@ -206,5 +206,7 @@
"passwordInstanceUnproven": "Die Instanz konnte nicht beweisen, dass sie dein Passwort kennt, daher vertraut dieses Gerät ihr nicht. Versuch es noch einmal; passiert es wieder, ist die Instanz nicht die, die sie zu sein behauptet.",
"passwordKeysMissing": "Die Schlüssel deines Kontos sind nicht auf diesem Gerät. Melde dich hier ab und mit deinem Passwort wieder an.",
"passwordUnsafeCosts": "Die Instanz wollte dein Passwort auf eine Weise prüfen lassen, die kein Konto nutzt, daher wurde nichts gesendet. Passiert es wieder, ist die Instanz nicht die, die sie zu sein behauptet.",
"passwordFailed": "Die Instanz war nicht erreichbar. Prüf die Verbindung und versuch es noch einmal."
"passwordFailed": "Die Instanz war nicht erreichbar. Prüf die Verbindung und versuch es noch einmal.",
"passwordMinLength": "Mindestens {count} Zeichen",
"passwordTooShort": "Ein neues Passwort braucht mindestens {count} Zeichen: Sollte die Datenbank der Instanz je nach außen gelangen, wird ein kurzes zuerst erraten."
}

View file

@ -432,5 +432,21 @@
"passwordInstanceUnproven": "The instance couldn't prove it knows your password, so this device trusts nothing it says. Try again; if it happens again, the instance isn't the one it claims to be.",
"passwordKeysMissing": "Your account's keys aren't on this device. Sign out and in again with your password here.",
"passwordUnsafeCosts": "The instance asked for your password to be checked in a way no account uses, so nothing was sent. If it happens again, the instance isn't the one it claims to be.",
"passwordFailed": "Couldn't reach the instance. Check the connection and try again."
"passwordFailed": "Couldn't reach the instance. Check the connection and try again.",
"passwordMinLength": "At least {count} characters",
"@passwordMinLength": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"passwordTooShort": "A new password needs at least {count} characters: should the instance's database ever leak, a short one is guessed first.",
"@passwordTooShort": {
"placeholders": {
"count": {
"type": "int"
}
}
}
}

View file

@ -1344,6 +1344,18 @@ abstract class HalkyonAppLocalizations {
/// In en, this message translates to:
/// **'Couldn\'t reach the instance. Check the connection and try again.'**
String get passwordFailed;
/// No description provided for @passwordMinLength.
///
/// In en, this message translates to:
/// **'At least {count} characters'**
String passwordMinLength(int count);
/// No description provided for @passwordTooShort.
///
/// In en, this message translates to:
/// **'A new password needs at least {count} characters: should the instance\'s database ever leak, a short one is guessed first.'**
String passwordTooShort(int count);
}
class _HalkyonAppLocalizationsDelegate

View file

@ -773,4 +773,14 @@ class HalkyonAppLocalizationsDe extends HalkyonAppLocalizations {
@override
String get passwordFailed =>
'Die Instanz war nicht erreichbar. Prüf die Verbindung und versuch es noch einmal.';
@override
String passwordMinLength(int count) {
return 'Mindestens $count Zeichen';
}
@override
String passwordTooShort(int count) {
return 'Ein neues Passwort braucht mindestens $count Zeichen: Sollte die Datenbank der Instanz je nach außen gelangen, wird ein kurzes zuerst erraten.';
}
}

View file

@ -756,6 +756,16 @@ class HalkyonAppLocalizationsEn extends HalkyonAppLocalizations {
@override
String get passwordFailed =>
'Couldn\'t reach the instance. Check the connection and try again.';
@override
String passwordMinLength(int count) {
return 'At least $count characters';
}
@override
String passwordTooShort(int count) {
return 'A new password needs at least $count characters: should the instance\'s database ever leak, a short one is guessed first.';
}
}
/// The translations for English, as used in the United Kingdom (`en_GB`).

View file

@ -149,6 +149,7 @@ class SodiumAccountCrypto() implements AccountCrypto {
UnlockedAccountKeys keys,
) => Isolate.run(
() => _guarded(() async {
checkNewPassword(password);
final sodium = await SodiumSumoInit.init();
final opened = _keysOf(sodium, keys);
final salt = _own(newPasswordSalt(sodium));
@ -287,15 +288,20 @@ PasswordKdf _kdfOf(protocol.PasswordCosts costs) {
}
}
/// What [step] gives, a password libsodium can't take ([PasswordRefused])
/// refused as [PasswordProblem.passwordUnusable] and keys that don't
/// rebuild as [PasswordProblem.keysMissing]: on the isolate, so the
/// refusal that crosses back is a `PasswordFailed`.
/// What [step] gives, a password that can't be taken ([PasswordRefused])
/// refused as [PasswordProblem.passwordTooShort] or
/// [PasswordProblem.passwordUnusable] and keys that don't rebuild as
/// [PasswordProblem.keysMissing]: on the isolate, so the refusal that
/// crosses back is a `PasswordFailed`.
Future<T> _guarded<T>(Future<T> Function() step) async {
try {
return await step();
} on PasswordRefused {
throw const PasswordFailed(PasswordProblem.passwordUnusable);
} on PasswordRefused catch (refused) {
throw PasswordFailed(switch (refused.reason) {
PasswordRefusal.tooShort => PasswordProblem.passwordTooShort,
PasswordRefusal.empty ||
PasswordRefusal.controlCharacter => PasswordProblem.passwordUnusable,
});
} on KeyRefused {
throw const PasswordFailed(PasswordProblem.keysMissing);
}
@ -309,6 +315,7 @@ NewAccountMaterial _material(
AccountKeys keys, {
required String phrase,
}) {
checkNewPassword(password);
final salt = _own(newPasswordSalt(sodium));
final unlocked = derivePasswordKeys(sodium, password: password, salt: salt);
final SecureKey recoveryKey;

View file

@ -87,6 +87,9 @@ enum PasswordProblem() {
/// The password can't be used: empty, or with control characters.
passwordUnusable,
/// A new password is shorter than halkyon_keys' `newPasswordMinLength`.
passwordTooShort,
/// The instance couldn't prove it knows the password (SRP's M2), or its
/// keys don't open: nothing it said is trusted.
instanceUnproven,

View file

@ -173,6 +173,7 @@ class _AccountRecoveryState() extends State<_AccountRecovery> {
PasswordField(
controller: _password,
label: l10n.passwordNewPassword,
showsMinimum: true,
isNew: true,
enabled: enabled,
),

View file

@ -277,6 +277,7 @@ class _ChangePasswordState() extends State<_ChangePassword> {
PasswordField(
controller: _new,
label: l10n.passwordNewPassword,
showsMinimum: true,
isNew: true,
),
const SizedBox(height: 8),

View file

@ -194,6 +194,7 @@ class _AccountSetupState() extends State<_AccountSetup> {
PasswordField(
controller: _password,
label: l10n.passwordNewPassword,
showsMinimum: true,
isNew: true,
enabled: enabled,
autofocus: true,

View file

@ -1,5 +1,6 @@
import 'package:halkyon_app/l10n/halkyon_app_localizations.dart';
import 'package:halkyon_app/src/password/model/password_failed.dart';
import 'package:halkyon_keys/halkyon_keys.dart' show newPasswordMinLength;
import 'package:intl/intl.dart';
import 'package:material_ui/material_ui.dart';
@ -42,6 +43,9 @@ String passwordProblemText(BuildContext context, PasswordFailed failed) {
PasswordProblem.notAPhrase => l10n.passwordNotAPhrase,
PasswordProblem.phraseDoesNotFit => l10n.passwordPhraseDoesNotFit,
PasswordProblem.passwordUnusable => l10n.passwordUnusable,
PasswordProblem.passwordTooShort => l10n.passwordTooShort(
newPasswordMinLength,
),
PasswordProblem.instanceUnproven => l10n.passwordInstanceUnproven,
PasswordProblem.unsafeCosts => l10n.passwordUnsafeCosts,
PasswordProblem.keysMissing => l10n.passwordKeysMissing,

View file

@ -6,6 +6,7 @@ import 'package:halkyon_app/l10n/halkyon_app_localizations.dart';
import 'package:halkyon_app/src/app/app_scope.dart';
import 'package:halkyon_app/src/password/model/account_authenticator.dart';
import 'package:halkyon_app/src/password/model/phrase_check.dart';
import 'package:halkyon_keys/halkyon_keys.dart' show newPasswordMinLength;
import 'package:halkyon_ui/halkyon_ui.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:material_ui/material_ui.dart';
@ -24,6 +25,9 @@ class const PasswordField({
final bool enabled = true,
final bool autofocus = false,
final bool isNew = false,
/// Whether the field says how long a new password must be.
final bool showsMinimum = false,
final TextInputAction textInputAction = TextInputAction.next,
final ValueChanged<String>? onSubmitted,
super.key,
@ -62,6 +66,9 @@ class _PasswordFieldState() extends State<PasswordField> {
context,
InputDecoration(
labelText: widget.label,
helperText: widget.showsMinimum
? l10n.passwordMinLength(newPasswordMinLength)
: null,
errorText: widget.errorText,
suffixIcon: IconButton(
tooltip: _shown ? l10n.passwordHide : l10n.passwordShow,

View file

@ -92,6 +92,14 @@ class FakeAccountCrypto() implements AccountCrypto {
}
}
/// As the device checks a new password: at least 12 characters.
static void _checkNew(String password) {
_check(password);
if (password.runes.length < 12) {
throw const PasswordFailed(PasswordProblem.passwordTooShort);
}
}
NewAccountMaterial _material(
String password,
UnlockedAccountKeys keys,
@ -113,7 +121,7 @@ class FakeAccountCrypto() implements AccountCrypto {
@override
Future<NewAccountMaterial> newAccount(String password) async {
_check(password);
_checkNew(password);
return _material(password, keysNumbered(10 * ++_accounts), fakePhrase);
}
@ -123,7 +131,7 @@ class FakeAccountCrypto() implements AccountCrypto {
UnlockedAccountKeys keys, {
required String phrase,
}) async {
_check(password);
_checkNew(password);
return _material(password, keys, phrase);
}
@ -171,7 +179,7 @@ class FakeAccountCrypto() implements AccountCrypto {
String password,
UnlockedAccountKeys keys,
) async {
_check(password);
_checkNew(password);
return protocol.NewPassword(
salt: ByteData(16),
costs: _costs,