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.
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
static volatile sig_atomic_t intr_signal;
to
static volatile int intr_signal;
for preventing building error
Build OpenSSL for i368 iPhoneSimulator:
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:
CC= /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386
Add as first item to CFLAG:
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk
Build it:
make make install
Your libcrypto.a and libssl.a are in the folder openssl_i368/lib
Build OpenSSL for armv6 iOS:
mv openssl_i386 ../ssllibs make clean ./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_armv6
Edit Makefile:
Change CC = cc to:
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6
Add as first item to CFLAG:
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
Build it:
make make install
Your libcrypto.a and libssl.a are in the folder openssl_armv6/lib
Build OpenSSL for armv7 iOS:
mv openssl_armv6 ../ssllibs make clean ./configure BSD-generic32 --openssldir=/Users/<username>/openssl-1.0.0a/openssl_armv7
Edit Makefile:
Change CC = cc to:
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7
Add as first item to CFLAG:
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
Build it:
make make install
Your libcrypto.a and libssl.a are in the folder openssl_armv7/lib
Create universal libs:
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
$(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: