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

How to integrate SQLite3MultipleCiphers with RSQLite ? #137

Closed
JeremyPasco opened this issue Jan 2, 2024 · 3 comments
Closed

How to integrate SQLite3MultipleCiphers with RSQLite ? #137

JeremyPasco opened this issue Jan 2, 2024 · 3 comments

Comments

@JeremyPasco
Copy link

Hello,
I'm trying to integrate SQLite3MultipleCiphers into the R package RSQLite (package issue: r-dbi/RSQLite#484) but I think I miss some part of the picture.
As I understand, RSQLite use the amalgation source code of SQLite right now. I managed to replace it with the amalgation source code of SQLite3MultipleCiphers and to recompile the package without error.

The idea behind was that, maybe, the current R <--> C binding of the RSQLite package with SQLite would be enough to handle SQLite3MultipleCiphers.

But then, PRAGMA statements don't trigger encryption, DB is still in plain text. Am I missing something? Is there some bindings or other dev I should do to make it work?

@utelle
Copy link
Owner

utelle commented Jan 2, 2024

I'm trying to integrate SQLite3MultipleCiphers into the R package RSQLite (package issue: r-dbi/RSQLite#484) but I think I miss some part of the picture. As I understand, RSQLite use the amalgation source code of SQLite right now. I managed to replace it with the amalgation source code of SQLite3MultipleCiphers and to recompile the package without error.

In principle, the SQLite3 Multiple Ciphers amalgamation source code can be used as a drop-in replacement for the official SQLite amalgamation source code. However, usually you need to specify some extra preprocessor symbols to make it work as you expect.

Without knowing which C preprocessor symbols you defined for compiling the source code, it is hard to tell whether the resulting library works as expected or not.

The idea behind was that, maybe, the current R <--> C binding of the RSQLite package with SQLite would be enough to handle SQLite3MultipleCiphers.

Again, in principle, it should not require any special handling, except for specifying the relevant URI parameters or executing the corresponding PRAGMA statements.

But then, PRAGMA statements don't trigger encryption, DB is still in plain text. Am I missing something? Is there some bindings or other dev I should do to make it work?

Well, your description is too vague for analyzing the problem, unfortunately.

  1. If you want to create a new encrypted database, you will have to execute a PRAGMA key='passphrase' statement before accessing (reading or writing) any data in the database.
  2. If you try to open an existing non-empty plain database, and execute a PRAGMA key='passphrase' statement, you will get errors like "file is not a database" when accessing the database file.
  3. If you want to encrypt an existing non-empty database, you will have to execute PRAGMA rekey='passphrase' to actually encrypt the database file.
  4. If you want to use a non-default cipher scheme, you have to set the cipher scheme parameters before executing PRAGMA key='passphrase'.

In principle, all encryption parameters can be set via the database URI. However, I don't know how the R SQLite interface handles URI parameters. If they are passed unchanged to the SQLite open function, then SQLite3 Multiple Ciphers will handle them properly. However, if the R SQLite interface performs other activities before SQLite3 Multiple Ciphers gets a chance to handle the URI parameters, this may explain your problems.

@JeremyPasco
Copy link
Author

Thank you for your quick reply. As I am not a C developper, I feared that I could have missed some low level integration detail.
RSQLite already had C preprocessor working well with SQLite but doesn't handle URI parameters.

I just missed a compilation error with AES needing some compilation flag. Once fixed, PRAGMA statements work as intended through RSQLite + SQLite3MultiCiphers.
Thanks a lot for your amazing work!

@utelle
Copy link
Owner

utelle commented Jan 3, 2024

As I am not a C developper, I feared that I could have missed some low level integration detail. RSQLite already had C preprocessor working well with SQLite but doesn't handle URI parameters.

Enabling URI parameters in SQLite makes it usually a lot easier to configure non-default ciphers for SQLite3 Multiple Ciphers, because you don't need to explicitly perform separate PRAGMA statements in a specific order.

I just missed a compilation error with AES needing some compilation flag. Once fixed, PRAGMA statements work as intended through RSQLite + SQLite3MultiCiphers.

Glad to hear that.

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

No branches or pull requests

2 participants