Last active
December 26, 2015 10:59
-
-
Save ggiraldez/7141132 to your computer and use it in GitHub Desktop.
Adding encryption to sqlite JDBC driver with Botan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install Botan dependency | |
$ brew install botan | |
# Check out botansqlite3 | |
$ git clone git@github.com:OlivierJG/botansqlite3.git | |
# Copy all files from botansqlite3 to sqlite-jdbc/target/sqlite-amalgamation-3071500 | |
$ echo '#include "codecext.c"' >> sqlite3.c | |
# Compile native library and JAR | |
$ JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/ make | |
$ mvn package | |
# Compiling the modified shell | |
$ JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/ make target/sqlite-3.7.15-Mac-x86_64/shell | |
$ target/sqlite-3.7.15-Mac-x86_64/shell test.db | |
sqlite> pragma key=foo; | |
sqlite> create table test (a int, b varchar); | |
sqlite> insert into test values (1,'foo'); | |
sqlite> insert into test values (2,'bar'); | |
sqlite> .q | |
# Testing the JAR | |
$ groovyConsole -cp target/sqlite-jdbc-3.7.15-M1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r d90d6d8748d8 Makefile | |
--- a/Makefile Sat Jun 22 20:30:43 2013 +0900 | |
+++ b/Makefile Thu Oct 24 13:55:47 2013 -0300 | |
@@ -45,6 +45,10 @@ | |
clean: clean-native clean-java clean-tests | |
+BOTAN_CFLAGS=`botan-config-1.10 --cflags` | |
+BOTAN_LIBS=-lstdc++ -lpthread /usr/local/lib/libbotan-1.10.a | |
+# `botan-config-1.10 --libs` | |
+ | |
$(SQLITE_OUT)/sqlite3.o : $(SQLITE_UNPACKED) | |
@mkdir -p $(@D) | |
perl -p -e "s/sqlite3_api;/sqlite3_api = 0;/g" \ | |
@@ -53,7 +57,7 @@ | |
perl -p -e "s/^opendb_out:/ if(!db->mallocFailed && rc==SQLITE_OK){ rc = RegisterExtensionFunctions(db); }\nopendb_out:/;" \ | |
$(SQLITE_AMAL_DIR)/sqlite3.c > $(SQLITE_OUT)/sqlite3.c | |
cat src/main/ext/*.c >> $(SQLITE_OUT)/sqlite3.c | |
- $(CC) -o $@ -c $(CFLAGS) \ | |
+ $(CC) -o $@ -c $(CFLAGS) $(BOTAN_CFLAGS) \ | |
-DSQLITE_ENABLE_LOAD_EXTENSION=1 \ | |
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \ | |
-DSQLITE_ENABLE_COLUMN_METADATA \ | |
@@ -62,15 +66,35 @@ | |
-DSQLITE_ENABLE_FTS3_PARENTHESIS \ | |
-DSQLITE_ENABLE_RTREE \ | |
-DSQLITE_ENABLE_STAT2 \ | |
+ -DSQLITE_HAS_CODEC \ | |
$(SQLITE_FLAGS) \ | |
$(SQLITE_OUT)/sqlite3.c | |
-$(SQLITE_OUT)/$(LIBNAME): $(SQLITE_OUT)/sqlite3.o $(SRC)/org/sqlite/NativeDB.c $(SQLITE_OUT)/NativeDB.h | |
+$(SQLITE_OUT)/codec.o : $(SQLITE_UNPACKED) | |
+ @mkdir -p $(@D) | |
+ $(CC) $(CFLAGS) $(BOTAN_CFLAGS) -c -o $(SQLITE_OUT)/codec.o $(SQLITE_AMAL_DIR)/codec.cpp | |
+ | |
+$(SQLITE_OUT)/$(LIBNAME): $(SQLITE_OUT)/sqlite3.o $(SRC)/org/sqlite/NativeDB.c $(SQLITE_OUT)/NativeDB.h $(SQLITE_OUT)/codec.o | |
@mkdir -p $(@D) | |
$(CC) $(CFLAGS) -c -o $(SQLITE_OUT)/NativeDB.o $(SRC)/org/sqlite/NativeDB.c | |
- $(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/*.o $(LINKFLAGS) | |
+ $(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/NativeDB.o $(SQLITE_OUT)/sqlite3.o $(SQLITE_OUT)/codec.o $(LINKFLAGS) $(BOTAN_LIBS) | |
$(STRIP) $@ | |
+$(SQLITE_OUT)/shell.o : $(SQLITE_UNPACKED) | |
+ $(CC) -o $@ -c $(CFLAGS) $(BOTAN_CFLAGS) \ | |
+ -DSQLITE_ENABLE_LOAD_EXTENSION=1 \ | |
+ -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \ | |
+ -DSQLITE_ENABLE_COLUMN_METADATA \ | |
+ -DSQLITE_CORE \ | |
+ -DSQLITE_ENABLE_FTS3 \ | |
+ -DSQLITE_ENABLE_FTS3_PARENTHESIS \ | |
+ -DSQLITE_ENABLE_RTREE \ | |
+ -DSQLITE_ENABLE_STAT2 \ | |
+ -DSQLITE_HAS_CODEC \ | |
+ $(SQLITE_FLAGS) \ | |
+ $(SQLITE_AMAL_DIR)/shell.c | |
+$(SQLITE_OUT)/shell : $(SQLITE_OUT)/shell.o $(SQLITE_OUT)/$(LIBNAME) | |
+ $(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/*.o $(BOTAN_LIBS) | |
NATIVE_DIR=src/main/resources/org/sqlite/native/$(OS_NAME)/$(OS_ARCH) | |
NATIVE_TARGET_DIR:=$(TARGET)/classes/org/sqlite/native/$(OS_NAME)/$(OS_ARCH) | |
diff -r d90d6d8748d8 Makefile.common | |
--- a/Makefile.common Sat Jun 22 20:30:43 2013 +0900 | |
+++ b/Makefile.common Thu Oct 24 13:55:47 2013 -0300 | |
@@ -75,14 +75,14 @@ | |
SunOS-sparcv9_LIBNAME := libsqlitejdbc.so | |
SunOS-sparcv9_SQLITE_FLAGS := | |
-Mac-i386_CC := gcc -arch $(OS_ARCH) | |
+Mac-i386_CC := gcc-4.2 -arch $(OS_ARCH) | |
Mac-i386_STRIP := strip -x | |
Mac-i386_CFLAGS := -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.4 -fvisibility=hidden | |
Mac-i386_LINKFLAGS := -dynamiclib -static-libgcc | |
Mac-i386_LIBNAME := libsqlitejdbc.jnilib | |
Mac-i386_SQLITE_FLAGS := -DSQLITE_ENABLE_LOCKING_STYLE=0 | |
-Mac-x86_64_CC := gcc -arch $(OS_ARCH) | |
+Mac-x86_64_CC := gcc-4.2 -arch $(OS_ARCH) | |
Mac-x86_64_STRIP := strip -x | |
MAC_SDK := /Developer/SDKs/MacOSX10.7.sdk | |
ifeq ($(wildcard MAC_SDK),) | |
diff -r d90d6d8748d8 src/main/java/org/sqlite/SQLiteConfig.java | |
--- a/src/main/java/org/sqlite/SQLiteConfig.java Sat Jun 22 20:30:43 2013 +0900 | |
+++ b/src/main/java/org/sqlite/SQLiteConfig.java Thu Oct 24 13:55:47 2013 -0300 | |
@@ -269,6 +269,7 @@ | |
TEMP_STORE("temp_store", toStringArray(TempStore.values())), | |
TEMP_STORE_DIRECTORY("temp_store_directory"), | |
USER_VERSION("user_version"), | |
+ ENCRYPTION_KEY("key"), | |
// Others | |
TRANSACTION_MODE("transaction_mode", toStringArray(TransactionMode.values())), | |
diff -r d90d6d8748d8 src/main/resources/org/sqlite/native/Mac/i386/libsqlitejdbc.jnilib | |
Binary file src/main/resources/org/sqlite/native/Mac/i386/libsqlitejdbc.jnilib has changed | |
diff -r d90d6d8748d8 src/main/resources/org/sqlite/native/Mac/x86_64/libsqlitejdbc.jnilib | |
Binary file src/main/resources/org/sqlite/native/Mac/x86_64/libsqlitejdbc.jnilib has changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class.forName('org.sqlite.JDBC') | |
import groovy.sql.Sql | |
import java.sql.DriverManager | |
def props = new Properties() | |
props['key'] = "foo" | |
sql = Sql.newInstance('jdbc:sqlite:test.db', props) | |
sql.eachRow('select * from test') { println it } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment