Tutorial: iPhone App With Compiled OpenSSL 1.0.0a Library

| Comments

This is a tutorial for using self-compiled builds of the OpenSSL-library on the iPhone. You can build apps with XCode and the official SDK from Apple with this. I also made a small example-app for using the libraries with XCode and the iPhone/iPhone-Simulator. You can also download the precompiled OpenSSL-library (1.0.0a).

This tutorial works with OpenSSL 1.0.0a and Xcode 3.2.3 with iOS 4.

Update: Script for automatic building OpenSSL (currently 1.0.0d) for iOS: http://www.x2on.de/2010/12/16/tutorial-script-for-building-openssl-for-ios-iphoneipad/

You can find the tutorial for OpenSSL 0.9.8 at http://www.x2on.de/2010/02/01/tutorial-iphone-app-with-compiled-openssl-library/

You can get the Source of the example app with compiled OpenSSL at http://github.com/x2on/OpenSSL-for-iPhone

Create OpenSSL Libary:

Download OpenSSL Sourcecode

Change in crypto/ui/ui_openssl.c

1
static volatile sig_atomic_t intr_signal;

to

1
static volatile int intr_signal;

for preventing building error

Build OpenSSL for i368 iPhoneSimulator:

1
2
3
4
mkdir ssllibs
cd openssl-1.0.0a
mkdir openssl_armv6 openssl_armv7 openssl_i386
./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_i386
Edit Makefile:

Change CC = cc to:

1
CC= /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386

Add as first item to CFLAG:

1
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk
Build it:
1
2
make
make install

Your libcrypto.a and libssl.a are in the folder openssl_i368/lib

Build OpenSSL for armv6 iOS:

1
2
3
mv openssl_i386 ../ssllibs
make clean
./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_armv6
Edit Makefile:

Change CC = cc to:

1
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6

Add as first item to CFLAG:

1
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
Build it:
1
2
make
make install

Your libcrypto.a and libssl.a are in the folder openssl_armv6/lib

Build OpenSSL for armv7 iOS:

1
2
3
mv openssl_armv6 ../ssllibs
make clean
./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_armv7
Edit Makefile:

Change CC = cc to:

1
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7

Add as first item to CFLAG:

1
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
Build it:
1
2
make
make install

Your libcrypto.a and libssl.a are in the folder openssl_armv7/lib

Create universal libs:

1
2
3
cp -r openssl_armv7/include ../ssllibs/
lipo -create ../ssllibs/openssl_i386/lib/libcrypto.a ../ssllibs/openssl_armv6/lib/libcrypto.a openssl_armv7/lib/libcrypto.a -output ../ssllibs/libcrypto.a
lipo -create ../ssllibs/openssl_i386/lib/libssl.a ../ssllibs/openssl_armv6/lib/libssl.a openssl_armv7/lib/libssl.a -output ../ssllibs/libssl.a

Edit your iPhone-XCode project:

Copy the “include” folder from OpenSSL into your project-folder

Copy the libcrypto.a and libssl.a files into your project-folder

Drag the libcrypto.a and libssl.a files into your XCode Framework Folder-Tree

Open the Build-Info from your “Target” (Righclick on Target - Get Info)

Change _Library Search Paths_ to

1
$(inherited) "$(SRCROOT)"

Change _User Header Search Paths_ to _include_

Activate _Always Search User Paths_

Enjoy OpenSSL on the iPhone!

I have made an iOS 3.2/4.0 XCode Project with OpenSSL 1.0.0a libaries. The examples uses the MD5-algorithm to calculate an md5 hash from an UITextfield.

Download: http://github.com/x2on/OpenSSL-for-iPhone

Disclaimer: Use this at your own risk.

Links:

Sponsor

Comments