Skip to content
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

Make sqlite database upgradabale and crypto-agile #124

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

simo5
Copy link
Member

@simo5 simo5 commented Dec 4, 2024

Add metadata to the sqlite database that allows for easier crypto agility as well as allow future upgrades. Move all non-object information to a metadata table.

Fixes #109

@simo5 simo5 marked this pull request as draft December 4, 2024 23:18
@simo5 simo5 force-pushed the verformat branch 4 times, most recently from 0e38432 to d4bd38e Compare December 10, 2024 00:10
doc/storage-encryption.md Outdated Show resolved Hide resolved
doc/storage-encryption.md Outdated Show resolved Hide resolved
src/storage/format.rs Outdated Show resolved Hide resolved
src/storage/sqlite.rs Outdated Show resolved Hide resolved
doc/storage-encryption.md Show resolved Hide resolved
@simo5 simo5 force-pushed the verformat branch 5 times, most recently from 077482a to f848663 Compare December 10, 2024 20:08
@simo5 simo5 marked this pull request as ready for review December 10, 2024 20:13
Copy link
Contributor

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
By any chance, did you test this change with pkcs11-provider locally to make sure this works correctly and we wont break the CI?

src/storage/aci.rs Outdated Show resolved Hide resolved
@simo5
Copy link
Member Author

simo5 commented Dec 11, 2024

Looks good. By any chance, did you test this change with pkcs11-provider locally to make sure this works correctly and we wont break the CI?

Yes I always make a run with pkcs11-provider locally to ensure changes actually work in a backwards compatible way.
pkcs11-provider CI more than once caught things.

Adds a new metadat table named meta.
Sets a database version in this table to allow for future
upgrades/backwards compatibility functions.

Moves token info from a fake object to metadata storage.

Signed-off-by: Simo Sorce <[email protected]>
The database Encryption Key is now stored as the ASN.1 Encoding of the
KProtectedData structure, which contains all the data to reversibly
derive t Key Encryption Key from the pin using PBKDF2 and then encrypt
the Encryption Key with this KEK using AES GCM.

This structure allows us to be crypto agile, as the derivation function
and the encryption function are identified by the OIDs stored in this
ASN.1 Structure, and therefore the data is fully self described so that
a future change can be done while maintaining the ability to
interoperate with pre-existing databases.

Signed-off-by: Simo Sorce <[email protected]>
Implement the data encryption layer explained in the document added in
the previoud commit.

Specifically make the EK be a generic key and then derive individual AES
keys from it via an HKDF Expand step before encrypting the actual data.

Signed-off-by: Simo Sorce <[email protected]>
No need for object gimmicks, just keep a copy of the struct and remove a
bunch of now useless attributes.

Signed-off-by: Simo Sorce <[email protected]>
Insted of using a complex pkcs#11 object, save user PIN and counters
in the metadata table. Enhance the ACI Authentication Info structure
to carry all of the user data and streamline all related operations.

Signed-off-by: Simo Sorce <[email protected]>
Change these two databases to properly handle the move of token and user
info out of the database objects space.

Signed-off-by: Simo Sorce <[email protected]>
@simo5
Copy link
Member Author

simo5 commented Dec 11, 2024

Rebased on main, and fixed the typo in the comment.
Thanks for the review, will merge once all tests pass.

@simo5 simo5 merged commit b09c082 into latchset:main Dec 11, 2024
19 checks passed
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.

Change decryption key storage format
2 participants