Recently I had to add In-App Purchases to an app I am developing as a personal hobby. Dealing with IAP alone can be a pain if you don’t know much about cryptography, but luckily there are many libraries that make this process simpler.

But here’s a small catch: Almost all of the IAP libraries (and many other libraries you will want to use) require OpenSSL. Particularly libraries that deal with cryptography may need it. With the release of the iPhone 5S and it’s 64-Bit processor, it is a little bit tricky to compile it and get it to work.

At first I found a pre-compiled version of OpenSSL and added it to my project. The problem was that I was only testing with an iPod Touch 5, and as such I didn’t see many potential problems with the different processor architecture of the 5S. I used that pre-compiled OpenSSL library for a while until I tested it on my iPhone 5S and oh boy. Whenever  I tried to compile for ARM64, it complained that all the cryptography-related symbols were not found.

Luckily, compiling OpenSSL to work with both ARM and ARM64 is really easy and fast.

Step by step:

  1. Download this shell script.
  2. Create a new directory and cd to it. It’s easier to see all the generated files this way (for the sake of simplicity, I created a “pls” directory in my Documents directory and cd to it).
  3. Run it on terminal:

    This will do most of the hard work for you: It will download OpenSSL, compile it, and create OpenSSL libraries for both ARM, ARM64, and even for Mac!
    Please note that executing this script may take a few minutes. Not only does it have to download OpenSSL, but it also has to compile it and it is a middle-sized library. It shouldn’t take longer than 5 minutes in an i5 processor, but still patience is to be expected.

    The output should be something like this:

    Cleaning up
    Downloading openssl-1.0.1e.tar.gz
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 4355k  100 4355k    0     0   8618      0  0:08:37  0:08:37 --:--:--  5299
    Unpacking openssl
    Building openssl-1.0.1e for i386
    Building openssl-1.0.1e for x86_64
    Copying headers
    Building Mac libraries
    Building openssl-1.0.1e for iPhoneOS 7.0 armv7
    Building openssl-1.0.1e for iPhoneOS 7.0 armv7s
    Building openssl-1.0.1e for iPhoneOS 7.0 arm64
    Building openssl-1.0.1e for iPhoneSimulator 7.0 x86_64
    Building openssl-1.0.1e for iPhoneSimulator 7.0 i386
    Building iOS libraries
    Adding 64-bit libraries
    Cleaning up
  4. In the directory you created on step 2, you should now have two directories and one file: “include”, “lib”, and “openssl-VERSION_NUMBER.tar.gz”. Y0u can ignore the latter.
  5. Open “lib”. It should have a total of 4 files. This is intuitive but I will state it for the sake of completeness: For iOS, you’re only interested in “libcrypto_iOS.a” and “libssl_iOS.a”.
  6. In your XCode project, open its settings and go to the “Build Phases” tab. Extend “Link Binary with Libraries” and drag and drop both .a files from the step above there.
  7. Now go to the “Build Settings” tab, look for “Search Paths”,  and then “Header Search Paths”. Double click it until you see a menu like this:

    Screenshot 2014-01-14 03.26.43

  8. Like you can see in the screenshot, I just dragged the entire “include” directory there. This directory has an openssl directory, but you don’t need to concern yourself with it.

And that’s it! You should now be able to use OpenSSL with both ARM and ARM64 applications.

Positive SSL