Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

sqlcipher for sqlite

by TomKane (Beadle)
on Dec 28, 2012 at 17:36 UTC ( #1010722=perlquestion: print w/ replies, xml ) Need Help??
TomKane has asked for the wisdom of the Perl Monks concerning the following question:

I have been using sqlite on Win32 for some time now. I am now trying to use the sqlite3.dll file that is derived from the sqlcipher source code. This is a relatively new extension of SQLite that provides a pragma of "key" that lets you encrypt the entire database.

It took me a while, but I finally found the place for swapping out the dll file: C:/Perl/site/lib/auto/DBD/SQLite/SQLite.dll (where the new dll file was appropriately renamed). I have placed the new sqlite.dll and sqlite.lib files in the directory, but I do not have a sqlite.exp file, such as was provided in the original perl/sqlite installation.

Here is the very brief program that I used to test the new dll:

use DBI ; my $db_Handle = DBI->connect( "dbi:SQLite:sql_cipher_test.db", "", "", { AutoCommit => 1, } ) ;

The error message I'm getting is "Can't find 'boot_DBD__SQLite' symbol in" the dll file.

I have a bad feeling that I'm going to have to rebuild SQLite.pm or the .xs file, or both, or something else that's really scary, in order to get this to work.

If anyone has wisdom on the matters of linking perl to dll files (to sqlite.dll in particular), I would greatly appreciate your advice.

Comment on sqlcipher for sqlite
Download Code
Re: sqlcipher for sqlite
by roboticus (Canon) on Dec 28, 2012 at 18:39 UTC

    TomKane:

    Just replacing the DLL isn't going to work because the API is slightly different. For example, how would DBD::SQLite know how to send the key to the dll? I'd think your best bet if you know C and perl would be to look at the installation package and see how hard it might be to add sqlcipher to the package. I'm guessing it would be fairly straightforward, but you'll have to spend some time to figure out how the module builds, build some test cases and such.

    Failing that, you could offer to pay the maintainer to do the integration for you, or pay someone to create a patch for you.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: sqlcipher for sqlite
by Corion (Pope) on Dec 28, 2012 at 21:42 UTC

    DBD::SQLite basically gets compiled from the SQLite source code, together with some Perl-specific C code ("XS code"). Simply replacing the SQLite.dll with a DLL that was not compiled from the XS code in DBD::SQLite will not work. You will have to recompile DBD::SQLite with the sqlcipher source code and then also think hard about the new API to pass the decryption key around.

    Recompiling DBD::SQLite with the sqlcipher code should be fairly easy:

    1. Download the sqlcipher package
    2. Download and change into the DBD::SQLite package directory:
      > cpan cpan[1]> look DBD::SQLite
    3. Replace the sqlite3.c and sqlite3.h files with the files from sqlcipher
    4. Use the standard invocation to compile and install the module:

      perl Makefile.PL dmake dmake test dmake install
Re: sqlcipher for sqlite
by TomKane (Beadle) on Dec 29, 2012 at 14:55 UTC
    Thank you both, roboticus and Corion, for your comments on my post. You have confirmed what I had suspected. It's been a while since I did the XS tutorial, but at least I once was able to do it. Now I'll see if I can do it for production code. Oh what joy!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010722]
Approved by kennethk
Front-paged by kennethk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-12-29 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls