-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for SQLCipher #1109
base: master
Are you sure you want to change the base?
Conversation
3100022
to
34e1e85
Compare
tried it, it works well. |
@jgiannuzzi I tried it as well, and it works flawlessly! Thank you for the tremendous job. |
@jgiannuzzi It is maintained pretty well, and updates are released almost every month. But honestly, I'm not sure how good it is compared to |
@rittneje I'm okay to add this feature into go-sqlite3. any thought? |
It seems not great to force people to download 2 gigantic C files when they only ever need (at most) one, especially in CI/CD cases. I wonder if there is a way to treat this more like libsqlite3, where we can somehow link against an external C library? Then only people that care about SQLCipher (which seems pretty niche, given typical use cases for SQLite) have to download the second giant C file. (And that can even be in a totally separate repo.) |
As an alternate perspective, might 'perfect' be the enemy of 'good' here? Perhaps @jgiannuzzi 's patch could be a stepping stone to something more optimal in the future, if the additional large C file does become problematic? |
@damoclark It would have to be supported forever because of backwards compatibility. |
@rittneje Supported yes, but that doesn't mean the implementation can't change. Like changing from the sqlite preferred amalgamation method for sqlcipher to linking with an external library as you suggested. Or am I completely misunderstanding the build process proposed? |
This is definitely what i was looking for. Hopefully it will soon to be merged. Thanks for your hardwork! |
We really need encryption feature. will we have it any time soon? |
@rittneje This is already possible in my proposed change ( As @7fold suggested above, another way to go may be to use SQLite3MultipleCiphers which seems really well-maintained, supports more ciphers than SQLCipher (whilst being compatible with it), does not depend on a separate crypto library, and seems to be consistently keeping up with new SQLite3 releases. I would be happy to update this PR or create another one where the SQLite3MC amalgamation would replace the SQLite3 one. Thoughts? |
I have created a branch that supports SQLite3MultipleCiphers: |
+1 thanks for jgiannuzzi for the branch. go mod edit -replace="github.com/mattn/go-sqlite3=github.com/jgiannuzzi/go-sqlite3@sqlite3mc" Reference: https://github.com/jgiannuzzi/go-sqlite3/tree/sqlite3mc |
Hey @rittneje and @mattn, what are your thoughts on this? I would really like to add encryption support to go-sqlite3 and it looks like there is a bit of demand for it based on the various issues created over time and the reactions to this PR. How can we move forward with this? |
@jgiannuzzi The debate over SQLCipher vs. SQLite3MultipleCiphers only solidifies my earlier point - I do not believe it belongs in this library. Really there is a generic desire to allow linking against a custom/external build of SQLite. (See also #1153 #1150.) At the moment I am not sure how to make that work well in the confines of cgo. Is that something you'd be able to look into? I assume with that in place there would be no need of forking anymore. |
Hey @rittneje and @mattn, would you mind taking a second look at my SQLite3MultipleCiphers branch? Here is a comparison to help you see what I changed. This should solve the issue you had with the 2 "gigantic" C files, as this essentially augments the original SQLite implementation. SQLite3MultipleCiphers has a great track record of keeping up-to-date with SQLite and has a very clean architecture that aims at minimising patching. I would really like to avoid making users link to a custom build or having to use a fork of go-sqlite3, especially for a feature that seems quite popular! |
@jgiannuzzi @mattn I used the branch of github.com/mutecomm/go-sqlcipher before, but its new version does not support enough, and the database cannot be recognized. That old version has the problem of memory overflow when executing large-volume DB files. Those above problems were solved by @jgiannuzzi, thanks a lot. I also think that sqlcipher should be part of the sqlite base library. Developers can easily read and write encrypted databases without looking for other solutions. Using this branch, I successfully connected to the Wechat client database, and share the method with you: go.mod
db.go
Hope to merge as soon as possible, there is no need to replace package |
How is this haven't merge to the master brand? |
Migrated from github.com/glebarez/sqlite to gorm.io/driver/sqlite (which uses github.com/mattn/go-sqlite3) Override github.com/mattn/go-sqlite3 with forked version from @jgiannuzzi which supports Encryption at rest. See mattn/go-sqlite3#1109 See #236 Added documentation for how to open an encrypted sqlite database in IntelliJ - CONTRIBUTING.md update
I'd like to thank @jgiannuzzi for his hard work, and confirm that his branch works as a drop-in replacement for mattn/go-sqlite3 when used with Gorm. @gainskills and @ellermister's DSN string example was also incredibly helpful. Baking encryption-at-rest into this library would be an incredibly powerful feature. As someone who's built a number of apps ontop of SQLite, 50% or more would have benefited from the additional security, and my most recent tool - Fasten Health requires it since its a open-source personal health record with access to all your private medical information. Pointing to the sqlite.org source-code and saying "see, they don't bake in the SQLite Encryption Extension, so we shouldn't either" ignores the fact that they have artificially segmented their user base to sell an add-on in order to build a sustainable business -- which is completely within their rights. It doesn't mean that we need to live under the same handicap with this port of SQLite. Personally I migrated to mattn/go-sqlite3 only because of @jgiannuzzi -- and just the possibility of this PR getting merged. |
Migrated from github.com/glebarez/sqlite to gorm.io/driver/sqlite (which uses github.com/mattn/go-sqlite3) Override github.com/mattn/go-sqlite3 with forked version from @jgiannuzzi which supports Encryption at rest. See mattn/go-sqlite3#1109 See #236 Added documentation for how to open an encrypted sqlite database in IntelliJ - CONTRIBUTING.md update
Thank you @jgiannuzzi for you effort. I really appreciate it. Gonna use your branch for my use-case 🚀 |
For anyone interested in my
|
Please merge, this is a big win for Go developers using sqlite |
this is one of the most important features that will definitely benefit so many apps, services, developers, and users forward. thanks to @jgiannuzzi for this! Encryption, though might not be considered that important in decades ago, has been indispensable now, especially for database on the cloud. It would be undoubtedly great if this could be merged. Thanks! @mattn |
please merge =) want to use |
Yes, can we get this merged asap? We want to use this in a project asap. Is there anything we can do to help get this merged? |
please merge =) want to use |
+1 for merging this |
+1 for merging, it would be very helpful |
please merge! |
Great stuff, thank you. I got this working with litestream. |
please merge i beg you @mattn |
It has been more than a year, is there a reason that this is still not merged? |
@rittneje Have you solved what you thought as the problem above? |
@jgiannuzzi Does this work with VACUUM INTO? |
Thank you @jgiannuzzi for your hard work. Really hoping this gets merged 👍 |
build linux arm64 on amd64 error github.com/mattn/go-sqlite3sqlcipher-binding.c:110873:10: fatal error: 'openssl/crypto.h' file not found |
@labulakalia could you please try my other branch, as referenced here: #1109 (comment) |
thanks,it works @jgiannuzzi |
This PR adds support for SQLCipher whilst keeping the existing embedded sqlite3 implementation. The support is enabled via the
sqlcipher
andlibsqlcipher
build tags, which respectively use the embedded SQLCipher implementation or link directly to libsqlcipher.An upgrade script has been added to automate the inclusion of new versions of SQLCipher.
I believe that adding this support would benefit the Go ecosystem, as multiple unmaintained repos have flourished that are forks of this repo bolting on support for older versions of SQLCipher. Having support here would enable gorm users to benefit from the encryption feature without having to patch anything.