Giter Club home page Giter Club logo

go-sqlcipher's Introduction

go-sqlcipher

Build Status

SQLCipher driver conforming to the built-in database/sql interface and using the latest sqlite3 code.

GoDoc Reference Build Status Coverage Status Go Report Card

NOTE: v2.0.1 or higher is unfortunatal release. So there are no big changes. And does not provide v2 feature.

Description

which is 3.31.0

Working with sqlcipher version which is 4.3.0

It's wrapper with

  • go-sqlite3 sqlite3 driver for go that using database/sql.
  • SQLCipher SQLCipher is an SQLite extension that provides 256 bit AES encryption of database files.
  • Using openssl as the 256 bit AES encryption.

Supported Golang version: See .travis.yml

This package follows the official Golang Release Policy.

Upgrade

Due to the go-sqlite3 project change its way to load the PRAGMA variables. Setting the encrypting key won't work for the existing database anymore. But you can load the encrypt key by setting with query parameter _key, like:

b, err = sql.Open("sqlite3", databasefile +"?_key=password")

To upgrade SQLCipher from 3.x to 4.x, please take a look of:

  1. https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_migrate
  2. Upgrading to SQLCipher 4

Overview

Installation

This package can be installed with the go get command:

go get github.com/xeodou/go-sqlcipher

go-sqlcipher is cgo package. If you want to build your app using go-sqlcipher, you need gcc. However, if you install go-sqlcipher with go install github.com/xeodou/go-sqlcipher, you don't need gcc to build your app anymore.

Important: because this is a CGO enabled package you are required to set the environment variable CGO_ENABLED=1 and have a gcc compile present within your path.

API Reference

API documentation can be found here: http://godoc.org/github.com/xeodou/go-sqlcipher

Examples can be found under the examples directory

Connection String

When creating a new SQLite database or connection to an existing one, with the file name additional options can be given. This is also known as a DSN string. (Data Source Name).

Options are append after the filename of the SQLite database. The database filename and options are seperated by an ? (Question Mark). Options should be URL-encoded (see url.QueryEscape).

This also applies when using an in-memory database instead of a file.

Options can be given using the following format: KEYWORD=VALUE and multiple options can be combined with the & ampersand.

This library supports dsn options of SQLite itself and provides additional options.

Boolean values can be one of:

  • 0 no false off
  • 1 yes true on
Name Key Value(s) Description
UA - Create _auth - Create User Authentication, for more information see User Authentication
UA - Username _auth_user string Username for User Authentication, for more information see User Authentication
UA - Password _auth_pass string Password for User Authentication, for more information see User Authentication
UA - Crypt _auth_crypt
  • SHA1
  • SSHA1
  • SHA256
  • SSHA256
  • SHA384
  • SSHA384
  • SHA512
  • SSHA512
Password encoder to use for User Authentication, for more information see User Authentication
UA - Salt _auth_salt string Salt to use if the configure password encoder requires a salt, for User Authentication, for more information see User Authentication
Auto Vacuum _auto_vacuum | _vacuum
  • 0 | none
  • 1 | full
  • 2 | incremental
For more information see PRAGMA auto_vacuum
Busy Timeout _busy_timeout | _timeout int Specify value for sqlite3_busy_timeout. For more information see PRAGMA busy_timeout
Case Sensitive LIKE _case_sensitive_like | _cslike boolean For more information see PRAGMA case_sensitive_like
Defer Foreign Keys _defer_foreign_keys | _defer_fk boolean For more information see PRAGMA defer_foreign_keys
Foreign Keys _foreign_keys | _fk boolean For more information see PRAGMA foreign_keys
Ignore CHECK Constraints _ignore_check_constraints boolean For more information see PRAGMA ignore_check_constraints
Immutable immutable boolean For more information see Immutable
Journal Mode _journal_mode | _journal
  • DELETE
  • TRUNCATE
  • PERSIST
  • MEMORY
  • WAL
  • OFF
For more information see PRAGMA journal_mode
Locking Mode _locking_mode | _locking
  • NORMAL
  • EXCLUSIVE
For more information see PRAGMA locking_mode
Mode mode
  • ro
  • rw
  • rwc
  • memory
Access Mode of the database. For more information see SQLite Open
Mutex Locking _mutex
  • no
  • full
Specify mutex mode.
Query Only _query_only boolean For more information see PRAGMA query_only
Recursive Triggers _recursive_triggers | _rt boolean For more information see PRAGMA recursive_triggers
Secure Delete _secure_delete boolean | FAST For more information see PRAGMA secure_delete
Shared-Cache Mode cache
  • shared
  • private
Set cache mode for more information see sqlite.org
Synchronous _synchronous | _sync
  • 0 | OFF
  • 1 | NORMAL
  • 2 | FULL
  • 3 | EXTRA
For more information see PRAGMA synchronous
Time Zone Location _loc auto Specify location of time format.
Transaction Lock _txlock
  • immediate
  • deferred
  • exclusive
Specify locking behavior for transactions.
Writable Schema _writable_schema Boolean When this pragma is on, the SQLITE_MASTER tables in which database can be changed using ordinary UPDATE, INSERT, and DELETE statements. Warning: misuse of this pragma can easily result in a corrupt database file.

DSN Examples

file:test.db?cache=shared&mode=memory

Features

This package allows additional configuration of features available within SQLite3 to be enabled or disabled by golang build constraints also known as build tags.

Click here for more information about build tags / constraints.

Please notice The userAuthentication extention is not support the library, since the SQLCipher is already let you create the encrypted database.

Usage

If you wish to build this library with additional extensions / features. Use the following command.

go build --tags "<FEATURE>"

If you want to build the project without the libcrypto, you could specific the openssl library by using the command.

CGO_ENABLE=1 CGO_LDFLAGS="-L/usr/local/opt/openssl/lib" CGO_CPPFLAGS="-I/usr/local/opt/openssl/include" go build _example/encrypto/encrypto.go

For available features see the extension list. When using multiple build tags, all the different tags should be space delimted.

Example:

go build --tags "icu json1 fts5 secure_delete"

Feature / Extension List

Extension Build Tag Description
Additional Statistics sqlite_stat4 This option adds additional logic to the ANALYZE command and to the query planner that can help SQLite to chose a better query plan under certain situations. The ANALYZE command is enhanced to collect histogram data from all columns of every index and store that data in the sqlite_stat4 table.

The query planner will then use the histogram data to help it make better index choices. The downside of this compile-time option is that it violates the query planner stability guarantee making it more difficult to ensure consistent performance in mass-produced applications.

SQLITE_ENABLE_STAT4 is an enhancement of SQLITE_ENABLE_STAT3. STAT3 only recorded histogram data for the left-most column of each index whereas the STAT4 enhancement records histogram data from all columns of each index.

The SQLITE_ENABLE_STAT3 compile-time option is a no-op and is ignored if the SQLITE_ENABLE_STAT4 compile-time option is used
Allow URI Authority sqlite_allow_uri_authority URI filenames normally throws an error if the authority section is not either empty or "localhost".

However, if SQLite is compiled with the SQLITE_ALLOW_URI_AUTHORITY compile-time option, then the URI is converted into a Uniform Naming Convention (UNC) filename and passed down to the underlying operating system that way
App Armor sqlite_app_armor When defined, this C-preprocessor macro activates extra code that attempts to detect misuse of the SQLite API, such as passing in NULL pointers to required parameters or using objects after they have been destroyed.

App Armor is not available under Windows.
Disable Load Extensions sqlite_omit_load_extension Loading of external extensions is enabled by default.

To disable extension loading add the build tag sqlite_omit_load_extension.
Foreign Keys sqlite_foreign_keys This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections.

Each database connection can always turn enforcement of foreign key constraints on and off and run-time using the foreign_keys pragma.

Enforcement of foreign key constraints is normally off by default, but if this compile-time parameter is set to 1, enforcement of foreign key constraints will be on by default
Full Auto Vacuum sqlite_vacuum_full Set the default auto vacuum to full
Incremental Auto Vacuum sqlite_vacuum_incr Set the default auto vacuum to incremental
Full Text Search Engine sqlite_fts5 When this option is defined in the amalgamation, versions 5 of the full-text search engine (fts5) is added to the build automatically
International Components for Unicode sqlite_icu This option causes the International Components for Unicode or "ICU" extension to SQLite to be added to the build
Introspect PRAGMAS sqlite_introspect This option adds some extra PRAGMA statements.
  • PRAGMA function_list
  • PRAGMA module_list
  • PRAGMA pragma_list
JSON SQL Functions sqlite_json When this option is defined in the amalgamation, the JSON SQL functions are added to the build automatically
Pre Update Hook sqlite_preupdate_hook Registers a callback function that is invoked prior to each INSERT, UPDATE, and DELETE operation on a database table.
Secure Delete sqlite_secure_delete This compile-time option changes the default setting of the secure_delete pragma.

When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.

The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.

On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information
Secure Delete (FAST) sqlite_secure_delete_fast For more information see PRAGMA secure_delete
Tracing / Debug sqlite_trace Activate trace functions
User Authentication sqlite_userauth SQLite User Authentication see User Authentication for more information.

Compilation

This package requires CGO_ENABLED=1 ennvironment variable if not set by default, and the presence of the gcc compiler.

If you need to add additional CFLAGS or LDFLAGS to the build command, and do not want to modify this package. Then this can be achieved by using the CGO_CFLAGS and CGO_LDFLAGS environment variables.

Android

This package can be compiled for android. Compile with:

go build --tags "android"

For more information see #201

ARM

To compile for ARM use the following environment.

env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
    CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 \
    go build -v

Additional information:

Cross Compile

This library can be cross-compiled.

In some cases you are required to the CC environment variable with the cross compiler.

Additional information:

Google Cloud Platform

Building on GCP is not possible because Google Cloud Platform does not allow gcc to be executed.

Please work only with compiled final binaries.

Linux

To compile this package on Linux you must install the development tools for your linux distribution.

To compile under linux use the build tag linux.

go build --tags "linux"

If you wish to link directly to libsqlite3 then you can use the libsqlite3 build tag.

go build --tags "libsqlite3 linux"

Alpine

When building in an alpine container run the following command before building.

apk add --update gcc musl-dev

Fedora

sudo yum groupinstall "Development Tools" "Development Libraries"

Ubuntu

sudo apt-get install build-essential

Mac OSX

OSX should have all the tools present to compile this package, if not install XCode this will add all the developers tools.

Required dependency

brew install sqlite3

For OSX there is an additional package install which is required if you wish to build the icu extension.

This additional package can be installed with homebrew.

brew upgrade icu4c

To compile for Mac OSX.

go build --tags "darwin"

If you wish to link directly to libsqlite3 then you can use the libsqlite3 build tag.

go build --tags "libsqlite3 darwin"

Additional information:

Windows

The golang code is copy from go-sqlite3 If you have some issue, maybe you can find from https://github.com/mattn/go-sqlite3/issues

Here is some help from go-sqlite3 project.

  • Want to build go-sqlite3 with libsqlite3 on my linux.
  1. Install a Windows gcc toolchain.
  2. Add the bin folders to the Windows path if the installer did not do this by default.
  3. Open a terminal for the TDM-GCC toolchain, can be found in the Windows Start menu.
  4. Navigate to your project folder and run the go build ... command for this package.

For example the TDM-GCC Toolchain can be found here.

Errors

  • Compile error: can not be used when making a shared object; recompile with -fPIC

    When receiving a compile time error referencing recompile with -FPIC then you are probably using a hardend system.

    You can compile the library on a hardend system with the following command.

    go build -ldflags '-extldflags=-fno-PIC'

    More details see #120

  • Can't build go-sqlite3 on windows 64bit.

    Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit. See: mattn/go-sqlite3#27

  • go get github.com/mattn/go-sqlite3 throws compilation error.

    gcc throws: internal compiler error

    Remove the download repository from your disk and try re-install with:

    go install github.com/mattn/go-sqlite3

User Authentication

This package supports the SQLite User Authentication module.

Compile

To use the User authentication module the package has to be compiled with the tag sqlite_userauth. See Features.

Usage

Create protected database

To create a database protected by user authentication provide the following argument to the connection string _auth. This will enable user authentication within the database. This option however requires two additional arguments:

  • _auth_user
  • _auth_pass

When _auth is present on the connection string user authentication will be enabled and the provided user will be created as an admin user. After initial creation, the parameter _auth has no effect anymore and can be omitted from the connection string.

Example connection string:

Create an user authentication database with user admin and password admin.

file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin

Create an user authentication database with user admin and password admin and use SHA1 for the password encoding.

file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin&_auth_crypt=sha1

Password Encoding

The passwords within the user authentication module of SQLite are encoded with the SQLite function sqlite_cryp. This function uses a ceasar-cypher which is quite insecure. This library provides several additional password encoders which can be configured through the connection string.

The password cypher can be configured with the key _auth_crypt. And if the configured password encoder also requires an salt this can be configured with _auth_salt.

Available Encoders

  • SHA1
  • SSHA1 (Salted SHA1)
  • SHA256
  • SSHA256 (salted SHA256)
  • SHA384
  • SSHA384 (salted SHA384)
  • SHA512
  • SSHA512 (salted SHA512)

Restrictions

Operations on the database regarding to user management can only be preformed by an administrator user.

Support

The user authentication supports two kinds of users

  • administrators
  • regular users

User Management

User management can be done by directly using the *SQLiteConn or by SQL.

SQL

The following sql functions are available for user management.

Function Arguments Description
authenticate username string, password string Will authenticate an user, this is done by the connection; and should not be used manually.
auth_user_add username string, password string, admin int This function will add an user to the database.
if the database is not protected by user authentication it will enable it. Argument admin is an integer identifying if the added user should be an administrator. Only Administrators can add administrators.
auth_user_change username string, password string, admin int Function to modify an user. Users can change their own password, but only an administrator can change the administrator flag.
authUserDelete username string Delete an user from the database. Can only be used by an administrator. The current logged in administrator cannot be deleted. This is to make sure their is always an administrator remaining.

These functions will return an integer.

  • 0 (SQLITE_OK)
  • 23 (SQLITE_AUTH) Failed to perform due to authentication or insufficient privileges
Examples
// Autheticate user
// Create Admin User
SELECT auth_user_add('admin2', 'admin2', 1);

// Change password for user
SELECT auth_user_change('user', 'userpassword', 0);

// Delete user
SELECT user_delete('user');

*SQLiteConn

The following functions are available for User authentication from the *SQLiteConn.

Function Description
Authenticate(username, password string) error Authenticate user
AuthUserAdd(username, password string, admin bool) error Add user
AuthUserChange(username, password string, admin bool) error Modify user
AuthUserDelete(username string) error Delete user

Attached database

When using attached databases. SQLite will use the authentication from the main database for the attached database(s).

Extensions

If you want your own extension to be listed here or you want to add a reference to an extension; please submit an Issue for this.

Spatialite

Spatialite is available as an extension to SQLite, and can be used in combination with this repository. For an example see shaxbee/go-spatialite.

extension-functions.c from SQLite3 Contrib

extension-functions.c is available as an extension to SQLite, and provides the following functions:

  • Math: acos, asin, atan, atn2, atan2, acosh, asinh, atanh, difference, degrees, radians, cos, sin, tan, cot, cosh, sinh, tanh, coth, exp, log, log10, power, sign, sqrt, square, ceil, floor, pi.
  • String: replicate, charindex, leftstr, rightstr, ltrim, rtrim, trim, replace, reverse, proper, padl, padr, padc, strfilter.
  • Aggregate: stdev, variance, mode, median, lower_quartile, upper_quartile

For an example see dinedal/go-sqlite3-extension-functions.

FAQ

  • Getting insert error while query is opened.

    You can pass some arguments into the connection string, for example, a URI. See: #39

  • Do you want to cross compile? mingw on Linux or Mac?

    See: #106 See also: http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html

  • Want to get time.Time with current locale

    Use _loc=auto in SQLite3 filename schema like file:foo.db?_loc=auto.

  • Can I use this in multiple routines concurrently?

    Yes for readonly. But, No for writable. See #50, #51, #209, #274.

  • Why I'm getting no such table error?

    Why is it racy if I use a sql.Open("sqlite3", ":memory:") database?

    Each connection to ":memory:" opens a brand new in-memory sql database, so if the stdlib's sql engine happens to open another connection and you've only specified ":memory:", that connection will see a brand new database. A workaround is to use "file::memory:?cache=shared" (or "file:foobar?mode=memory&cache=shared"). Every connection to this string will point to the same in-memory database.

    Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the max idle connection limit is > 0, and the connection lifetime is infinite.

    For more information see

  • Reading from database with large amount of goroutines fails on OSX.

    OS X limits OS-wide to not have more than 1000 files open simultaneously by default.

    For more information see #289

  • Trying to execute a . (dot) command throws an error.

    Error: Error: near ".": syntax error Dot command are part of SQLite3 CLI not of this library.

    You need to implement the feature or call the sqlite3 cli.

    More information see #305

  • Error: database is locked

    You can ignore these messages.

    Example:

    db, err := sql.Open("sqlite3", "file:locked.sqlite?cache=shared")

    Second please set the database connections of the SQL package to 1.

    db.SetMaxOpenConns(1)

    More information see #209

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

MIT:

sqlite3-binding.c, sqlite3-binding.h, sqlite3ext.h

The -binding suffix was added to avoid build failures under gccgo.

In this repository, those files are amalgamation code that copied from SQLCipher. The license of those codes are depend on the license of SQLCipher.

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.

Original repository https://github.com/mattn/go-sqlite3 is under MIT.

Author

xeodou

go-sqlcipher's People

Contributors

a-p- avatar akalin avatar azavorotnii avatar bytbox avatar conorbranagan avatar cookieo9 avatar dajohi avatar danderson avatar egonelbre avatar gholt avatar gimpldo avatar gjrtimmer avatar jander avatar jgallagher avatar kenshaw avatar larsmans avatar mattn avatar mix3 avatar mjtrangoni avatar mstetson avatar otoolep avatar pwaller avatar rittneje avatar robertknight avatar shaxbee avatar t2y avatar tuxlinuxien avatar xeodou avatar zmedico avatar zombiezen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-sqlcipher's Issues

[build error] `_example/encrypto> go build` results in `sqlite3-binding.c:18401:12: error: storage size of ‘hctx’ isn’t known`

_example/encrypto> go build

github.com/xeodou/go-sqlcipher

../../sqlite3-binding.c: In function ‘sqlcipher_openssl_hmac’:
../../sqlite3-binding.c:18401:12: error: storage size of ‘hctx’ isn’t known
HMAC_CTX hctx;
^~~~
../../sqlite3-binding.c:18403:3: warning: implicit declaration of function ‘HMAC_CTX_init’ [-Wimplicit-function-declaration]
HMAC_CTX_init(&hctx);
^~~~~~~~~~~~~
../../sqlite3-binding.c:18408:3: warning: implicit declaration of function ‘HMAC_CTX_cleanup’ [-Wimplicit-function-declaration]
HMAC_CTX_cleanup(&hctx);
^~~~~~~~~~~~~~~~
../../sqlite3-binding.c: In function ‘sqlcipher_openssl_cipher’:
../../sqlite3-binding.c:18418:18: error: storage size of ‘ectx’ isn’t known
EVP_CIPHER_CTX ectx;
^~~~

Upgrade SQLite version

Hi @xeodou, there is a new version of SQLite released last month (3.31.1) and I was wondering if you can find time to upgrade. Thanks!

error: invalid argument type 'void' to unary expression

I am trying to compile go-sqlcipher as part of the hover project so that I can create Darwin packages of my app via the hover docker method. I modified the Dockerfile to have OpenSSL installed.

However, as soon as I try to get the build, I get this error:

github.com/xeodou/go-sqlcipher
# github.com/xeodou/go-sqlcipher
sqlite3-binding.c:24508:10: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24511:10: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24514:10: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24520:6: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24522:8: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24524:6: error: invalid argument type 'void' to unary expression
sqlite3-binding.c:24539:11: warning: implicit declaration of function 'PKCS5_PBKDF2_HMAC' is invalid in C99 [-Wimplicit-function-declaration]
11:53:34 build.go:457: hover: Go build failed: exit status 2

My command line is rather long so it is in a tiny shell script:

#!/bin/bash
docker run \
    --rm \
    --mount type=bind,source=/home/yann/worldr/github/desktop-app,target=/app \
    --mount type=bind,source=/home/yann/.cache/hover/engine,target=/root/.cache/hover/engine \
    --mount type=bind,source=/home/yann/.cache/hover/docker-go-cache,target=/go-cache \
    --env GOCACHE=/go-cache \
    --env HOVER_SAFE_CHOWN_UID=1000 \
    --env HOVER_SAFE_CHOWN_GID=1000 \
    --env GOPROXY=direct \
    --env GOPRIVATE= \
    my-desktop-app-builder \
    hover-safe.sh \
    build \
    --verbose \
    darwin-dmg \
    --skip-flutter-build-bundle \
    --skip-engine-d

Any idea what I am doing wrong?

undefined reference to `__imp_CertFreeCertificateContext'

//windows 10

github.com/xeodou/go-sqlcipher

D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0xe0): unde
fined reference to __imp_CertFreeCertificateContext' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x160): und efined reference to __imp_CertFreeCertificateContext'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x56f): und
efined reference to __imp_CertGetCertificateContextProperty' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0xafe): und efined reference to __imp_CertGetCertificateContextProperty'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0xc4e): und
efined reference to __imp_CertEnumCertificatesInStore' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0xd01): und efined reference to __imp_CertFindCertificateInStore'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2d50): un
defined reference to __imp_CertOpenStore' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2d80): un defined reference to __imp_CertEnumCertificatesInStore'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2e81): un
defined reference to __imp_CertDuplicateCertificateContext' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2eee): un defined reference to __imp_CertCloseStore'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2f8a): un
defined reference to __imp_CertFreeCertificateContext' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3610): un defined reference to __imp_CertOpenStore'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3655): un
defined reference to __imp_CertFreeCertificateContext' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3660): un defined reference to __imp_CertCloseStore'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3683): un
defined reference to __imp_CertEnumCertificatesInStore' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3782): un defined reference to __imp___acrt_iob_func'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3dc7): un
defined reference to __imp_CertOpenStore' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3e35): un defined reference to __imp_CertFreeCertificateContext'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3e40): un
defined reference to __imp_CertCloseStore' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3f69): un defined reference to __imp_CertFreeCertificateContext'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x4000): un
defined reference to __imp_CertFreeCertificateContext' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(eng_openssl.o):eng_openssl.c:(.text+0 x42): undefined reference to __imp___acrt_iob_func'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(eng_openssl.o):eng_openssl.c:(.text+0
x296): undefined reference to __imp___acrt_iob_func' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(ui_openssl.o):ui_openssl.c:(.text+0x1 9): undefined reference to __imp___acrt_iob_func'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(ui_openssl.o):ui_openssl.c:(.text+0x1
a4): undefined reference to __imp___acrt_iob_func' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(ui_openssl.o):ui_openssl.c:(.text+0x1 c7): undefined reference to __imp___acrt_iob_func'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xad): unde
fined reference to __imp_getnameinfo' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xde): unde fined reference to __imp_ntohs'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0x23b): und
efined reference to gai_strerrorW' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0x6f8): und efined reference to __imp_freeaddrinfo'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xb2e): und
efined reference to __imp_getaddrinfo' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xbf2): und efined reference to gai_strerrorW'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xd10): und
efined reference to __imp_getaddrinfo' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xdd2): und efined reference to gai_strerrorW'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xd5): unde
fined reference to __imp_WSAStartup' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xe3): unde fined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x28d): und
efined reference to __imp_WSAStartup' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x29b): und efined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x36d): und
efined reference to __imp_ntohs' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x3b3): und efined reference to __imp_getsockopt'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x3d2): und
efined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x3e3): und efined reference to __imp_gethostbyname'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x435): und
efined reference to __imp_WSAStartup' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x43f): und efined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4bd): und
efined reference to __imp_WSACleanup' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4db): und efined reference to __imp_ioctlsocket'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4f2): und
efined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x69d): und efined reference to __imp_WSAStartup'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x6ab): und
efined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x8c2): und efined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x945): und
efined reference to __imp_setsockopt' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x978): und efined reference to __imp_ioctlsocket'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x992): und
efined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x9f8): und efined reference to __imp_getsockname'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xa52): und
efined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x27): un defined reference to __imp_socket'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4a): un
defined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x106): u ndefined reference to __imp_setsockopt'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x135): u
ndefined reference to __imp_connect' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x16d): u ndefined reference to __imp_setsockopt'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x17b): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x223): u ndefined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x27a): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x2ff): u ndefined reference to __imp_bind'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x352): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x401): u ndefined reference to __imp_getsockopt'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x415): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4b7): u ndefined reference to __imp_setsockopt'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x53a): u
ndefined reference to __imp_listen' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x545): u ndefined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5b5): u
ndefined reference to __imp_setsockopt' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5c3): u ndefined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x640): u
ndefined reference to __imp_setsockopt' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x64e): u ndefined reference to __imp_WSAGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x6a2): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x726): u ndefined reference to __imp_accept'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x764): u
ndefined reference to __imp_WSAGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x7ba): u ndefined reference to __imp_closesocket'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x7c9): u
ndefined reference to __imp_closesocket' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1b6): undefined reference to __imp_WSASetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1c9): undefined reference to __imp_se nd' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1fc): undefined reference to __imp_WS
AGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x297): undefined reference to __imp_WS ASetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x2aa): undefined reference to __imp_se
nd'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x2dc): undefined reference to __imp_WS AGetLastError' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x350): undefined reference to __imp_WS
ASetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x363): undefined reference to __imp_re cv' D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x3c2): undefined reference to __imp_WS
AGetLastError'
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x48a): undefined reference to `__imp_WS
AGetLastError'
collect2.exe: error: ld returned 1 exit status

file is not a database

when I run the _example/encrypto.go twice it print the error:
file is not a database
the users.db has created, any body help, tks.

Upgrade SQLite and SQLCipher

Hi, @xeodou , thanks for your awesome library!

A newer version of SQLite and SQLCipher has been released. Can you upgrade it to latest version? If not, how can I upgrade it?

warning: 'OSAtomicCompareAndSwapPtrBarrier' is deprecated

warning: 'OSAtomicCompareAndSwapPtrBarrier' is deprecated: first deprecated in macOS 10.12 - Use atomic_compare_exchange_strong() from <stdatomic.h> instead [-Wdeprecated-declarations]
/usr/include/libkern/OSAtomicDeprecated.h:547:6: note: 'OSAtomicCompareAndSwapPtrBarrier' has been explicitly marked deprecated here

parameters to open with regular db browser

What parameters are required to open an encrypted db with sqlite browser?
Neither of the suggested options (Sqlcipher 3.x, 4.x or custom) seems to work
What is the specific AES256 algo, number of iterations, hmac algo and page size to use?

1 High and 1 Medium vulnerabilities detected when using an automatic vulnerability-detection tool

Context where the vulnerabilities are detected

Steps to reproduce:

Create a Hello World application importing xeodou/go-sqlcipher
Build the application
Scan the result with Black Duck Binary Analysis

Expected behavior:

No vulnerablities should be reported.

Actual behavior:

1 High and 1 Medium vulnerabilities are detected.

More details on the vulnerabilities:

High (CVE-2021-3119)

Zetetic SQLCipher 4.x before 4.4.3 has a NULL pointer dereferencing issue related to sqlcipher_export in crypto.c and sqlite3StrICmp in sqlite3.c. This may allow an attacker to perform a remote denial of service attack. For example, an SQL injection can be used to execute the crafted SQL command sequence, which causes a segmentation fault.

Medium (CVE-2020-27207)

Zetetic SQLCipher 4.x before 4.4.1 has a use-after-free, related to sqlcipher_codec_pragma and sqlite3Strlen30 in sqlite3.c. A remote denial of service attack can be performed. For example, a SQL injection can be used to execute the crafted SQL command sequence. After that, some unexpected RAM data is read.

Additional details

I know that you are not responsible, technically speaking,of the SQLCipher from Zetetic. I am just afraid that you are wrapping in Go, an outdated version of SQLCipher.

[PROVIDED] Manual for compile on Windows 64Bit

After some work hereby the manual for succesfull compilation on Windows 64 bit. ( Also for dummies )

OS: Windows 10
Arch: 64bit

This tutorial is based upon my own setup which means: I install development related programs within C:\Development

Also this tutorial assumes you have Go 1.8 64Bit setup correctly.
(By correctly I assume you have a GOPATH variable setup which points to a single directory)


1) Setup

1.1 Install Perl64bit
Go to ActiveState and download the latest Perl64, Windows Installer.
Install this to: C:\Development\Perl64 and make sure you check the checkbox within the installer for Add to Path.

1.2 Install TDM-GCC-64
Go to TDM-GCC-64 and download either the webdl or the tdm64 installer.
Install this to: C:\Development\TDM-GCC-64

1.3 Install MSYS
Go to [http://www.mingw.org/wiki/msys] and download the 1.0.11 MSYS.
Direct Download: http://downloads.sourceforge.net/mingw/MSYS-1.0.11.exe
Install this to C:\Development\MSYS

During the post install it will ask for the MINGW location: enter the following: C:\Development\TDM-GCC-64 The post install will detect several files and if all oke it will also gives you the message that it can not find make within TDM-GCC-64 and that you should keep it like this.
MSYS will be the one to provide you with the make command.

So far so good, let's review, we have perl64, MSYS to provide make and the post install of MSYS also created a mount point within it self /mingw which points to C:\Development\TDM-GCC-64

So to verify the setup => Start Menu => Start the MSYS terminal
Run perl -v it gives you the perl version information
Run gcc -v it gives you the gcc version information
Run make -v it gives you the make version information

2) Compile OpenSSL 64Bit

2.1 Prepare OpenSSL
Create the following folder path with windows Explorer: C:\Development\OpenSSL\src

2.2 Download OpenSSL Source
Go to https://www.openssl.org/source/

Download the latest openssl-1.0.x[a-z].tar.gz
For this tutorial I've used: https://www.openssl.org/source/openssl-1.0.2k.tar.gz
For the purpose of this tutorial I will continue to refere to openssl-1.0.2k for folder and files location(s).

Copy openssl-1.0.2k.tar.gz => C:\Development\OpenSSL\src

Open MSYS Terminal (Start Menu => MSYS)
$ cd /c/Development/OpenSSL/src
$ tar -xvzf openssl-1.0.2k.tar.gz
$ cd openssl-1.0.2k

Configure OpenSSL
$ perl configure mingw64 no-shared no-asm

Build OpenSSL
$ make

Building OpenSSL only takes a few minutes on a Intel I7.

3) Copy OpenSSL Resources

Copy OpenSSL resources to TDM-GCC-64 for go-sqlcipher compilation (Windows Explorer)

Within the folder C:\Development\OpenSSL\src\openssl-1.0.2k you will find 2 files which needs to be copied.

  • libcrypto.a
  • libcrypto.pc

Copy these files to C:\Development\TDM-GCC-64\lib

Now copy the entire OpenSSL include to TDM-GCC-64.
Goto C:\Development\OpenSSL\src\openssl-1.0.2k\include in this folder you will find a single folder named openssl copy this folder to C:\Development\TDM-GCC-64\x86_64-w64-mingw32\include

Copy the entire folder not contents.

4) Build go-sqlcipher

Now we are ready to build go-sqlcipher, we are using the still opened MSYS terminal from step 2 by the way.

Because we need a single change in a file for succesful compilation, we need to do the following.

Check out go-sqlcipher
$ go get -u -v github.com/xeodou/go-sqlcipher

This will also start a build but this will fail; don't worry it's oke.

Now edit the following file: <GOPATH>\src\github.com\xeodou\go-sqlcipher\sqlite3_windows.go
And add the following flag to the LDFLAGS -lgdi32

Complete new contents for sqlite3_windows.go

// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
// +build windows

package sqlite3

/*
#cgo CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
#cgo windows,386 CFLAGS: -D_USE_32BIT_TIME_T
#cgo LDFLAGS: -lmingwex -lmingw32 -lgdi32
*/
import "C"

now we can build succesfuly:
$ cd $GOPATH\src\github.com\xeodou\go-sqlcipher
$ go install -v .

All done :-) Enjoy :-)

I hope this will help some people.

Error on installation

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build067311942=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

go install github.com/xeodou/go-sqlcipher

# github.com/xeodou/go-sqlcipher
sqlite3-binding.c: В функции «sqlcipher_openssl_hmac»:
sqlite3-binding.c:18401:12: ошибка: размер «hctx» в памяти неизвестен
   HMAC_CTX hctx;
            ^~~~
sqlite3-binding.c:18403:3: предупреждение: implicit declaration of function «HMAC_CTX_init»; did you mean «HMAC_CTX_new»? [-Wimplicit-function-declaration]
   HMAC_CTX_init(&hctx);
   ^~~~~~~~~~~~~
   HMAC_CTX_new
sqlite3-binding.c:18408:3: предупреждение: implicit declaration of function «HMAC_CTX_cleanup»; did you mean «HMAC_CTX_get_md»? [-Wimplicit-function-declaration]
   HMAC_CTX_cleanup(&hctx);
   ^~~~~~~~~~~~~~~~
   HMAC_CTX_get_md
sqlite3-binding.c: В функции «sqlcipher_openssl_cipher»:
sqlite3-binding.c:18418:18: ошибка: размер «ectx» в памяти неизвестен
   EVP_CIPHER_CTX ectx;
                  ^~~~

Update SQLCipher

@xeodou Can you to update it to the latest sqlite3 + SQLCipher ?

If not any information / howto on how to accomplish it ?

Cross Compile to Windows From Linux

As title said, I'm trying to cross compile my app from Ubuntu 64-bit to Windows 32-bit. From issue 106 in go-sqlite3, I've tried this command :

env CGO_ENABLED=1 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build

But it failed with this result :

# github.com/xeodou/go-sqlcipher
../github.com/xeodou/go-sqlcipher/sqlite3-binding.c:18280:26: fatal error: openssl/rand.h: No such file or directory
compilation terminated.

The installation is failing on windows, may be because it's not been tested i believe.

I have the gcc properly installed. But looks like there seems to be an issue while installing go-sqlchiper. Has anyone tried to install the new release on windows yet. Any help is greatly appreciated. Thanks

go get github.com/xeodou/go-sqlcipher

github.com/xeodou/go-sqlcipher

....\workspace\src\github.com\xeodou\go-sqlcipher\sqlite3-binding.c:18280:26: fatal error: openssl/rand.h: No such file or directory
#include <openssl/rand.h>
^
compilation terminated.

Upgrade sqlite3 to the latest version.

This package is using a the version 3.30.1 from sqlite3 which doesn't support RETURNING that a lot of orms use when creating new record in the database, I tried forking the package and using the upgrade script, but the pragma key is no longer working.
image

Can't install on OSX

I have install openssl with homebrew and ran brew link --force openssl.

I tried installing go-sqlcipher with go install github.com/xeodou/go-sqlcipher and I get the following:

ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)

"panic: file is not a database"

Hello and excuse me for a strange question.

I've started maintaining our company's small project written in Go. It uses SQLite3 and your go-sqlcipher, also Gorm v1 and labstack/echo as a simple web server.

I have an old binary build which works this way:

  1. During the first run, the database is ciphered with a random key. 3 subkeys are computed and printed (2 of them are enough to reproduce the key). PRAGMA key ... is issued and application runs fine.
  2. During the other runs, the application opens the database, but since it is encrypted, it justs waits for keys to be put via HTTP request to unseal the DB file.

However, on the second run, I get "panic: file is not a database" error. The easiest way to reproduce this is to use your encrypto example: https://github.com/xeodou/go-sqlcipher/blob/master/_example/encrypto/encrypto.go
Run it once, everything is fine. Run it twice without ?key=123456, you get the error. To skip the error, you need to pass ?key=123456 with db path. However, the app I'm maintaining used to work without this addition.

So my question is: which version of go-sqlcipher should I use to keep the old behavior?

windows10 error

image
I set the environment variable. but when i use
go install show the error:
image
How to solve???

How to support windows long path

I am trying to create a db by the function Open. It was fine but for some other db when file name is too long it's giving below error:
unable to open database file

cannot find -lcrypto

PS C:\Windows\system32> go get -v github.com/xeodou/go-sqlcipher d:/workspace/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcrypto collect2.exe: error: ld returned 1 exit status


OpenSSL> version OpenSSL 1.1.1c 28 May 2019 OpenSSL>


windows10 64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.