Under the Bridge

iPhone OpenSSL

So if you have any desktop code that involves secure communications, chances are pretty darn good that it involves the OpenSSL library. And when you begin to port said code that involves secure communications to the iPhone, you promptly find … it’s not there! At least, for a value of “not there” which is “not exposed in the official SDK”. Issues with encryption export, it seems; apparently Apple’s own apps using encryption on the phone doesn’t cover third party apps? Or something. But for whatever reason, it’s not there, and you have to build your own. And here we have some help for you with that:

Tutorial: How To Compile OpenSSL for the iPhone

Walks you through getting the source, sorting out iPhone architecture settings, and building it. Or, if you have a troll’s attitude to work, skip straight to the last paragraph:

Some people had some questions about how to use the libraries in an Xcode project. Here is a simple xcode project including just the linking of the libraries and adding of the header files: openssl_tutorial

For the lazy people. Compiled libraries: compiled_libraries

Although his nomenclature needs a little bit of work. It’s not about being “lazy”. It’s about being efficient. Although, granted, the line can be fine indeed.

As an alternative, if you’d like to integrate it into your Xcode build process, check out

Tutorial: iPhone SQLite Encryption With SQLCipher

which includes the aside

OpenSSL can be a tricky system to compile properly from source. It’s even more complex when you’re dealing with multiple target architectures, targeting i386 for the simulator but armv6 for a device. Luckily we’ve built a handy XCode project template to make it easy called openssl-xcode. The project actually relies on the OpenSSL configure and make system to build the libraries. However, it automatically detects the appropriate build settings for architecture (i386, ppc, arv6), build tools, and SDK. This makes it ideal for inclusion in an iPhone project. Just git clone or download openssl-xcode from GitHub and move the openssl.xcodeproj file into the OpenSSL source directory.

We’re quite satisfied with just linking straight to the prebuilt libraries and pretending like we’re linking to system libraries on the desktop … but hey, if you want complete build control, there you go!

1
  • W

    Alex,
    Thanks for this post! It may well have saved our project. Something as critical as good encryption should be accessible, and you have made it so.
    Regards,
    W