fix(auth)!: proofs are bound to the instance's whole base URL

SRP's identity and the recovery phrase's proof carried the host alone, so
instances on one host under another port, path or scheme could relay each
other's proofs (the full reading's device low 4). Both now carry the base
URL the device addresses, written alike on both sides
(canonicalInstanceUrl: scheme and host in lower case, the port only where
it isn't the scheme's own, the path ending in /); the register takes its
own public scheme, host and port (Serverpod serves at the root), a member
the URL it names, development anything.

The identity also gains a purpose and the digest of what a proof sets,
both empty so far (signing in), with the framing for a new phrase's and an
authenticator's digest beside the new password's: the owner's proofs bind
them next. Cross-tests hold both sides to the same bytes. OwnerProof's and
DeletionProof's host, and every endpoint's, become instanceUrl.

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-21 13:59:32 +02:00
commit 1ad5d84110
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -189,8 +189,8 @@ void main() {
test(
"signs the key proof with the phrase's own proof key, whose public "
"half the setup carries, for the instance's host and the password it "
"sets: never the account's key, which a signed-in device keeps",
"half the setup carries, for the instance's base URL and the password "
"it sets: never the account's key, which a signed-in device keeps",
() async {
final challenge = protocol.KeyProofChallenge(
challenge: protocol.UuidValue.fromString(
@ -211,20 +211,20 @@ void main() {
final signature = await crypto.signKeyProof(
account.phrase,
challenge,
host: 'learn.halkyon.eu',
instanceUrl: 'https://learn.halkyon.eu/',
password: password,
);
final sodium = await SodiumSumoInit.init();
bool verifies(
Uint8List publicKey, {
String host = 'learn.halkyon.eu',
String instanceUrl = 'https://learn.halkyon.eu/',
List<int>? digest,
}) => sodium.crypto.sign.verifyDetached(
message: srp.keyProofMessage(
challenge.challenge.toBytes(),
List.filled(32, 9),
host: host,
instanceUrl: instanceUrl,
purpose: srp.KeyProofPurpose.passwordReset,
digest:
digest ??
@ -246,13 +246,16 @@ void main() {
final proofKey = Uint8List.sublistView(account.setup.recoveryProofKey);
expect(verifies(proofKey), isTrue);
expect(verifies(account.keys.signingPublicKey), isFalse);
expect(verifies(proofKey, host: 'learn.evil.example'), isFalse);
expect(
verifies(proofKey, instanceUrl: 'https://learn.evil.example/'),
isFalse,
);
expect(verifies(proofKey, digest: List.filled(32, 0)), isFalse);
await expectLater(
crypto.signKeyProof(
'not a phrase',
challenge,
host: 'learn.halkyon.eu',
instanceUrl: 'https://learn.halkyon.eu/',
),
throwsA(
isA<PasswordFailed>().having(
@ -298,7 +301,7 @@ void main() {
]),
),
),
host: 'learn.halkyon.eu',
instanceUrl: 'https://learn.halkyon.eu/',
);
expect(answer.clientValue.lengthInBytes, group.length);