SQLCipher ported to Harbour (Windows)

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by Rathinagiri » Mon Mar 31, 2014 10:42 pm

Hi Qatan,

I had found a clue from here.
"What I am noticing is that it is this check for '-lcrypto' which is failing on MinGW/MSYS. Also, if I pass '--with-crypto-lib=none' then the configure script runs fine and generates the Makefile, but make is breaking at that point however, I think that is fixable. I though the check for '-lcrypto' on a windows system is not possible as Openssl libraries are named 'libeay32' on windows."
Now, using this clue, I had created a new libSQLCipher.a

I am attaching the same with this. Please test and tell me if it is ok. As it is 4.10 a.m. here, I feel sleeeeeeepy. I will test it tomorrow.
libsqlcipher.zip
(418.21 KiB) Downloaded 132 times
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Tue Apr 01, 2014 7:22 am

I have tested the above library in HMG 3.2 and is working fine in encrypting and decrypting.

However, I can't decrypt a database which was encrypted using previous version of SQLCipher. I don't know why.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Tue Apr 01, 2014 8:20 am

Rathinagiri wrote:
I had found a clue from https://groups.google.com/forum/#!topic ... HkvQvWQaWE.

"What I am noticing is that it is this check for '-lcrypto' which is failing on MinGW/MSYS. Also, if I pass '--with-crypto-lib=none' then the configure script runs fine and generates the Makefile, but make is breaking at that point however, I think that is fixable. I though the check for '-lcrypto' on a windows system is not possible as Openssl libraries are named 'libeay32' on windows."
Now, using this clue, I had created a new libSQLCipher.a
[/quote]
Here it worked also, thanks for the tip!

Now I got stuck with make command
I am not sure what I should see when I issue the above command but I get a lot of information, warnings and errors and in the end it shows:

./src/alter.c:812:17: warning: assignment from incompatible pointer type [enable
d by default]
pNew->pSchema = db->aDb[iDb].pSchema;
^
make: *** [alter.lo] Error 1


I don't know what is the problem... trying to go foward with make dll and make install just give similar errors.
One important detail is that the first time I tried this morning the message I got was about tcl (something about not fiding it...) so maybe this is the problem...
I don't know where tcl enters in this whole process... how do you link tcl to msys?
I have tcl installed in c:\tcl but I do not know how to link it to the process of building sqlcipher... what am I missing?


I am attaching the same with this. Please test and tell me if it is ok. As it is 4.10 a.m. here, I feel sleeeeeeepy. I will test it tomorrow.
Nice!
Which version of Harbour / HMG did you use?
I am trying to build sqlcipher with Harbour Nightly Binaries

I think you can not mix sqlcipher versions... this is why you can't decrypt what was encrypted with other version of sqlcipher. For me it makes sense, doesn't it?

Ah! :o and the last thing. I built a program with the previous sucessful lib you created libSQLCipher.a and it worked fine! The only problem I found was distribuiting the program (I made a postal code searching utility for free distribuition). For some people the utility doesn't run because it gives the following message:

This application failed to start because libeay32.dll was not found. Reinstalling the application may fix the problem

I think for most people it does not give any error because their Windows already have this dll installed.

So I came to the conclusion that I have to distribute the EXE with libeay32.dll... right?
I can survive with that but I have to admit I hate DLL's... I would prefer to have it inside the EXE (The only thing I like to have is only one EXE, a manual (PDF) and the database (protected with SQLCipher) ;)

I remember a note on the original message from P.Chornyj (where all this started) where he adds:
With hbmk2 create a import library for OpenSSL dll's
If you use Harbour with HB_WITH_OPENSSL you already have OpenSSL binary and import libraries

So it's possible to do it but I will go after this detail when I succesfully generate the lib for sqlcipher

Thanks for all your help and patience. :roll:
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Tue Apr 01, 2014 9:15 am

We require sqlite3.c and sqlite.h files only during the make process. There would be warnings since we had overridden openssl during configure.

Also, it is the version of GCC involved in the libsqlcipher creation and not any Harbour build since sqlcipher is pure 'c' level.

HBSQlite is the prg<->c bridge which involves 'harbour' calling 'c' functions.
If you use Harbour with HB_WITH_OPENSSL you already have OpenSSL binary and import libraries
That is nice. Let us try that route. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Tue Apr 01, 2014 10:08 am

Rathinagiri wrote:We require sqlite3.c and sqlite.h files only during the make process. There would be warnings since we had overridden openssl during configure.
Hmm, sorry for asking... but where should I expect to have sqlite3.c and sqlite.h? I mean in which folder I should get it?

Also I still do not understand where tcl goes into this whole process... Will MSys find tcl automatically? How? Where is the link between the build process and tcl?
I just want to understand. I don't like when things just happen without understanding because it may be the source of problems :shock: (or solutions) :D to me
Also, it is the version of GCC involved in the libsqlcipher creation and not any Harbour build since sqlcipher is pure 'c' level.
Right
HBSQlite is the prg<->c bridge which involves 'harbour' calling 'c' functions.
This will be the next step but I do not find sqlite3.c and sqlite.h so I am still on the previous step...
If you use Harbour with HB_WITH_OPENSSL you already have OpenSSL binary and import libraries
That is nice. Let us try that route. :)
Sure!
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Tue Apr 01, 2014 10:36 am

but where should I expect to have sqlite3.c and sqlite.h? I mean in which folder I should get it?
These two files will be created during the MAKE process in the sqlcipher main directory itself.

I think you can disable tcl altogether using --disable-tcl. Enabling tcl allows you to run tcl scripts, I think.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Tue Apr 01, 2014 12:56 pm

Well, it's a test of patience and much reading.
What is sometimes frustrating is that I am trying to do something I do not really understand but I will share what I did so far.

I *think* I successfully built sqlcipher lib: LINK WAS REMOVED

Would you mind to test it in your program? It has a different size than of your version...

This is how I typed the ./configure part:

./configure --disable-tcl --disable-amalgamation --with-crypto-lib=none CFLAGS="-DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -I/c/OpenSSL/include /c/OpenSSL/libeay32.dll -L/c/OpenSSL/lib/MinGW" LDFLAGS="-leay32"


This time didn't give any errors

Then:

make clean
make
make dll
make install


In the folder sqlcipher I found:
  • libsqlcipher.a (obs: this one was inside a folder sqlcipher\.libs)
    sqlcipher.exe
    sqlite3.dll
    sqlite3.h
But *strangely* I didn't find sqlite3.c :(
Last edited by Hazael on Tue Apr 01, 2014 3:02 pm, edited 1 time in total.
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Tue Apr 01, 2014 2:02 pm

Wow man! You had done it!
But *strangely* I didn't find sqlite3.c
Because you had disabled amalgamation!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Hazael
Posts: 109
Joined: Thu Jun 24, 2010 11:37 am
Location: France

Post by Hazael » Tue Apr 01, 2014 2:26 pm

Rathinagiri wrote:Wow man! You had done it!
But *strangely* I didn't find sqlite3.c
Because you had disabled amalgamation!
Exactly!

I removed that non-sense option and now it generates sqlite3.c: LINK WAS REMOVED

For the first time it worked flawlessly. I am kind of trying to generate the lib since 2010 but never really persevered to the end.

Now I will stop a bit (we need some refreshment) and then I will try to build on Harbour.

Did you test the lib I generated? I just want to make sure it is working.

Thanks for your great help and support!
Last edited by Hazael on Tue Apr 01, 2014 3:03 pm, edited 1 time in total.
Harbour | GTWVT | MingW | Visual Studio Code

User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

Post by Rathinagiri » Tue Apr 01, 2014 2:41 pm

When I tried to compile an existing project with your library and latest harbour nightly build, I got this error.

Code: Select all

C:/hmg.3.2a/harbour/lib/win/mingw/libhbsqlit3.a(core.o):core.c:(.text+0x2738): undefined reference to `sqlite3_enable_load_extension'
collect2: ld returned 1 exit status
hbmk2[pyrocost]: Error: Running linker. 1
gcc.exe .hbmk/win/mingw/main.o .hbmk/win/mingw/group.o .hbmk/win/mingw/grouptype.o .hbmk/win/mingw/openxb.o .hbmk/win/mingw/subgroup.o .hbmk/win/mingw/supergroup.o .hbmk/win/mingw/xactwindow.o .hbmk/win/mingw/_hbmkaut_main.o D:/MyProjects/pyrocost/_temp.o    -Wl,--nxcompat -Wl,--dynamicbase -mwindows -Wl,--start-group -lhmg -lcrypt -ledit -leditex -lgraph -lhfcl -lini -lreport -lmsvfw32 -lvfw32 -lhbct -lhbwin -lhbmzip -lminizip -lhbmemio -lhbmisc -lhbmysql -lmysql -lhbtip -lhbsqlit3 -lsddodbc -lrddsql -lsddmy -lhbodbc -lodbc32 -lhbhpdf -lhbfimage -lhbpgsql -lhbnetio -lxhb -lpng -llibhpdf -lhbvpdf -lhbzebra -lsqlcipher -lhmgsqlite -leay32 -lhbextern -lhbdebug -lhbvmmt -lhbrtl -lhblang -lhbcpage -lgtcgi -lgtpca -lgtstd -lgtwin -lgtwvt -lgtgui -lhbrdd -lhbuddall -lhbusrrdd -lrddntx -lrddcdx -lrddnsx -lrddfpt -lhbrdd -lhbhsx -lhbsix -lhbmacro -lhbcplr -lhbpp -lhbcommon -lhbmainwin -lkernel32 -luser32 -lgdi32 -ladvapi32 -lws2_32 -liphlpapi -lwinspool -lcomctl32 -lcomdlg32 -lshell32 -luuid -lole32 -loleaut32 -lmpr -lwinmm -lmapi32 -limm32 -lmsimg32 -lwininet -lhbpcre -lhbzlib   -Wl,--end-group -opyrocost.exe  -LC:/hmg.3.2a/harbour/lib/win/mingw -LC:/hmg.3.2a/lib
However, if I replace with my library, it works ok. I don't understand why.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply