fix(backup): read nothing shorter than a ciphertext as needing a key

The shortest value either codec writes is 40 base64 characters. A
shorter string under an ...Encrypted member is not ciphertext, and
reading it as a legacy value would have made a restore demand the v1
key for a field that holds none.
This commit is contained in:
Marc-André Bombeck committed 2026-09-26 20:41:52 +02:00
1 parent 7da778760e
commit 94aa7c6bd4
2 files changed
+13 -4

No files matched your search

@@ -77,9 +77,12 @@ describe("innerCiphertextKeyId", () => {
expect(innerCiphertextKeyId(legacy)?.keyId).toBe("v1");
});
it("ignores an empty value and one that is not base64", () => {
it("ignores an empty value, a short one, and one that is not base64", () => {
expect(innerCiphertextKeyId("")).toBeNull();
expect(innerCiphertextKeyId("not ciphertext at all!")).toBeNull();
expect(innerCiphertextKeyId("yes")).toBeNull();
expect(
innerCiphertextKeyId("not ciphertext at all, and long enough to count!"),
).toBeNull();
});
});
@@ -122,7 +125,9 @@ describe("assessBackupKeys", () => {
useKeys({ old: K1, cur: K2 }, "cur");
const file = {
moodEntries: [{ noteEncrypted: bytesString("fine") }],
appSettings: { adminAiKeyEncrypted: "gone.QUJDRA==" },
appSettings: {
adminAiKeyEncrypted: `gone.${Buffer.alloc(40).toString("base64")}`,
},
};
const collector = new BackupKeyIdCollector();
collector.visit(file);