groue / GRDB.swift

A toolkit for SQLite databases, with a focus on application development
MIT License
6.88k stars 708 forks source link

Suggested change to support SQLite Encryption Extension #506

Closed barnettben closed 5 years ago

barnettben commented 5 years ago

I am building GRDBCustomSQLite so that I can use the SQLite Encryption Extension (for which I have purchased a license).

Unfortunately, GRDB appears to not support this and only supports SQLCipher for encrypted databases.

Using SQLite-SEE, my custom build has defined the preprocessor macro SQLITE_HAS_CODEC.

When this is defined, GRDB attempts to validate that SQLCipher has been correctly linked.

In this case however, we don't want to perform validation as the custom SQLite build has taken care of encryption duties.

I would like to request that we adjust this following section of code to allow support for custom SQLite-SEE builds. I am happy to offer a pull request with changes/doc updates if that would help.

My suggestion would be to change occurrences of:

#if SQLITE_HAS_CODEC

to

#if SQLITE_HAS_CODEC && !GRDB_SQLITE_SEE

Then if we want to use a custom build of SQLite-SEE, we can define GRDB_SQLITE_SEE in the .xcconfig files and will bypass the SQLCipher check.

If the extra macro is not defined, then there is no impact on existing users.

GRDB flavor(s): GRDBCustom GRDB version: v3.7 Installation method: Manual Xcode version: 10.2 Swift version: 5 Platform(s) running GRDB: iOS/macOS **macOS version running Xcode: 10.14.4

groue commented 5 years ago

Hello @benrb,

You have well explained your trouble.

I know that the current GRDB code tests both SQLITE_HAS_CODEC and GRDBCIPHER identifiers, and not always in the correct way, as you have noticed.

I would be happy to review a pull request that cleans up this situation.

barnettben commented 5 years ago

Thank you for the response. I now have a local version which appears to work with the encryption extension which I can push to my fork and open a pull request for initial review. It has the basics working and passes the same tests as the SQLCipher version (but updated with slightly different API).

Do you still want it based off the development branch? I have been working with Swift 5/Xcode 10.2 so perhaps it is best to base it on the GRDB-4.0 branch? Which is better for you?

groue commented 5 years ago

@benrb I would be glad with your pull request! And as you have noticed, GRDB 4 is on the way. Yes, the GRDB-4.0 branch is the perfect target 👍

groue commented 5 years ago

Discussion has moved to #509.