Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling the latest OpenSSL for Android

I am trying to generate the shared library for the (.so) files of the OpenSSL1.0.1c for the Android. I found that they have added three options for compiling for the Android in the android script.

./Configure android-armv7  (or) ./Configure android-x86    (or) ./Configure android 

once I configured for the OS and then try to compile, its throwing errors. Currently I am working x86 windows7 and installed Cygwin, Android sdk R20, Android NDK r8

sh-4.1$ make making all in crypto... make[1]: Entering directory `/cygdrive/d/SourceCodes/OpenSSL/openssl-1.0.1c/crypto' gcc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=armv7-a -mandroid -I/include -B/lib -O3 -fomit-frame-pointer -Wall -DOPENSSL_BN_ASM_MONT -DOP ENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DGHASH_ASM   -c -o cryptlib.o cryptlib.c cc1: error: unrecognized command line option "-mandroid" cryptlib.c:1:0: error: bad value (armv7-a) for -march= switch <builtin>: recipe for target `cryptlib.o' failed make[1]: *** [cryptlib.o] Error 1 make[1]: Leaving directory `/cygdrive/d/SourceCodes/OpenSSL/openssl-1.0.1c/crypto' Makefile:278: recipe for target `build_crypto' failed make: *** [build_crypto] Error 1 sh-4.1$ 

Please let me know if anyone faced the similar issue and got the solution for resolving the same.

like image 798
Suman Avatar asked Aug 13 '12 07:08

Suman


People also ask

What is Openssldir?

OpenSSL is a very important library, widely used in numerous open source and closed source applications. This library has an internal directory tree that is used to locate the configuration file and this directory is called OPENSSLDIR. Inside OPENSSLDIR resides the configuration file openssl.


2 Answers

I would seriously not advise to grab anything outside of the official OpenSSL web site. You cannot take a chance when dealing with cryptography and security.

The only problem that I see is that you are using your host's gcc rather than using android's cross compilers.

Here is how I would compile the official OpenSSL on Ubuntu 14.04LTS (this works with OpenSSL 1.0.1g)

From your home folder, run the following commands:

tar xzvf ~/Downloads/openssl-1.0.1g.tar.gz cd openssl-1.0.1g export NDK=~/android-ndk-r9d $NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.6 --install-dir=`pwd`/android-toolchain-arm export TOOLCHAIN_PATH=`pwd`/android-toolchain-arm/bin export TOOL=arm-linux-androideabi export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL} export CC=$NDK_TOOLCHAIN_BASENAME-gcc export CXX=$NDK_TOOLCHAIN_BASENAME-g++ export LINK=${CXX} export LD=$NDK_TOOLCHAIN_BASENAME-ld export AR=$NDK_TOOLCHAIN_BASENAME-ar export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib export STRIP=$NDK_TOOLCHAIN_BASENAME-strip export ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" export ARCH_LINK="-march=armv7-a -Wl,--fix-cortex-a8" export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions " export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export LDFLAGS=" ${ARCH_LINK} " 

And then run your configure script:

./Configure android-armv7 

And then build

PATH=$TOOLCHAIN_PATH:$PATH make 

You should see that it is using arm-linux-androideabi-gcc instead of gcc

To build for the old armeabi:

tar xzvf ~/Downloads/openssl-1.0.1g.tar.gz cd openssl-1.0.1g export NDK=~/android-ndk-r9d $NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.6 --install-dir=`pwd`/android-toolchain-arm export TOOLCHAIN_PATH=`pwd`/android-toolchain-arm/bin export TOOL=arm-linux-androideabi export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL} export CC=$NDK_TOOLCHAIN_BASENAME-gcc export CXX=$NDK_TOOLCHAIN_BASENAME-g++ export LINK=${CXX} export LD=$NDK_TOOLCHAIN_BASENAME-ld export AR=$NDK_TOOLCHAIN_BASENAME-ar export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib export STRIP=$NDK_TOOLCHAIN_BASENAME-strip export ARCH_FLAGS="-mthumb" export ARCH_LINK= export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions " export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export LDFLAGS=" ${ARCH_LINK} " ./Configure android make clean PATH=$TOOLCHAIN_PATH:$PATH make 

to build for x86 :

tar xzvf ~/Downloads/openssl-1.0.1g.tar.gz cd openssl-1.0.1g export NDK=~/android-ndk-r9d $NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86-4.6 --install-dir=`pwd`/android-toolchain-x86 export TOOLCHAIN_PATH=`pwd`/android-toolchain-x86/bin export TOOL=i686-linux-android export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL} export CC=$NDK_TOOLCHAIN_BASENAME-gcc export CXX=$NDK_TOOLCHAIN_BASENAME-g++ export LINK=${CXX} export LD=$NDK_TOOLCHAIN_BASENAME-ld export AR=$NDK_TOOLCHAIN_BASENAME-ar export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib export STRIP=$NDK_TOOLCHAIN_BASENAME-strip export ARCH_FLAGS="-march=i686 -msse3 -mstackrealign -mfpmath=sse" export ARCH_LINK= export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions " export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 " export LDFLAGS=" ${ARCH_LINK} " ./Configure android-x86 make clean PATH=$TOOLCHAIN_PATH:$PATH make 
like image 119
mchiasson Avatar answered Sep 28 '22 03:09

mchiasson


In OpenSSL 1.0.1e, all I need to do is:

CC=~/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc ./Configure android-armv7 ANDROID_DEV=~/android-ndk-r9//platforms/android-8/arch-arm/usr make build_libs 
like image 44
James Moore Avatar answered Sep 28 '22 02:09

James Moore