Skip to content

Generate a random salt when a page is encrypted before the salt is known - #633

Open
LucaCappelletti94 wants to merge 1 commit into
sqlcipher:prereleasefrom
LucaCappelletti94:upstream/zero-salt-after-size-hint
Open

LucaCappelletti94 wants to merge 1 commit into
sqlcipher:prereleasefrom
LucaCappelletti94:upstream/zero-salt-after-size-hint

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

A new database reads its salt from the first 16 bytes of the file and falls back to random bytes only when that read fails. The read happens when page 1 is first encrypted, after pager_write_pagelist has sent SQLITE_FCNTL_SIZE_HINT. A VFS that grows the file on that hint, like the unix VFS with SQLITE_FCNTL_CHUNK_SIZE or the browser opfs-sahpool VFS, makes the read return zeros, so every new database gets the same all-zero salt.

This generates the salt when a page is encrypted before the salt is known. A connection decrypts page 1 of an existing database before writing to it, so this only happens for a new file. Existing databases still read the salt from the header. beta has the same code.

@sjlombardo

Copy link
Copy Markdown
Member

This will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants