-
-
Notifications
You must be signed in to change notification settings - Fork 23
AES-XTS VFS #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AES-XTS VFS #171
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Go `xts` SQLite VFS | ||
|
||
This package wraps an SQLite VFS to offer encryption at rest. | ||
|
||
The `"xts"` VFS wraps the default SQLite VFS using the | ||
[AES-XTS](https://pkg.go.dev/golang.org/x/crypto/xts) | ||
tweakable and length-preserving encryption.\ | ||
In general, any XTS construction can be used to wrap any VFS. | ||
|
||
The default AES-XTS construction uses AES-128, AES-192, or AES-256 | ||
for its block cipher. | ||
Additionally, we use [PBKDF2-HMAC-SHA512](https://pkg.go.dev/golang.org/x/crypto/pbkdf2) | ||
to derive AES-128 keys from plain text where needed. | ||
File contents are encrypted in 512 byte sectors, matching the | ||
[minimum](https://sqlite.org/fileformat.html#pages) SQLite page size. | ||
|
||
The VFS encrypts all files _except_ | ||
[super journals](https://sqlite.org/tempfiles.html#super_journal_files): | ||
these _never_ contain database data, only filenames, | ||
and padding them to the sector size is problematic. | ||
Temporary files _are_ encrypted with **random** AES-128 keys, | ||
as they _may_ contain database data. | ||
To avoid the overhead of encrypting temporary files, | ||
keep them in memory: | ||
|
||
PRAGMA temp_store = memory; | ||
|
||
> [!IMPORTANT] | ||
> XTS is a cipher mode typically used for disk encryption. | ||
> The standard threat model for disk encryption considers an adversary | ||
> that can read multiple snapshots of a disk. | ||
> The only security property that disk encryption provides | ||
> is that all information such an adversary can obtain | ||
> is whether the data in a sector has or has not changed over time. | ||
|
||
The encryption offered by this package is fully deterministic. | ||
|
||
This means that an adversary who can get ahold of multiple snapshots | ||
(e.g. backups) of a database file can learn precisely: | ||
which sectors changed, which ones didn't, which got reverted. | ||
|
||
This is slightly weaker than other forms of SQLite encryption | ||
that include *some* nondeterminism; with limited nondeterminism, | ||
an adversary can't distinguish between | ||
sectors that actually changed, and sectors that got reverted. | ||
|
||
> [!CAUTION] | ||
> This package does not claim protect databases against tampering or forgery. | ||
|
||
The major practical consequence of the above point is that, | ||
if you're keeping `"xts"` encrypted backups of your database, | ||
and want to protect against forgery, you should sign your backups, | ||
and verify signatures before restoring them. | ||
|
||
This is slightly weaker than other forms of SQLite encryption | ||
that include page-level [MACs](https://en.wikipedia.org/wiki/Message_authentication_code). | ||
Page-level MACs can protect against forging individual pages, | ||
but can't prevent them from being reverted to former versions of themselves. | ||
|
||
> [!TIP] | ||
> The [`"adiantum"`](../adiantum/README.md) package also offers encryption at rest. | ||
> In general Adiantum performs significantly better, | ||
> and as a "wide-block" cipher, _may_ offer improved security. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.