Issue
I need to build latest tor for Android on Linux, for successive use in Tor Onion Proxy Library.
Current latest stable tor is maint-0.3.1.
I am using Android NDK r15b.
Solution
I have prepared a solution that I am going to show below. It is a composition of various sources. The script can be further optimized.
The instructions allow to build tor using:
- Android SDK 25
- Android NDK r15b
- tor maint-0.3.1
- openssl1.1.0f
- libevent 2.0.23-stable-rc
The main steps are:
- build openssl
- build libevent
- build tor
The complete script can be downloaded here.
Specify the location of installed ndk:
export ANDROID_NDK_HOME=/home/marco/Android/ndkr15b
We create and work in a folder called 'native':
rm -Rf native
mkdir native
mkdir native/lib
cd native
Build openssl
See also these instructions.
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
setenv-android.sh can be downloaded from here and edited, or use this version already modified to use _ANDROID_EABI="arm-linux-androideabi-4.9".
# ANDROID_NDK_ROOT is required by setenv-android.sh
export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
. ../setenv-android.sh
# ANDROID_TOOLCHAIN is now set
tar -xvzf openssl-1.1.0f.tar.gz
cd openssl-1.1.0f
# openssl engine is needed by libevent
./config shared no-ssl2 no-ssl3 no-comp no-hw --openssldir=/usr/local/ssl/android-16/
make depend
make all
take care: the next command installs cross compiled headers and libs respectively in /usr/local/include/openssl, /usr/local/lib/. Crosscompiled libs will be used in the final step when linking tor.
sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib
cd ..
# go back to native folder
# when linking to, openssl libraries are still linked from /usr/local/lib/
cp ./openssl-1.1.0f/'*'.a lib/
cp -R ./openssl-1.1.0f/include/openssl ./include
Build libevent
rm -Rf libevent
we need to remove the reference to arc4random_addrandom, for convenience we can use this repo of corrected libevent. See the diff.
git clone https://github.com/marcotessarotto/libevent
cd libevent
export NDK=$ANDROID_NDK_ROOT
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-16 --toolchain=arm-linux-androideabi-4.9 --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 -D__ANDROID_API__=16 "
export CXX="$NDK_TOOLCHAIN_BASENAME-g++ -D__ANDROID_API__=16 "
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} "
./autogen.sh
./configure --host=arm-linux-androideabi
make
# all tests should pass successfully
#copy headers and libary in work folder
cp .libs/libevent.a ../lib
cp -R include/* ../include
cd ..
Build tor
git clone https://github.com/torproject/tor
cd tor/
git checkout remotes/origin/maint-0.3.1
export NDK_ROOT=$ANDROID_NDK_ROOT
echo "SETTING UP CROSS COMPILER"
# export needed variables
export NDK_TOOLCHAIN=$NDK_ROOT/my-android-toolchain
# remove the old toolchain
rm -rf $NDK_TOOLCHAIN
# create the toolchain
$NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-16 --install-dir=$NDK_TOOLCHAIN
# export needed variables for crosscompile
export PATH="$NDK_TOOLCHAIN/bin/:$PATH"
export HOST=arm-linux-androideabi
export CC=$HOST-gcc
export CXX=$HOST-g++
export AR=$HOST-ar
export LD=$HOST-ld
export AS=$HOST-as
export NM=$HOST-nm
export STRIP=$HOST-strip
export RANLIB=$HOST-ranlib
export OBJDUMP=$HOST-objdump
export CPPFLAGS="--sysroot=$NDK_TOOLCHAIN/sysroot -I$NDK_TOOLCHAIN/sysroot/usr/include -I$NDK_TOOLCHAIN/include -I../include -L../lib "
export LDFLAGS="-L$NDK_TOOLCHAIN/sysroot/usr/lib -L$NDK_TOOLCHAIN/lib -L../lib"
export CC="$HOST-gcc -D__ANDROID_API__=16 "
export CXX="$HOST-g++ -D__ANDROID_API__=16 "
./autogen.sh
./configure --host=arm-linux-eabi --disable-asciidoc --prefix=$NDK_TOOLCHAIN --with-openssl-dir=../lib --enable-static-openssl --with-libevent-dir=../lib --enable-static-libevent
make
#some tests fail on compilation, but tor is built (in src/or/tor) and I confirm that it works on Android 6
cd ..
Here is the logcat from starting tor (0.3.2.0-alpha-dev) using patched Tor Onion Proxy Library (see below):
09-14 12:25:43.059 13520-13544/? I/c*.m*.t*.t*.c: Sep 14 12:25:43.058 [notice] Tor 0.3.2.0-alpha-dev (git-d71a00e91f3921f6) running on Linux with Libevent 2.0.23-stable, OpenSSL 1.1.0f, Zlib 1.2.8, Liblzma N/A, and Libzstd N/A.
09-14 12:25:43.060 13520-13544/? I/c*.m*.t*.t*.c: Sep 14 12:25:43.058 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
09-14 12:25:43.060 13520-13544/? I/c*.m*.t*.t*.c: Sep 14 12:25:43.058 [notice] This version is not a stable Tor release. Expect more bugs than usual.
09-14 12:25:43.060 13520-13544/? I/c*.m*.t*.t*.c: Sep 14 12:25:43.059 [notice] Read configuration file "/data/user/0/com.example.vpnandroidclient/app_torfiles/torrc".
09-14 12:25:43.080 13520-13544/? I/c*.m*.t*.t*.c: Sep 14 12:25:43.079 [notice] I think we have 8 CPUS, but only 2 of them are available. Telling Tor to only use 2. You can override this with the NumCPUs option
09-14 12:26:04.593 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 53%: Loading relay descriptors
09-14 12:26:07.023 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 59%: Loading relay descriptors
09-14 12:26:08.472 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 67%: Loading relay descriptors
09-14 12:26:09.027 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 72%: Loading relay descriptors
09-14 12:26:09.689 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 78%: Loading relay descriptors
09-14 12:26:10.301 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 80%: Connecting to the Tor network
09-14 12:26:11.633 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Bootstrapped 90%: Establishing a Tor circuit
09-14 12:26:14.637 13520-13548/? I/c*.m*.t*.t*.d: message: severity: NOTICE, msg: Tor has successfully opened a circuit. Looks like client functionality is working.
Tor Onion Proxy Library
In order to use the latest tor version (when writing: 0.3.2.0 alpha-dev), the torrc configuration mus be produced differently by Tor Onion Proxy Library, since the most recent tor is more stringent on relative paths inside its configuration file (tor will exit if relative file name are specified).
The patched Tor Onion Proxy Library can be found here.
Answered By - mrtexaz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.