How to correctly use SQL cipher

2,647 views
Skip to first unread message

Seelan

unread,
Dec 8, 2010, 11:41:36 PM12/8/10
to SQLCipher Users
Hey guys,

I need to use SQL cipher for a project. And have been unable to get a
encrypted database from a plain-text database using the ATTACH
command.

I have downloaded the latest versions of SQL Cipher and OpenSSL and
successfully built them in xCode.

I have tried using the ATTACH command for a few days now with no luck,
and I'm guessing I made a mistake somewhere. The command that i used
to ATTACH is from http://zetetic.net/blog/2009/12/29/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher/
. But always the output, the "enc.db" is unencrypted.

Do I have to carry out the following steps that are listed out in the
readme?

[Compiling]
Building SQLite Cipher is almost the same as compiling a regular
version of SQLite with three small exceptions:
1. building via 'amalgamation' isn't supported (where all sqlite
source is merged into one file)
2. you must define SQLITE_HAS_CODEC and SQLITE_TEMP_STORE=2 in your
application when including SQLCipher
3. You need to link against a OpenSSL's libcrypto with sha256 support
compiled in
Example Static linking (replace /opt/local/lib with the path to
libcrypto.a)
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC"
LDFLAGS="/opt/local/lib/libcrypto.a"
make
Example Dynamic linking
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC"
LDFLAGS="-lcrypto"
make

If so where and how should I carry out these steps? Sorry for the noob
questions, I'm not really a programmer, but am trying hard to do this
project!

Thanks!

Stephen Lombardo

unread,
Dec 9, 2010, 10:16:17 AM12/9/10
to sqlc...@googlegroups.com
Hi Seelan,

I read your post, and went back through the previous email you sent to this mailing list. I really can't see anything specific that you're doing wrong with the steps. However, I did notice that you reported this in the last message you sent:

"My sqlite version is sqlite 3.6.12, is this an issue or am i missing any commands?"

The latest version of SQLCipher is built against 3.7.2, and in fact, I don't think any version of SQLCipher ever used 3.6.12 as a baseline. I think it is possible that you are running your tests using some pre-installed sqlite version on your system, instead of the sqlcipher-enabled binary. Please make sure you are running the sqlite3 executable you built from the source package, and let us know if this resolves your problem.

Cheers,
Stephen

Seelan

unread,
Dec 10, 2010, 1:47:04 AM12/10/10
to SQLCipher Users
Hey,

-_-" it took me a while to indeed realise that i wasn't supposed to be
running the pre-installed sqlite3 on the Mac. If I only had figured
this out sooner.
But its ok, i managed to get the encryption working, thanks for taking
your time to answer my pretty lame blunder.

In the mobile orchard tutorial it didn't point out to compile and run
sqlite3 from the sqlcipher code, and me being the blur guy attempted
using Mac's sqlite3.(thats what happens when you forget to RTFM) I
should have my decryption working up in a bit. Thanks for all the
help.

And also awesome job on SQLCipher, it really is a very well-done open-
source tool.

Regards,
Seelan

On Dec 9, 11:16 pm, Stephen Lombardo <sjlomba...@zetetic.net> wrote:
> Hi Seelan,
>
> I read your post, and went back through the previous email you sent to this
> mailing list. I really can't see anything specific that you're doing wrong
> with the steps. However, I did notice that you reported this in the last
> message you sent:
>
> "My sqlite version is sqlite 3.6.12, is this an issue or am i missing any
> commands?"
>
> The latest version of SQLCipher is built against 3.7.2, and in fact, I don't
> think any version of SQLCipher ever used 3.6.12 as a baseline. I think it is
> possible that you are running your tests using some pre-installed sqlite
> version on your system, instead of the sqlcipher-enabled binary. Please make
> sure you are running the sqlite3 executable you built from the source
> package, and let us know if this resolves your problem.
>
> Cheers,
> StephenOn Wed, Dec 8, 2010 at 11:41 PM, Seelan <gunaseelan.vel...@gmail.com> wrote:
> > Hey guys,
>
> > I need to use SQL cipher for a project. And have been unable to get a
> > encrypted database from a plain-text database using the ATTACH
> > command.
>
> > I have downloaded the latest versions of SQL Cipher and OpenSSL and
> > successfully built them in xCode.
>
> > I have tried using the ATTACH command for a few days now with no luck,
> > and I'm guessing I made a mistake somewhere. The command that i used
> > to ATTACH is from
> >http://zetetic.net/blog/2009/12/29/how-to-encrypt-a-plaintext-sqlite-...

John

unread,
Jan 6, 2011, 1:34:33 PM1/6/11
to SQLCipher Users
Hi guys

I am having the same problem. When I execute on a terminal window
'sqlite3', then after following the online instructions about the
ATTACH process (http://sqlcipher.net/documentation/api#attach), my
resulted db is not encrypted. So, I am guessing that I am actually
using my Mac's sqlite, and not the one from sqlcipher.

Do you know where can I find the right one? Thanks,
John

Billy Gray

unread,
Jan 6, 2011, 2:03:11 PM1/6/11
to sqlc...@googlegroups.com
Hi John,

You'll need to either specify the full path to the correct executable when you run it, or put it in your PATH. The easiest thing to do is to cd into the directory where you build SQLCipher and run the command there. For instance, if I built sqlcipher in /Users/wgray/Documents/Sources/sqlcipher, then I would do the following in Terminal:

$ cd /Users/wgray/Documents/Sources/sqlcipher
$ ./sqlite3

The './' bit tells the shell to run the file named 'sqlite3' in the current directory.

If it helps, you can determine which sqlite3 executable is being found via your PATH with the following:

$ which sqlite3

Regards,
Billy
--
Team Zetetic
http://zetetic.net

John

unread,
Jan 6, 2011, 2:44:00 PM1/6/11
to SQLCipher Users
Hi Billy

thanks a lot for your prompt reply.

I tried this and get the following error:

*********** terminal output *******

sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret';
dyld: lazy symbol binding failed: Symbol not found:
_EVP_get_cipherbyname
Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace

dyld: Symbol not found: _EVP_get_cipherbyname
Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace

Trace/BPT trap
nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$

***** terminal output end *****

As you can see, the code seems to crash and exits back to the prompt.
Any suggestions?

Best,
John

Billy Gray

unread,
Jan 6, 2011, 2:47:26 PM1/6/11
to sqlc...@googlegroups.com
On Thu, Jan 6, 2011 at 2:44 PM, John <john.kal...@gmail.com> wrote:

I tried this and get the following error:

sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret';
dyld: lazy symbol binding failed: Symbol not found:
_EVP_get_cipherbyname
 Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
 Expected in: flat namespace

dyld: Symbol not found: _EVP_get_cipherbyname
 Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
 Expected in: flat namespace

Trace/BPT trap
nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$

***** terminal output end *****



It looks like you are now using the right build! 

This suggests that openssl isn't being linked in properly when sqlcipher is built. If you are building in XCode, take a look at the Build Results window, and look for linker errors during the libtool phase, or just any bonks during the openssl compile. That'll help us track down what's wrong.

B

Stephen Lombardo

unread,
Jan 6, 2011, 2:58:44 PM1/6/11
to sqlc...@googlegroups.com
Hi John,

It might be helpful if you could attach the exact configure command you're using to build sqlcipher if you are building on the command line. Usually this would be picked up from the Openssl library included with MacOS X. Do you have any login scripts that might be modifying DYLD_LIBRARY_PATH in an odd way?

Cheers,
Stephen

John

unread,
Jan 6, 2011, 4:28:20 PM1/6/11
to SQLCipher Users
Hi

here is what I did step by step, I hope this gives you a better
understanding of the situation.

1. downloaded sqlcipher and openssl source code (/Users/nemesis/
Documents/source/openssl-1.0.0c, and /Users/nemesis/Documents/source/
sqlcipher)
2. followed the tutorial as on how to set up my Xcode project
3. successfully built my project from Xcode. I noticed that
libsqlcipher.a and libcrypto.a where shown as red (not compiled
probably)
4. opened separately the openssl and sqlcipher Xcode projects, and ran
build
5. reopened my original project and rebuilt -> the libs were then
complied
6. couldn't find the correct sqlcipher executable so went to terminal
7. on a terminal window, I typed

nemesis@Ioanniss-MacBook:~$ ./configure --enable-tempstore=yes
CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/Users/nemesis/Documents/source/
openssl-1.0.0/libcrypto.a"
nemesis@Ioanniss-MacBook:~$ make

8. Then went to /Users/nemesis/Documents/source/sqlcipher and typed
(still in terminal)

nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$ ./sqlcipher
unencrypted.sql
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.sql' AS encrypted KEY 'secret';
dyld: lazy symbol binding failed: Symbol not found:
_EVP_get_cipherbyname
Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace
dyld: Symbol not found: _EVP_get_cipherbyname
Referenced from: /Users/nemesis/Documents/source/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace
Trace/BPT trap
nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$

And now I am stuck :) Best,
John

John

unread,
Jan 6, 2011, 4:35:02 PM1/6/11
to SQLCipher Users
Correction!!!

The correct path for the configure and make is this one

nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$

Stephen Lombardo

unread,
Jan 6, 2011, 8:55:35 PM1/6/11
to sqlc...@googlegroups.com
Hi John,

Based on the fact that had already built openssl based on the ios xcode kit, I'm not sure what state libcrypto.a would be in at that point. Please you try to use the following configure command, just to establish a baseline:

./configure --prefix=/path/to/put/sqlcipher --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
make 
make install

Then change to the prefix path and run sqlite3 from there. Let us know if that works. Thanks!

Cheers,
Stephen

John

unread,
Jan 8, 2011, 5:14:10 PM1/8/11
to SQLCipher Users
Hi Stephen

thanks for your help. I removed the source code folders of sqlcipher
and openssl, re-downloaded them and followed the tutorial on using
them for my own project (http://sqlcipher.net/documentation/ios).
Everything compiled fine, but the libraries were still red. So I open
both the openssl and sqlcipher xocde projects, and compiled. The
encryption-enabled sqlite3 was not in the sqlcipher folder, so I went
to the terminal and used the command you suggested above, i.e.

nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$ ./configure --
prefix=/Users/nemesis/Documents/source/sqlcipher --enable-
tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$ make
nemesis@Ioanniss-MacBook:~/Documents/source/sqlcipher$ make install

Here is the output of make install

*** start of terminal output ***

/usr/bin/install -c -d /Users/nemesis/Documents/source/sqlcipher/lib
./libtool --mode=install /usr/bin/install -c libsqlite3.la /Users/
nemesis/Documents/source/sqlcipher/lib
libtool: install: /usr/bin/install -c .libs/libsqlite3.0.dylib /Users/
nemesis/Documents/source/sqlcipher/lib/libsqlite3.0.dylib
libtool: install: (cd /Users/nemesis/Documents/source/sqlcipher/lib &&
{ ln -s -f libsqlite3.0.dylib libsqlite3.dylib || { rm -f
libsqlite3.dylib && ln -s libsqlite3.0.dylib libsqlite3.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libsqlite3.lai /Users/
nemesis/Documents/source/sqlcipher/lib/libsqlite3.la
libtool: install: /usr/bin/install -c .libs/libsqlite3.a /Users/
nemesis/Documents/source/sqlcipher/lib/libsqlite3.a
libtool: install: chmod 644 /Users/nemesis/Documents/source/sqlcipher/
lib/libsqlite3.a
libtool: install: ranlib /Users/nemesis/Documents/source/sqlcipher/lib/
libsqlite3.a
----------------------------------------------------------------------
Libraries have been installed in:
/Users/nemesis/Documents/source/sqlcipher/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
echo 'package ifneeded sqlite3 3.7.2 [list load /System/Library/
Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/sqlite3/
libtclsqlite3.so sqlite3]' > pkgIndex.tcl
/usr/bin/install -c -d /System/Library/Frameworks/Tcl.framework/
Versions/8.5/Resources/Scripts/sqlite3
install: mkdir /System/Library/Frameworks/Tcl.framework/Versions/8.5/
Resources/Scripts/sqlite3: Permission denied
make: *** [tcl_install] Error 71

*** end of terminal output ***

I wouldn't post the output if I didn't see an error message. However,
I went to my sqlcipher path (/Users/nemesis/Documents/source/
sqlcipher) and followed the attach instructions (http://sqlcipher.net/
documentation/api#attach), and... VOILA, my database was encrypted!!!

But I tried to use it from my xcode project like this

*** Obj-C code ***

...
#import <sqlite3.h>
...

- (void)viewDidLoad {
[super viewDidLoad];

sqlite3 *db;
const char *dbFile = [@"/Users/nemesis/Desktop/encrypted.db"
UTF8String];
if (sqlite3_open(dbFile, &db) == SQLITE_OK) {
//sqlite3_exec(db, "PRAGMA key = 'BIGsecret'", NULL, NULL, NULL);

//if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM
sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// // password is correct, or, database has been initialized
// } else {
// // incorrect password!
// }
}
}

*** end of Obj-C code ***

but I get the following error:

*** Xcode build errors ***

Ld "/Users/nemesis/Documents/App Development/xcode-builds/Debug-
iphonesimulator/Crypto.app/Crypto" normal i386
cd /Users/nemesis/Desktop/Crypto
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/
usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/
gcc-4.2 -arch i386 -isysroot /Developer/Platforms/
iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk "-L/
Users/nemesis/Documents/App Development/xcode-builds/Debug-
iphonesimulator" "-F/Users/nemesis/Documents/App Development/xcode-
builds/Debug-iphonesimulator" -filelist "/Users/nemesis/Documents/App
Development/xcode-builds/Crypto.build/Debug-iphonesimulator/
Crypto.build/Objects-normal/i386/Crypto.LinkFileList" -mmacosx-version-
min=10.6 -Xlinker -objc_abi_version -Xlinker 2 "/Users/nemesis/
Documents/App Development/xcode-builds/Debug-iphonesimulator/
libsqlcipher.a" "/Users/nemesis/Documents/App Development/xcode-builds/
Debug-iphonesimulator/libcrypto.a" -framework Foundation -framework
UIKit -framework CoreGraphics -o "/Users/nemesis/Documents/App
Development/xcode-builds/Debug-iphonesimulator/Crypto.app/Crypto"

Undefined symbols:
"_bn_sub_part_words", referenced from:
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status

*** end of Xcode build errors ***

Any ideas? I also tried this alternative

*** code ***
#import <sqlite3.h>
...
sqlite3 *db;
const char *dbFile = [@"/path/to/database" UTF8String];
if (sqlite3_open(dbFile, &db) == SQLITE_OK) {
const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(db, key, strlen(key));

if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM
sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// password is correct, or, database has been initialized
} else {
// incorrect password!
}
}
*** end code ***

and got these build results

*** build errors ***
/Users/nemesis/Desktop/Crypto/Classes/CryptoViewController.m:41:0 /
Users/nemesis/Desktop/Crypto/Classes/CryptoViewController.m:41:
warning: implicit declaration of function 'sqlite3_key'

"_bn_sub_part_words", referenced from:
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
_bn_mul_part_recursive in libcrypto.a(bn_mul.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
*** end build errors ***

Thanks for your ongoing support. Best,
John

Stephen Lombardo

unread,
Jan 11, 2011, 12:50:54 PM1/11/11
to sqlc...@googlegroups.com
Hi John,

Since you had the code compile once successfully, I strongly suspect that when you opened up the sub projects and built them directly you may have introduced the problem. The openssl-xcode and sqlcipher projects are both intended to be included as references, so that they inherit all of the build settings directly from the parent project. Opening them and building them individually is not desirable, and could leave incompatible artifacts in your build path. 

I would Build -> Clean All Targets, including all dependencies and pre-compiled headers. Then, close your Xcode project, reset openssl.xcode and sqlcipher.xcode to their original state and try to rebuild your parent project. If the project builds properly, then everything should be working. I'm not sure why the libraries might be showing red, but that could well be an Xcode quirk.

Please let us know if that works. Thanks!

Cheers,
Stephen

On Sat, Jan 8, 2011 at 5:14 PM, John <john.kal...@gmail.com> wrote:
Hi Stephen

thanks for your help. I removed the source code folders of sqlcipher
and openssl, re-downloaded them and followed the tutorial on using
them for my own project (http://sqlcipher.net/documentation/ios).
Everything compiled fine, but the libraries were still red. So I open
both the openssl and sqlcipher xocde projects, and compiled. The
encryption-enabled sqlite3 was not in the sqlcipher folder, so I went
to the terminal and used the command you suggested above, i.e.
....

John

unread,
Jan 11, 2011, 4:46:31 PM1/11/11
to SQLCipher Users
Hi Stephen

I followed your suggestion, but still the libraries are in a red
state, and what's funny is that, after the Xcode build, I go to my
sqlcipher source directory and the encryption-enabled sqlite3
executable is not there.

Any ideas? Best,
John

Stephen Lombardo

unread,
Jan 11, 2011, 5:44:39 PM1/11/11
to sqlc...@googlegroups.com
Hi John,

I think I understand where the confusion is. Building a SQLCipher IOS application and the command line libraries are two completely separate and unrelated tasks.

The sqlcipher xcode project does not build an encryption-enabled executable. It's solely intended to build an architecture appropriate static library for linking with your iOS application. After a successful build, you should expect your iphone application to be able to generate or use SQLCipher databases via the API, but you should not expect to see any binaries in the SQLCipher source directory. It sounds like this is working for you.

If you want to build a command line binary, that is where you would execute the configure and make steps I provided earlier, on the command line, specifying a prefix of the place you want the sqlcipher binaries to be installed. For example, you might do the following (note disabling tcl should resolve the error you got trying to install the SQLite tcl library in the system paths)

$ ./configure --prefix=/Users/nemesis/Documents/sqlcipher-binaries --disable-tcl --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-l crypto"
$ make
$ make install

Once this complete you should be able to run /Users/nemesis/Documents/sqlcipher-binaries/bin/sqlite3 as a sqlcipher enabled command like on your Mac. 

Please let me know if this clarifies the situation and resolves the problem.

Cheers,
Stephen

John

unread,
Jan 11, 2011, 6:34:52 PM1/11/11
to SQLCipher Users
Hi Stephen

Indeed this clarifies things a lot. Let me briefly explain what my
case is, so you could maybe suggest what a good approach is.

I would like to use a sqlite database on my iphone app. Initially this
db is not encrypted, but I want to encrypt it for obvious reasons. So,
if my understanding is correct, this means that for the encryption of
my db I would need the command line executable, which leads me to
the ./configure command. Afterwards, to be able to use that
(encrypted) db in my iphone app, I need to include the xcode openssl
and sqlcipher projects in my parent project, and build. Is everything
till here correct?

My terminal configure command, and the xcode build both work, but the
xcode libraries still remain in a red state. Another problem I have,
is that I get the compilation error I mentioned above (Undefined
symbols:
"_bn_sub_part_words", referenced from:
_bn_mul_recursive in libcrypto.a(bn_mul.o) etc etc)
when I try to actually code the reading/opening/accessing of my db.

Additionally, I have noted in the API documentation that for opening
the encrypted db I should use
sqlite3_exec(db, "PRAGMA key = 'BIGsecret', NULL, NULL, NULL);
Isn't there a " missing somewhere??

I apologize for bombarding you with messages, but it's really
frustrating to have something so powerful at your disposal, but not
being able to use it. Best,
John

PS: Is there a way to uninstall/remove the files which the triplet
"configure-make-make install" generated?
Message has been deleted

Stephen Lombardo

unread,
Jan 14, 2011, 1:35:04 AM1/14/11
to sqlc...@googlegroups.com
Hi John,

I have a few questions and comments, which you'll find in line below.

On Tue, Jan 11, 2011 at 6:34 PM, John <john.kal...@gmail.com> wrote:
Hi Stephen

Indeed this clarifies things a lot. Let me briefly explain what my
case is, so you could maybe suggest what a good approach is.

I would like to use a sqlite database on my iphone app. Initially this
db is not encrypted, but I want to encrypt it for obvious reasons. So,
if my understanding is correct, this means that for the encryption of
my db I would need the command line executable, which leads me to
the ./configure command. Afterwards, to be able to use that
(encrypted) db in my iphone app, I need to include the xcode openssl
and sqlcipher projects in my parent project, and build. Is everything
till here correct?

If you want to encrypt the database before distribution, then it is probably easiest to use the command line tool to do so. However, you could also create the encrypted database from inside your application too. Are you planning to bundle an encrypted application with your application? 
 
My terminal configure command, and the xcode build both work, but the
xcode libraries still remain in a red state. Another problem I have,
is that I get the compilation error I mentioned above (Undefined
symbols:
 "_bn_sub_part_words", referenced from:
     _bn_mul_recursive in libcrypto.a(bn_mul.o)  etc etc)
when I try to actually code the reading/opening/accessing of my db.

Here are two other things you might try:

1. Make sure your SDK versions are aligned with the simulator, per http://groups.google.com/group/sqlcipher/browse_thread/thread/795ab893de459310
2. Make sure that you have both sqlcipher and libcrypto.a set up to be linked to your application

If neither of these work, it would be very helpful if you could screenshot the entire expanded left navigation for your application.

Finally, if you are still having trouble, I'd like it if you could download a "known-good" codebase, ideally SQLCIpherSpeed from gihub here:


Try to build this application and see if it works. If it does we could at least be sure that the problem has to do with your XCode project settings and not some external issue.

Additionally, I have noted in the API documentation that for opening
the encrypted db I should use
sqlite3_exec(db, "PRAGMA key = 'BIGsecret', NULL, NULL, NULL);
Isn't there a " missing somewhere??

Yes, there should be a quote enclosing the end of the SQL statement. You could also consider using sqlite3_key from within your application, which will do the same think and avoid the need to encode the password in a pragma call.

PS: Is there a way to uninstall/remove the files which the triplet
"configure-make-make install" generated?

I'm not aware of any, other than to remove the files from under the path you specified to --prefix.

Please let us know how it goes from here, I hope we'll be able to resole the issues soon. Thanks!

Cheers,
Stephen
 

John

unread,
Jan 16, 2011, 5:03:51 PM1/16/11
to SQLCipher Users
Hi Stephen

I am really disappointed, nothing actually seems to work. For your
information, I have installed the latest iOS SDK (4.2), and Xcode
3.2.5

> If you want to encrypt the database before distribution, then it is probably
> easiest to use the command line tool to do so. However, you could also
> create the encrypted database from inside your application too. Are you
> planning to bundle an encrypted application with your application?

I am planning to include an encrypted database file in my app. The db
will be read from within the app.

> Here are two other things you might try:
> 1. Make sure your SDK versions are aligned with the simulator, perhttp://groups.google.com/group/sqlcipher/browse_thread/thread/795ab89...

As mentioned above, I am running iOS SDK 4.2, and can't figure out how
to set a different SDK (the only one available and installed on my
machine is 4.2)

> 2. Make sure that you have both sqlcipher and libcrypto.a set up to be linked to your application

I always link them, but they are always shown in a red state.

> If neither of these work, it would be very helpful if you could screenshot the entire expanded left navigation for your application.

Please have a look here http://www.mediafire.com/?opf882dr9s8iqr3

> Finally, if you are still having trouble, I'd like it if you could download
> a "known-good" codebase, ideally SQLCIpherSpeed from gihub here:
>
> https://github.com/sjlombardo/SQLCipherSpeed
>
> Try to build this application and see if it works. If it does we could at
> least be sure that the problem has to do with your XCode project settings
> and not some external issue.
>

Unfortunately, neither my app works nor SQLCipher. Have a look here
for SQLCipher build results http://www.mediafire.com/?2uhx0cgxb9xcgv1.

> PS: Is there a way to uninstall/remove the files which the triplet
>
> > "configure-make-make install" generated?
>
> I'm not aware of any, other than to remove the files from under the path you
> specified to --prefix.

I would like to remove any files installed under /System/Library,
cause I tried the configure command with sudo, so the permission error
was lifted.

Thanks for your help. Best,
John

PS: I apologize for the clumsy address to download the snapshots, but
my server is currently down.

Stephen Lombardo

unread,
Jan 16, 2011, 5:26:20 PM1/16/11
to sqlc...@googlegroups.com
Hi John,

Thanks for the detailed response. I'll take a look at the screenshots shortly. In the mean time, what version of OpenSSL are you using? Is it 1.0.0 or greater? If not, that may be a contributing problem. I ask because some older versions of the iOS tutorial (i.e. on Mobile Orchard) referenced older versons of OpenSSL.  

Cheers,
Stephen

Sam

unread,
Jan 16, 2011, 6:13:21 PM1/16/11
to SQLCipher Users
Hi John,

Just to let you know that I just followed Mobile Orchard instructions
and successfully compiled
https://github.com/sjlombardo/SQLCipherSpeed

I have latest openssl-1.0.0c, Xcode 3.2.5 and run debug code on the
simulator and my 3GS iphone with iOs 4.0.

The project was already configured for dependencies so there is no
need to do anything just run XCode. Of course you have to have openssl
and sqlcipher in place and global paths set for in Xcode as per
Orchard instructions.

The db were created in /Users/SG/Library/Application Support/iPhone
Simulator/4.2/Applications/E0E4D1F6-8406-462F-8F8F-6A24129DCF20/
documents. Mind you, there are deleted after the tests.

Review your steps. Good luck. Compiling this project was a pleasant
experience for me. Thank you Stephen for SQLCipherSpeed!

Sam

Sam

unread,
Jan 16, 2011, 6:45:16 PM1/16/11
to SQLCipher Users
John,

I looked at your screenshots. Looks that your libs have not compiled
at all.

I am afraid that you might forget about global paths for XCode.

My projects compiled. The only small warning where:

"
Build SQLCipherSpeed of project SQLCipherSpeed with configuration
Debug

CompileXIB ResultViewController.xib
cd /Users/SG/Documents/code/SQLCipherSpeed
setenv IBC_MINIMUM_COMPATIBILITY_VERSION 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/
Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/usr/bin/ibtool --errors --warnings --notices --output-
format human-readable-text --compile /Users/SG/Documents/code/xcode-
build/Debug-iphoneos/SQLCipherSpeed.app/ResultViewController.nib /
Users/SG/Documents/code/SQLCipherSpeed/ResultViewController.xib --sdk /
Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk

/* com.apple.ibtool.document.warnings */
/Users/SG/Documents/code/SQLCipherSpeed/ResultViewController.xib:-1:
warning: The 'navigationItem' outlet of a UIViewController has been
deprecated. Navigation items are required prior to loading a view
controller's view. Instead of an outlet, consider embedding the
navigation item in the view controller.
/Users/SG/Documents/code/SQLCipherSpeed/ResultViewController.xib:-1:
warning: The 'navigationItem' outlet of 'File's Owner' is connected to
'Navigation Item (Test Results)' but 'navigationItem' is no longer
defined on ResultViewController.

CompileXIB TestResultCell.xib
cd /Users/SG/Documents/code/SQLCipherSpeed
setenv IBC_MINIMUM_COMPATIBILITY_VERSION 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/
Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/usr/bin/ibtool --errors --warnings --notices --output-
format human-readable-text --compile /Users/SG/Documents/code/xcode-
build/Debug-iphoneos/SQLCipherSpeed.app/TestResultCell.nib /Users/SG/
Documents/code/SQLCipherSpeed/TestResultCell.xib --sdk /Developer/
Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk

/* com.apple.ibtool.document.warnings */
/Users/SG/Documents/code/SQLCipherSpeed/TestResultCell.xib:-1:
warning: The 'resultCell' outlet of 'File's Owner' is connected to
'Test Result Cell' but 'resultCell' is no longer defined on
RootViewController.
"
which may be due to my settings for target 4.0
Sam

John

unread,
Jan 17, 2011, 3:05:34 AM1/17/11
to SQLCipher Users
> What version of OpenSSL are you using? Is it
> 1.0.0 or greater? If not, that may be a contributing problem. I ask because
> some older versions of the iOS tutorial (i.e. on Mobile Orchard) referenced
> older versons of OpenSSL.

@Stephen
To make things crystal clear, I am using OpenSSL 1.0.0-c, Xcode 3.2.5
and iOS SDK 4.2 (I recently upgraded from 4.0)

> The project was already configured for dependencies so there is no
> need to do anything just run XCode. Of course you have to have openssl
> and sqlcipher in place and global paths set for in Xcode as per
> Orchard instructions

@Sam
Hi Sam, thanks for your interest and your two cents in this. I have
indeed set my global paths and followed the tutorial instructions.
Still, the libs seem not to be compiled (the red state I mention),
even though Xcode goes through the build phases of each.

Stephen Lombardo

unread,
Jan 19, 2011, 1:47:48 PM1/19/11
to sqlc...@googlegroups.com
Hi John,

I'm sorry that you're still having trouble. I've looked over the screenshots, and re-reviewed this thread. I'm really not sure what could be causing the problem for you at this point, but I'm fairly certain it's environmental. 

The final thing that we could do is take a look at your full build results. Could you do a Clean with all dependencies, copy / paste the full log of your application build into a https://gist.github.com/ or pastie,org so that we could review it?

Thanks!

Cheers,
Stephen

John

unread,
Jan 19, 2011, 4:52:29 PM1/19/11
to SQLCipher Users
Hi Stephen

here are three files: https://gist.github.com/786912

*the SQLCipherSpeed build results
*my app-specific view controller where I try to use the database
*my app build results

Each time I tried to built, I cleaned all previous builds and
dependencies, and also deleted all folders under my global xcode-
builts folder. Have a look here for a snapshot of my Xcode settings
http://www.mediafire.com/?vcsjo8md3x6805d.

I hope this helps. Best,
John

Stephen Lombardo

unread,
Jan 19, 2011, 10:52:43 PM1/19/11
to sqlc...@googlegroups.com
Hi John,

The log was very helpful. The good news is this should be super easy for you to fix. After reviewing the full build log it's clear that the issue lies here:

Configuring for darwin-i386-cc
target already defined - darwin-i386-cc (offending arg: Development/xcode-builds)
making all in crypto...

Configure appears to have failed to process the custom options we provide, including no-gost. Given the "offending arg" comment, this is because your build path contains a space, and the openssl config script is not parsing it. I checked and openssl-excode has quoted "$BUILD_DIR", so I suspect this might be a problem with the OpenSSL config script, but I can't be sure without further testing. 

OpenSSL has a known issue including gost on darwin-i386-cc build targets, so openssl-xcode includes a patch to exclude that algorithm (https://github.com/sjlombardo/openssl-xcode/tree/a3791dbcaf87d6fac5a9213587e0253dea17e090). Unfortunately, due to the space in your path, openssl is being configured without the no-gost option. This manifests as the linker errors you are seeing.

The solution should be very easy. Open your XCode preferences, switch to the "Building" tab, and change your build directory from "/Users/nemesis/Documents/App Development/xcode-builds" to a path that doesn't contain a space. Restart XCode and then try to rebuild.

Let me know if this fixes the problem. Thanks!

Cheers,
Stephen

John

unread,
Jan 20, 2011, 3:10:17 PM1/20/11
to SQLCipher Users
Argggggg!!!!! Can you hear my head banging on the wall!!???!!???

It was this little detail, I wish I was smart enough to post my build
results earlier, so we don't waste our time. Thanks a lot for your
continuing support, help and encouragement.

By the way, for everyone following this post, there is a typing error:
in the ./configure command (in terminal) instead of
LDFLAGS="-l crypto"
you should use
LDFLAGS="-lcrypto"

i.e. with no space, otherwise it didn't work for me. Additionally,
what did not work for me was
sqlite3_exec(db, "PRAGMA key = 'BIGsecret', NULL, NULL, NULL);
but this did
sqlite3_exec(db, ["PRAGMA key = 'BIGsecret' UTF8String], NULL, NULL,
NULL);

If you don't hear back from me, then that should be good news ;)

Best,
John

Sam

unread,
Jan 20, 2011, 3:21:03 PM1/20/11
to SQLCipher Users
John,

Good to hear good news.

By the way, didn't you forget " somewhere here:
>sqlite3_exec(db, ["PRAGMA key = 'BIGsecret' UTF8String], NULL, NULL,
NULL);
?

John

unread,
Jan 20, 2011, 3:57:04 PM1/20/11
to SQLCipher Users
Actually yes, cause I just copy-pasted that line from the sqlcipher
API website, where Stephen has already mentioned that this " is indeed
missing ;)

Cheers
John
Reply all
Reply to author
Forward
0 new messages