Author SHA1 Message Date
sneak 88a6ce5b6b README: name only the password the server refuses
check / check (push) Successful in 3m13s
The README said every wrong password prints "incorrect email or
password". With email verification on, quak never sends the password
to the server: a wrong one fails while unlocking the keys and prints
the decryption error instead.

Model: opus-5-5
2026-11-19 07:21:33 +00:00
sneak 41d3e6f72f quak login: do not call an account without SRP attributes missing
check / check (push) Successful in 5m14s
The Ente server answers /users/srp/attributes with 404 and the code
NOT_FOUND when the account exists but has no SRP attributes, and with
404 and {} when no account has the email. Both were reported as "no
account with this email on the server". Only a 404 whose JSON body has
no code is named that way now.

Model: opus-5-5
2026-11-19 07:04:39 +00:00
sneak 6e361ace8a quak login: say in words why the login failed (closes #244)
check / check (push) Successful in 8m39s
A password the server refuses (401 from /users/srp/verify-session) now
fails with "incorrect email or password". An email the server has no
account for (404 with a JSON body from /users/srp/attributes) fails with
"no account with this email on the server". The error stays an ApiError
with the same status. A 404 without JSON, as from a server address that
is not an Ente server, keeps the bare "HTTP 404".

Model: opus-5-5
2026-11-19 06:46:20 +00:00
clawbot 2492946e9d quak login --server: log in to a self-hosted Ente server (closes #243)
check / check (push) Successful in 5m0s
`quak login` takes the server's API address from `--server` or
`QUAK_SERVER`. `isServerAddress` refuses anything but an http or https
URL with no query or fragment, there and in `Client.fromJSON`. The
client's snapshot keeps a non-default `apiOrigin`, so the session file
names the server and every later command uses it.

Two servers can give two accounts, and two files, the same ID. A
self-hosted account's default cache directory therefore names the
server, and `metadata.json` records it: `Library.open` deletes a cache
from another server whole. `originalOf` and `thumbnailOf` record the
account in a cache that names none before storing a file, and `open`
treats a cache with no collection as empty. This fixes
#254 (closes #254).

Model: opus-5-5
2026-11-13 22:57:49 +01:00
3 changed files with 132 additions and 19 deletions

No files matched your search

+7 -2
View File
@@ -276,8 +276,13 @@ factor at that point, login fails.
On success it logs `Logged in as <email> (user <id>)` and On success it logs `Logged in as <email> (user <id>)` and
`Session saved to <path>`. On failure it logs `Login failed: <reason>`, and the `Session saved to <path>`. On failure it logs `Login failed: <reason>`, and the
exit status is 1. `login` is the only command that prompts, and its prompts go exit status is 1. Two reasons are given in words:
to stdout.
- a password the server refuses: `Login failed: incorrect email or password`
- an email with no account on the server:
`Login failed: no account with this email on the server`
`login` is the only command that prompts, and its prompts go to stdout.
#### `quak whoami` #### `quak whoami`
+45 -11
View File
@@ -1,5 +1,5 @@
import { SRP, SrpClient } from "fast-srp-hap"; import { SRP, SrpClient } from "fast-srp-hap";
import type { ApiClient } from "../api/client.js"; import { ApiError, type ApiClient } from "../api/client.js";
import { deriveKEK, deriveLoginSubkey, fromBase64 } from "../crypto/index.js"; import { deriveKEK, deriveLoginSubkey, fromBase64 } from "../crypto/index.js";
import type { import type {
AuthorizationResponse, AuthorizationResponse,
@@ -10,6 +10,14 @@ import type {
// Ente uses the 4096-bit SRP group. Both client and server must agree. // Ente uses the 4096-bit SRP group. Both client and server must agree.
const SRP_PARAMS = SRP.params["4096"]; const SRP_PARAMS = SRP.params["4096"];
// The same error, with a message that says in words what the server refused.
const withMessage = (err: ApiError, message: string): ApiError =>
new ApiError(message, err.status, {
code: err.code,
requestID: err.requestID,
body: err.body,
});
// Wrap fast-srp-hap's callback-based genKey into a Promise. // Wrap fast-srp-hap's callback-based genKey into a Promise.
const genKey = (): Promise<Buffer> => SRP.genKey(); const genKey = (): Promise<Buffer> => SRP.genKey();
@@ -63,13 +71,20 @@ const srpHandshake = async (
srpClient.setB(Buffer.from(srpB, "base64")); srpClient.setB(Buffer.from(srpB, "base64"));
const srpM1 = srpClient.computeM1().toString("base64"); const srpM1 = srpClient.computeM1().toString("base64");
const verifyResponse = await api.postJSON< type VerifyResponse = AuthorizationResponse & { srpM2: string };
AuthorizationResponse & { srpM2: string } let verifyResponse: VerifyResponse;
>("/users/srp/verify-session", { try {
sessionID, verifyResponse = await api.postJSON<VerifyResponse>(
srpUserID: srpAttributes.srpUserID, "/users/srp/verify-session",
srpM1, { sessionID, srpUserID: srpAttributes.srpUserID, srpM1 },
}); );
} catch (err) {
// The server answers 401 when the password does not match.
if (err instanceof ApiError && err.status === 401) {
throw withMessage(err, "incorrect email or password");
}
throw err;
}
srpClient.checkM2(Buffer.from(verifyResponse.srpM2, "base64")); srpClient.checkM2(Buffer.from(verifyResponse.srpM2, "base64"));
@@ -101,9 +116,28 @@ export const beginLogin = async (
email: string, email: string,
password: string, password: string,
): Promise<LoginChallenge> => { ): Promise<LoginChallenge> => {
const { attributes } = await api.getJSON<{ let attributes: SRPAttributes;
attributes: SRPAttributes; try {
}>("/users/srp/attributes", { email }); ({ attributes } = await api.getJSON<{ attributes: SRPAttributes }>(
"/users/srp/attributes",
{ email },
));
} catch (err) {
// The Ente server answers 404 with `{}` when no account has the email.
// It answers 404 with the code NOT_FOUND when the account exists but
// has no SRP attributes. A server address that points somewhere else
// answers 404 without JSON. Those two errors stay as they are.
if (
err instanceof ApiError &&
err.status === 404 &&
typeof err.body === "object" &&
err.body !== null &&
err.code === undefined
) {
throw withMessage(err, "no account with this email on the server");
}
throw err;
}
if (attributes.isEmailMFAEnabled) { if (attributes.isEmailMFAEnabled) {
return { kind: "emailOTP" }; return { kind: "emailOTP" };
+80 -6
View File
@@ -30,7 +30,7 @@
import sodium from "libsodium-wrappers-sumo"; import sodium from "libsodium-wrappers-sumo";
import { SRP, SrpServer } from "fast-srp-hap"; import { SRP, SrpServer } from "fast-srp-hap";
import { beforeAll, describe, expect, it } from "vitest"; import { beforeAll, describe, expect, it } from "vitest";
import { ApiClient } from "../../src/api/client.js"; import { ApiClient, ApiError } from "../../src/api/client.js";
import { import {
init, init,
toBase64, toBase64,
@@ -142,10 +142,15 @@ const buildServerFixture = async (password: string) => {
* *
* @param fixture The server fixture from buildServerFixture * @param fixture The server fixture from buildServerFixture
* @param opts.requireTOTP If true, verify-session returns a 2FA challenge * @param opts.requireTOTP If true, verify-session returns a 2FA challenge
* @param opts.unknownEmail If true, the server has no account with the email
*/ */
const buildMockFetch = ( const buildMockFetch = (
fixture: Awaited<ReturnType<typeof buildServerFixture>>, fixture: Awaited<ReturnType<typeof buildServerFixture>>,
opts?: { requireTOTP?: boolean; requirePasskeyAndTOTP?: boolean }, opts?: {
requireTOTP?: boolean;
requirePasskeyAndTOTP?: boolean;
unknownEmail?: boolean;
},
) => { ) => {
let srpServer: SrpServer; let srpServer: SrpServer;
const sessionID = "test-session-id"; const sessionID = "test-session-id";
@@ -163,7 +168,15 @@ const buildMockFetch = (
const parsed = new URL(url); const parsed = new URL(url);
const path = parsed.pathname; const path = parsed.pathname;
// The Ente server answers its refusals with an empty JSON object.
const refusal = (status: number) =>
new Response("{}", {
status,
headers: { "content-type": "application/json" },
});
if (path === "/users/srp/attributes") { if (path === "/users/srp/attributes") {
if (opts?.unknownEmail) return refusal(404);
return new Response( return new Response(
JSON.stringify({ attributes: fixture.srpAttributes }), JSON.stringify({ attributes: fixture.srpAttributes }),
{ {
@@ -197,7 +210,11 @@ const buildMockFetch = (
if (path === "/users/srp/verify-session") { if (path === "/users/srp/verify-session") {
const body = JSON.parse(init?.body as string); const body = JSON.parse(init?.body as string);
srpServer.checkM1(Buffer.from(body.srpM1, "base64")); try {
srpServer.checkM1(Buffer.from(body.srpM1, "base64"));
} catch {
return refusal(401);
}
const M2 = srpServer.computeM2(); const M2 = srpServer.computeM2();
// IMPORTANT: the museum server's EmailAuthorizationResponse // IMPORTANT: the museum server's EmailAuthorizationResponse
@@ -365,13 +382,70 @@ describe("beginLogin via SRP", () => {
} }
}); });
it("rejects a wrong password (SRP M1 verification fails)", async () => { it("says a wrong password is incorrect (SRP M1 verification fails)", async () => {
const fixture = await buildServerFixture(TEST_PASSWORD); const fixture = await buildServerFixture(TEST_PASSWORD);
const api = new ApiClient({ fetch: buildMockFetch(fixture) }); const api = new ApiClient({ fetch: buildMockFetch(fixture) });
const err = await beginLogin(api, TEST_EMAIL, "wrong password").catch(
(e: unknown) => e,
);
expect(err).toBeInstanceOf(ApiError);
expect((err as ApiError).message).toBe("incorrect email or password");
expect((err as ApiError).status).toBe(401);
});
it("says the server has no account with an unknown email", async () => {
const fixture = await buildServerFixture(TEST_PASSWORD);
const api = new ApiClient({
fetch: buildMockFetch(fixture, { unknownEmail: true }),
});
const err = await beginLogin(api, TEST_EMAIL, TEST_PASSWORD).catch(
(e: unknown) => e,
);
expect(err).toBeInstanceOf(ApiError);
expect((err as ApiError).message).toBe(
"no account with this email on the server",
);
expect((err as ApiError).status).toBe(404);
});
// The Ente server's answer for an account that has no SRP attributes.
it("does not call an account with no SRP attributes missing", async () => {
const api = new ApiClient({
fetch: (async () =>
new Response(
JSON.stringify({ code: "NOT_FOUND", message: "" }),
{
status: 404,
headers: { "content-type": "application/json" },
},
)) as typeof globalThis.fetch,
});
const err = await beginLogin(api, TEST_EMAIL, TEST_PASSWORD).catch(
(e: unknown) => e,
);
expect(err).toBeInstanceOf(ApiError);
expect((err as ApiError).code).toBe("NOT_FOUND");
expect((err as ApiError).message).not.toBe(
"no account with this email on the server",
);
});
// A server address that points somewhere other than an Ente server.
it("keeps the bare status of a 404 that is not JSON", async () => {
const api = new ApiClient({
fetch: (async () =>
new Response("404 page not found", {
status: 404,
headers: { "content-type": "text/plain" },
})) as typeof globalThis.fetch,
});
await expect( await expect(
beginLogin(api, TEST_EMAIL, "wrong password"), beginLogin(api, TEST_EMAIL, TEST_PASSWORD),
).rejects.toThrow(); ).rejects.toThrow(/^HTTP 404$/);
}); });
}); });