Using SQLCipher without encryption - ATTACH DATABASE problem

189 views
Skip to first unread message

yas

unread,
Feb 25, 2010, 11:47:41 AM2/25/10
to SQLCipher Users
Hello,

I'd like to use SQLCipher in mixed mode - with and without encryption.
And It seems there is a problem with 'ATTACH DATABASE' command. The
scenario that reproduces this issue:

1. Open new database and don't use sqlite3_key for encryption.
2. Try to attache another new database (also without encryption) - an
error occurs (cannot attach database).

It seems he problem occurs at attachFunc(...) function, near

case SQLITE_NULL:
/* No key specified. Use the key from the main database */
sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
break;

Because there is no key at the main database - NULL value also passed
into sqlite3CodecAttach. Then sqlite3CodecAttach does nothing but
returns SQLITE_ERROR. I'm not sure it's SQLite error or SQLCipher
incorrect parameter processing.

I must to say also that I build WinCE version and I use and
amalgamation SQLite 3.6.22 source - I only added '#include "crypto.c"
line in the end of sqlite3.c.

Stephen Lombardo

unread,
Feb 25, 2010, 12:09:13 PM2/25/10
to sqlc...@googlegroups.com
Hi Yas,

There is a fix for this issue that I just pushed up to github.

Please note however that default behavior when attaching a database to an encrypted main database is to use the same key as the main database if a password is not provided. Therefore, attaching an unencrypted database to an unencrypted main would work fine with something like this:

ATTACH DATABASE 'test.db' AS test;

However, that would fail when your trying to attach an unencrypted database to an encrypted main database. In this case we'd need to specify a zero length but non null key to "override" the default, i.e.

ATTACH DATABASE 'test.db' AS test KEY '';

Cheers,
Stephen

Sergey Chumakov

unread,
Feb 25, 2010, 12:46:05 PM2/25/10
to sqlc...@googlegroups.com, Stephen Lombardo
Hello Stephen,

Thank you, this works great.

Stephen Lombardo wrote:
> There is a fix for this issue that I just pushed up to github.
>
> http://github.com/sjlombardo/sqlcipher

--
Best regards,
Sergey Chumakov 2:450/77[.43]

Reply all
Reply to author
Forward
0 new messages