fix(keys): a device refuses Argon2id costs beyond the register's ceiling

PasswordKdf.fromJson refused costs below the floor but took any above it,
so an instance could ask a device for 100 GiB and crash the app at every
sign-in. It now refuses more than the register's own ceiling (16 passes,
1 GiB; KeyRefusal.excessivePasswordKdf), and the app reads either refusal,
before deriving or sending anything, as PasswordProblem.unsafeCosts with
a text of its own (before, costs below the floor read as keys missing).

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 20:04:37 +02:00
commit e126e1d4fb
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -43,6 +43,32 @@ void main() {
signingPublicKey: account.keys.signingPublicKey,
);
test("refuses costs an instance mustn't ask for, before deriving "
'anything: below the floor, or beyond what a device can spare', () async {
for (final costs in [
protocol.PasswordCosts(
algorithm: 'argon2id13',
opsLimit: 1,
memLimit: 8 * 1024 * 1024,
),
protocol.PasswordCosts(
algorithm: 'argon2id13',
opsLimit: 3,
memLimit: 100 * 1024 * 1024 * 1024,
),
]) {
await expectLater(
crypto.unlock(
'correct horse battery staple',
salt: Uint8List.sublistView(account.setup.salt),
costs: costs,
),
failsWith(PasswordProblem.unsafeCosts),
reason: '${costs.memLimit}',
);
}
});
test('a new account: what the register takes, its keys opening with the '
'password on another device, the verifier made of the same x', () async {
final setup = account.setup;