SQLCipher ported to Harbour (Windows)

Moderator: Rathinagiri

Post Reply
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by esgici »

dhaine_adp wrote: ...The problem is when I link libsqlcipher.a and lieay32.a the application looks for libeay32.dll...
Hi Dany

As far as know, when linked a lib<xxx>. a file to an application, this application shouldn't "look" a .dll file; unless you didn't use CallDLL32() function. An "a" extension implies a "static" library, and ".dll" means "dynamic"; does I know wrong :?

Regards
Viva INTERNATIONAL HMG :D
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: SQLCipher ported to Harbour (Windows)

Post by dhaine_adp »

Hi Esgici,
As far as know, when linked a lib<xxx>. a file to an application, this application shouldn't "look" a .dll file; unless you didn't use CallDLL32() function. An "a" extension implies a "static" library, and ".dll" means "dynamic"; does I know wrong :?
You're absolutely right and on the contrary I never made a call on libeay32.dll. I think it was called from libeay32.a which in turn used by libsqlcipher.a

There are sources from this old distribution site: http://gnuwin32.sourceforge.net/packages/openssl.htm" onclick="window.open(this.href);return false;

But these sources are big and may require time to fully rebuilt the code for used with Hb/HMG. Definitely I will not take this path as much as possible.

I would like to encrypt the SQLite3 database and in doing so I found that libsqlcipher seems to be the best way but it requires to bundle the file libeay32.dll. Now this dll file is something that I wish to eliminate. I'd prefer to have an executable file without any dll file dependency.

Another option to try is to eliminate libsqlcipher totally and independently encrypt/decrypt the file attached to ON INIT procedure and modify the HMG error handler to encrypt the file before terminating the application. However this is less secure because if the application was terminated from the TaskManager, there is no guarantee that the database is still encrypted afterwards.

Regards,

Danny
Regards,

Danny
Manila, Philippines
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by danielmaximiliano »

Danny :
utilize este HMG.HBC y reconstruya las librerias / Use this HMG.HBC and rebuild the libraries

Code: Select all

# paths

incpaths=/.
incpaths=include
libpaths=lib

# main hmg libs

libs=hmg
libs=crypt
libs=edit
libs=editex
libs=graph
libs=hfcl
libs=ini
libs=report

# system libs

libs=msvfw32
libs=vfw32

# harbour contrib libs

libs=hbct
libs=hbwin
libs=hbmzip
libs=minizip
libs=hbmemio
libs=hbmisc
libs=hbmysql
libs=mysql
libs=hbtip
libs=sqlite3
libs=hbsqlit3
libs=sddodbc
libs=rddsql
libs=sddmy
libs=hbodbc
libs=odbc32
libs=hbhpdf
libs=hbfimage
libs=hbpgsql
libs=hbnetio
libs=xhb
libs=png
libs=libhpdf
libs=hbvpdf
libs=hbzebra
# ***** include this lines *****

libs=hbssl
libs=libeay32
libs=ssleay32
Libs=hbtipssl

# ***** include this lines *****

# link compiled resources

sources=${hb_curdir}_temp.
extraiga los archivos y reemplaze / remove and replace files
LIB.rar
(900.61 KiB) Downloaded 308 times
lib.png
lib.png (87.82 KiB) Viewed 4809 times
lib in IDE.png
lib in IDE.png (25.97 KiB) Viewed 4809 times

I think this is what you need
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by Rathinagiri »

Many of us (at least myself) don't like .dll files. However, using dll files is not a bad thing as it optimizes the memory usage. For example, if you use two programs calling the same functions, RAM usage is minimized as dll files are loaded only once.

Regarding this particular situation, I have tried to create static libraries of ssl, eay32 and ssleay32 but I couldn't. So, now I distribute my software along with dll files by a setup program. This setup program would copy the dll files in windows system folder, so that other programs (if any) which need these libraries can also be benefited. And, the user doesn't know about this.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by danielmaximiliano »

Hi Rathi :
Try this.

Download OpenSSL Win32 from http://slproweb.com/download/Win32OpenS ... 1_0_1e.exe
Download OpenSSL Win64 from http://slproweb.com/download/Win64OpenS ... 1_0_1e.exe

Install to c:\openssl

Download Harbour Contrib hbssl o use harbour sources in c:\harbour\core\contrib\hbssl
Contrib.rar
(145.4 KiB) Downloaded 305 times
Execute BuildOpenssl.bat and generate library
lib static.png
lib static.png (59.01 KiB) Viewed 4786 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by Rathinagiri »

Thank you Daniel. I will try and tell you. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: SQLCipher ported to Harbour (Windows)

Post by dhaine_adp »

Hi Daniel,

Thank you very much I'll try this. Linking the libsqlcipher gives me the error below if I don't include libeay32.dll. :)

I appreciate your help.

Regards,

Danny
Attachments
Missing libeay32.dll
Missing libeay32.dll
eay32.JPG (12.28 KiB) Viewed 4752 times
Regards,

Danny
Manila, Philippines
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by danielmaximiliano »

Hi Rathinagiri :

in my settings your example SQLCipher works correctly

Code: Select all

#include <hmg.ch>
#define CRLF                         Chr(13)+Chr(10)
Function Main
   local oDB := nil
   local cKey := 'password123'
   local cFile := 'sample.sqlite'
   local aTable := {}
   local cShow := ''
   
   if file( cFile )
      oDB := connect2db( 'sample.sqlite', .f. )
      if oDB == Nil
         msgstop( 'Database File can not be connected' )
      else
         iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) ), ;
              cShow += 'Encryption Key is set' + CRLF , msginfo( 'Encryption key can not be set' ) )
         aTable := sql( oDB, 'select name, city from master' )
         if len( aTable ) > 0
            msginfo( 'Name:' + aTable[ 1, 1 ] + ' City:' + aTable[ 1, 2 ] )
         endif   
      endif   
   else
      oDB := connect2db( 'sample.sqlite', .t. )
      if oDB == Nil
         msgstop( 'Database File can not be connected' )
      else
         iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) )  , ;
              cShow += 'Encryption Key is set' + CRLF , msginfo(  'Encryption key can not be set!' ) )
         iif( miscsql( oDB, 'create table master (name, city)' ) , ;
              cShow += 'Master table is created successfully!' + CRLF , msginfo( 'Table can not be created!' ) )
         iif( miscsql( oDB, 'insert into master ( name, city ) values ( ' + c2sql( 'Name1' ) + ', ' + c2sql( 'City1' ) + ' )' ) , ;
              MsgInfo( cShow + 'Sample Data updated' , 'Good Notice' ) , msginfo( 'sample data can not be updated!' ) )
      endif
   endif     
Return nil
	
	

Sample.png
Sample.png (71.22 KiB) Viewed 4733 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: SQLCipher ported to Harbour (Windows)

Post by dhaine_adp »

Hi Rathi,

Any progress? :) Somewhere in libsqlcipher is a call to libeay32.dll. It looks like we can't eliminate it and there is something interesting on sqlite3.c (libsqlcipher) at line no.: 4907-4918, it says:
#ifdef SQLITE_HAS_CODEC
/*
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
SQLITE_API int sqlite3_key(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The key */
);
At this point, I am going to follow your lead, to distribute the libeay32.dll

@Daniel:
Perhaps you may have either of these files libeay32.dll or libeay64.dll or libeay.dll, into your system.

BTW my libeay32.dll is located not window system folder but from GetStartUpFolder(). During testing I'd just renaming it. I have a reason for not installing it on the system folder.

Well, I am not successful in embedding the libeay32.dll into the executable and what's left for me is to do a dirty hack out of it by combining the exe + dll file and at run-time write [fcreate()] the dll file somewhere or in the temp folder. But this method will surely irritate the Anti Virus software.

Attached is a hex view of an encrypted SQLite database.

Thanks,

Danny
Attachments
This is an encrypted SQLite database
This is an encrypted SQLite database
encry.JPG (103.1 KiB) Viewed 4693 times
Regards,

Danny
Manila, Philippines
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: SQLCipher ported to Harbour (Windows)

Post by esgici »

Hi Danny,

What Hex view prg you are using ?

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D
Post Reply