2shady4u / godot-sqlite

GDExtension wrapper for SQLite (Godot 4.x+)
MIT License
895 stars 79 forks source link

Add database encryption/decryption #23

Closed 2shady4u closed 3 weeks ago

2shady4u commented 3 years ago

As requested by @MrSmite and many others, database encryption/decryption seems to be a much requested feature.

Work on this feature will be done on following branch: https://github.com/2shady4u/godot-sqlite/tree/godot-sqleet

Contained on this branch is a minimum (and rudimentary) viable product using SQLeet. Work on this feature will resume after other priority features (BLOBs, parameter bindings and database buffering) are completed.

Open questions/isues (mostly for myself):

MrSmite commented 3 years ago

For people who may want to compile this branch, here is an important note from sqleet of a use case where opening the database will fail even if the password is correct. This feature can be disabled at compile time.

I broke up the quote so the bolded pieces would stand out better. Bold in a markdown quote isn't very bold.

https://github.com/resilar/sqleet#example

Note:

In sqleet, the contents of an encrypted database file are indistinguishable from random data (of the same length). This is a conscious design decision,

but as a drawback, database settings cannot be read from the database file. Therefore, it is the user's responsibility to properly initialize database settings before accessing the database.

The most common issue is that opening a database fails regardless of valid key because the page size of the database differs from the default 4096 and page_size has not been set to the correct value with PRAGMA or URI API.

The official SQLite Encryption Extension (SEE) leaves bytes 16..23 of the database header unencrypted so that page size and other settings can be directly read from encrypted databases, which obviously makes SEE-encrypted databases distinguishable from random data. In sqleet,

this behavior can be optionally enabled with -DSKIP_HEADER_BYTES=24 compile-time flag

(bytes 0..15 contain the KDF salt so only the bytes 16..23 are actually skipped and left unencrypted).

At run-time, the compile-time default can be overridden with URI parameter skip=n where n is the skip amount.

2shady4u commented 3 years ago

Added SQLeet as a submodule and did a proper definition of the SQLITE_HAS_CODEC flag.

MrSmite commented 3 years ago

Thanks for the update. I haven't had much chance to test it though but it looks promising.

2shady4u commented 3 years ago

Implemented compilation flag for skipping header bytes (SKIP_HEADER_BYTES=24) to avoid failure to open database due to wrong settings.

Also updated the source files to be compatible with latest master.

hidemat commented 2 years ago

Hi. Sorry to bother you, and please tell me if I'm out of line, but how goes merging of Sqleet and Fst5 to the main branch?

2shady4u commented 2 years ago

Hey @hidemat! Sorry about my inactivity regarding the encryption and virtual table implementation. I was burned-out on this project for several months and am slowly getting back into the vibe.

Currently I'm focusing development on porting the plugin to Godot 4.0 so that its ready whenever Godot 4.0 releases for real.

Regarding the implementation of encryption and virtual table implementation, I would have to get back up-to-date with what I did and what I was still planning to do.

There have been several issues that make/made this merge difficult:

I'm sorry for promising this features and then not delivering 🙏

hidemat commented 2 years ago

I understand, thanks for the update. I've been looking into forking the repo and getting the binaries from Github actions, but I have no clue how to run the workflows once I have forked the repositories and enabled-fts5. It makes me dizzy, I guess I'll keep trying to figure this out.

EDIT: OHHHH I think I figured it out. It runs on a "on: push" event. So I had to enable the workflows in the actions tab and THEN push to the repo. (Duh)

Looking forward to the Godot 4 port. Best of luck.

xEstebanSalgadox commented 9 months ago

:'c

arabgamedev commented 2 months ago

when you add encryption?

2shady4u commented 3 weeks ago

Hello everyone,

Due to lack of time, I won't be able to work on adding encryption in the near future. SQLeet is currently unmaintained (and might abandoned) due to changes in the latest versions of SQLite.

If you need encryption please check out the following fork of this project: https://github.com/abcjjy/godot-sqlcipher