|
| 1 | +go-sqlite3-sqlcipher fork |
| 2 | +========================= |
| 3 | + |
| 4 | +This repository is a fork of [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) |
| 5 | +that adds SQLCipher support. The Go module path remains |
| 6 | +`github.com/mattn/go-sqlite3` so existing imports continue to work with a |
| 7 | +`replace` directive. |
| 8 | + |
| 9 | +Replace the module with this fork: |
| 10 | + |
| 11 | +```go |
| 12 | +require github.com/mattn/go-sqlite3 v1.14.47 |
| 13 | + |
| 14 | +replace github.com/mattn/go-sqlite3 => github.com/BitBoxSwiss/go-sqlite3-sqlcipher <version> |
| 15 | +``` |
| 16 | + |
| 17 | +Build with the `sqlcipher` tag to use the embedded SQLCipher amalgamation: |
| 18 | + |
| 19 | +```sh |
| 20 | +go build -tags sqlcipher ./... |
| 21 | +``` |
| 22 | + |
| 23 | +The embedded `sqlcipher` tag uses these crypto providers: |
| 24 | + |
| 25 | +| Platform | Crypto provider | External runtime crypto dependency | |
| 26 | +| --- | --- | --- | |
| 27 | +| iOS/macOS | CommonCrypto via Apple frameworks | No | |
| 28 | +| Android | LibTomCrypt from the submodule source | No | |
| 29 | +| Linux | LibTomCrypt from the submodule source | No | |
| 30 | +| Windows | LibTomCrypt from the submodule source, with `advapi32` for RNG seeding | No OpenSSL DLL | |
| 31 | +| `libsqlcipher` tag | Determined by the linked external `libsqlcipher` | Depends on that library | |
| 32 | + |
| 33 | +Initialize the LibTomCrypt submodule when working on the fork: |
| 34 | + |
| 35 | +```sh |
| 36 | +git submodule update --init |
| 37 | +``` |
| 38 | + |
| 39 | +The fork checks in generated LibTomCrypt binding files under |
| 40 | +`internal/libtomcrypt` so downstream `go mod vendor` users can build with |
| 41 | +`-mod=vendor` without initializing this submodule. |
| 42 | + |
| 43 | +This fork is based on the original work by Yasuhiro Matsumoto and the |
| 44 | +`mattn/go-sqlite3` contributors. SQLCipher support is based on |
| 45 | +[PR #1109](https://github.com/mattn/go-sqlite3/pull/1109) by |
| 46 | +[jgiannuzzi](https://github.com/jgiannuzzi). |
| 47 | + |
1 | 48 | go-sqlite3 |
2 | 49 | ========== |
3 | 50 |
|
@@ -41,9 +88,12 @@ This package follows the official [Golang Release Policy](https://golang.org/doc |
41 | 88 | - [macOS](#mac-osx) |
42 | 89 | - [Windows](#windows) |
43 | 90 | - [Errors](#errors) |
44 | | -- [User Authentication](#user-authentication) |
| 91 | +- [Encryption](#encryption) |
45 | 92 | - [Compile](#compile) |
46 | 93 | - [Usage](#usage-1) |
| 94 | +- [User Authentication](#user-authentication) |
| 95 | + - [Compile](#compile-1) |
| 96 | + - [Usage](#usage-2) |
47 | 97 | - [Create protected database](#create-protected-database) |
48 | 98 | - [Password Encoding](#password-encoding) |
49 | 99 | - [Available Encoders](#available-encoders) |
@@ -106,11 +156,17 @@ Boolean values can be one of: |
106 | 156 | | Auto Vacuum | `_auto_vacuum` \| `_vacuum` | <ul><li>`0` \| `none`</li><li>`1` \| `full`</li><li>`2` \| `incremental`</li></ul> | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) | |
107 | 157 | | Busy Timeout | `_busy_timeout` \| `_timeout` | `int` | Specify value for sqlite3_busy_timeout. For more information see [PRAGMA busy_timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout) | |
108 | 158 | | Case Sensitive LIKE | `_case_sensitive_like` \| `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) | |
| 159 | +| Cipher Compatibility | `_cipher_compatibility` | `int` | For more information see [PRAGMA cipher_compatibility](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_compatibility) | |
| 160 | +| Cipher Migrate | `_cipher_migrate` | - | For more information see [PRAGMA cipher_migrate](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_migrate) | |
| 161 | +| Cipher Page Size | `_cipher_page_size` | `int` | For more information see [PRAGMA cipher_page_size](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) | |
| 162 | +| Cipher Plaintext Header Size | `_cipher_plaintext_header_size` | `int` | For more information see [PRAGMA cipher_plaintext_header_size](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_plaintext_header_size) | |
| 163 | +| Cipher Use HMAC | `_cipher_use_hmac` | `int` | For more information see [PRAGMA cipher_use_hmac](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_use_hmac) | |
109 | 164 | | Defer Foreign Keys | `_defer_foreign_keys` \| `_defer_fk` | `boolean` | For more information see [PRAGMA defer_foreign_keys](https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys) | |
110 | 165 | | Foreign Keys | `_foreign_keys` \| `_fk` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) | |
111 | 166 | | Ignore CHECK Constraints | `_ignore_check_constraints` | `boolean` | For more information see [PRAGMA ignore_check_constraints](https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints) | |
112 | 167 | | Immutable | `immutable` | `boolean` | For more information see [Immutable](https://www.sqlite.org/c3ref/open.html) | |
113 | 168 | | Journal Mode | `_journal_mode` \| `_journal` | <ul><li>DELETE</li><li>TRUNCATE</li><li>PERSIST</li><li>MEMORY</li><li>WAL</li><li>OFF</li></ul> | For more information see [PRAGMA journal_mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) | |
| 169 | +| Encryption Key | `_key` | `string` | Sets the database encryption key to use with [SQLCipher](https://github.com/sqlcipher/sqlcipher). For more information see [PRAGMA key](https://www.zetetic.net/sqlcipher/sqlcipher-api/#PRAGMA_key) |
114 | 170 | | Locking Mode | `_locking_mode` \| `_locking` | <ul><li>NORMAL</li><li>EXCLUSIVE</li></ul> | For more information see [PRAGMA locking_mode](https://www.sqlite.org/pragma.html#pragma_locking_mode) | |
115 | 171 | | Mode | `mode` | <ul><li>ro</li><li>rw</li><li>rwc</li><li>memory</li></ul> | Access Mode of the database. For more information see [SQLite Open](https://www.sqlite.org/c3ref/open.html) | |
116 | 172 | | Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. | |
@@ -350,6 +406,18 @@ For example the TDM-GCC Toolchain can be found [here](https://jmeubank.github.io |
350 | 406 | go install github.com/mattn/go-sqlite3 |
351 | 407 | ``` |
352 | 408 |
|
| 409 | +# Encryption |
| 410 | +
|
| 411 | +## Compile |
| 412 | +
|
| 413 | +To use the database encryption feature, the package has to be compiled with the tags `sqlcipher` (to use the built-in implementation) or `libsqlcipher` (to link directly to libsqlcipher). |
| 414 | +
|
| 415 | +The built-in implementation requires OpenSSL to be installed (`libssl-dev` or `openssl-devel` on Linux). It is not required on macOS, where CommonCrypto gets used and is part of the system. |
| 416 | +
|
| 417 | +### Usage |
| 418 | +
|
| 419 | +Pass your encryption key via the `_key` argument in the connection string. See the [SQLCipher documentation](https://www.zetetic.net/sqlcipher/sqlcipher-api/#PRAGMA_key) for more details. |
| 420 | +
|
353 | 421 | # User Authentication |
354 | 422 |
|
355 | 423 | ***This is deprecated*** |
@@ -594,6 +662,16 @@ The -binding suffix was added to avoid build failures under gccgo. |
594 | 662 |
|
595 | 663 | In this repository, those files are an amalgamation of code that was copied from SQLite3. The license of that code is the same as the license of SQLite3. |
596 | 664 |
|
| 665 | +sqlcipher-binding.c and sqlcipher-binding.h are an amalgamation of code that |
| 666 | +was copied from [SQLCipher](https://github.com/sqlcipher/sqlcipher). See |
| 667 | +[LICENSE.SQLCIPHER](./LICENSE.SQLCIPHER) for the SQLCipher copyright notice |
| 668 | +and license terms. |
| 669 | + |
| 670 | +internal/libtomcrypt contains generated files copied from |
| 671 | +[LibTomCrypt](https://github.com/sqlcipher/libtomcrypt). See |
| 672 | +[LICENSE.LIBTOMCRYPT](./LICENSE.LIBTOMCRYPT) for the LibTomCrypt license |
| 673 | +terms. |
| 674 | + |
597 | 675 | # Author |
598 | 676 |
|
599 | 677 | Yasuhiro Matsumoto (a.k.a mattn) |
|
0 commit comments