Skip to content

Commit a959613

Browse files
Merge pull request #13 from bandi13/addAndroid
Add in sample IDE/android environment
2 parents 1da3d1e + a5566f8 commit a959613

5 files changed

Lines changed: 167 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@
5555
# Installed dependencies
5656
/openssl*
5757
/wolfssl*
58+
59+
IDE/Android/android-ndk-r26b/
60+
IDE/Android/openssl/
61+
IDE/Android/openssl-install/
62+
IDE/Android/wolfssl/
63+
IDE/Android/wolfssl-install/
64+
IDE/Android/wolfProvider/

IDE/Android/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Installing WolfProvider on Android
2+
3+
# Prerequisites
4+
You will need Android Studio to run an emulator. Though having an Android device plugged in via USB and able to connect via ADB should also work.
5+
6+
This example works with an x86_64 version of Android, but it should be relatively simple to change and use ARM or ARM64. You would need to modify `build.sh`.
7+
8+
You'll need to get the [Android NDK](https://developer.android.com/ndk/downloads/). I used [this one](https://dl.google.com/android/repository/android-ndk-r26b-linux.zip). The `build.sh` script should do this for you.
9+
10+
# Usage
11+
Have your Android device up and running. You can confirm it is reachable with `adb devices`.
12+
13+
Run the `build.sh` command which will compile OpenSSL as well as WolfProvider. Once the libraries are built, it will remove the symbolic links from the folders (because `adb push` is unable to deal with them). Lastly it will upload the files to `/data/local/tmp` on your Android device. It will also copy `run.sh` and execute it.
14+
15+
`run.sh` is a script that will attempt to run OpenSSL with wolfProvider and should output something like:
16+
```
17+
Providers:
18+
libwolfprov
19+
name: wolfSSL Provider
20+
version: 0.0.1
21+
status: active
22+
build info: wolfSSL 5.6.4
23+
gettable provider parameters:
24+
name: pointer to a UTF8 encoded string (arbitrary size)
25+
version: pointer to a UTF8 encoded string (arbitrary size)
26+
buildinfo: pointer to a UTF8 encoded string (arbitrary size)
27+
status: integer (arbitrary size)
28+
evpciph_aes_wrap.txt ... PASS
29+
evpencod.txt ... PASS
30+
evpkdf_hkdf.txt ... PASS
31+
evpkdf_pbkdf2.txt ... PASS
32+
evpkdf_tls11_prf.txt ... PASS
33+
evpkdf_tls12_prf.txt ... PASS
34+
evpkdf_tls13_kdf.txt ... PASS
35+
evpmd_md.txt ... PASS
36+
evpmd_sha.txt ... PASS
37+
evppbe_pbkdf2.txt ... PASS
38+
evppbe_pkcs12.txt ... PASS
39+
evppkey_kdf_hkdf.txt ... PASS
40+
evppkey_kdf_tls1_prf.txt ... PASS
41+
```
42+
43+
An alternate way of running `build.sh` is within a Docker environment. This can avoid unwanted local changes to your system by wrapping the environment in a container. Simply launch Docker with `docker run --rm -it -v $(pwd)/../../:/ws -w /ws/IDE/Android ubuntu:22.04 ./build.sh`. This should start the script and build everything in the local folder. Then you can take the `run.sh` script and run it from your host environment.

IDE/Android/build.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -e
4+
WORKSPACE=$(pwd)
5+
6+
AUTO_INSTALL_TOOLS=${AUTO_INSTALL_TOOLS:-true}
7+
if [ "${AUTO_INSTALL_TOOLS}" == "true" ]; then
8+
DEBIAN_FRONTEND=noninteractive apt update && apt install -y git make autoconf libtool android-tools-adb unzip wget
9+
fi
10+
11+
# https://developer.android.com/ndk/downloads/
12+
export ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-${WORKSPACE}/android-ndk-r26b}
13+
if [ ! -e ${ANDROID_NDK_ROOT} ]; then
14+
wget -q https://dl.google.com/android/repository/android-ndk-r26b-linux.zip
15+
unzip android-ndk-r26b-linux.zip
16+
fi
17+
PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
18+
19+
# Compile OpenSSL
20+
export OPENSSL_ALL_CIPHERS="-cipher ALL -ciphersuites TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:TLS_AES_128_CCM_SHA256:TLS_AES_128_CCM_8_SHA256"
21+
if [ ! -e ${WORKSPACE}/openssl ]; then
22+
git clone https://github.com/openssl/openssl.git ${WORKSPACE}/openssl
23+
cd ${WORKSPACE}/openssl && \
24+
./Configure android-x86_64 --prefix=${WORKSPACE}/openssl-install && \
25+
sed -i 's/-ldl//g' Makefile && \
26+
sed -i 's/-pie//g' Makefile && \
27+
make -j && \
28+
make -j install
29+
fi
30+
export LD_LIBRARY_PATH="${WORKSPACE}/openssl-install/lib64:$LD_LIBRARY_PATH"
31+
32+
# Compile WolfSSL
33+
export WOLFSSL_CONFIG_OPTS='--enable-debug --enable-opensslcoexist --enable-cmac --enable-keygen --enable-sha --enable-aesctr --enable-aesccm --enable-x963kdf --enable-compkey --enable-certgen --enable-aeskeywrap --enable-enckeys --enable-base16 --enable-aesgcm-stream --enable-curve25519 --enable-curve448 --enable-ed25519 --enable-ed448 --enable-pwdbased'
34+
export WOLFSSL_CONFIG_CPPFLAGS=CPPFLAGS="-I${WORKSPACE}/openssl-install -DHAVE_AES_ECB -DWOLFSSL_AES_DIRECT -DWC_RSA_NO_PADDING -DWOLFSSL_PUBLIC_MP -DECC_MIN_KEY_SZ=192 -DHAVE_PUBLIC_FFDHE -DHAVE_FFDHE_6144 -DHAVE_FFDHE_8192 -DFP_MAX_BITS=16384 -DWOLFSSL_DH_EXTRA -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_PSS_SALT_LEN_DISCOVER"
35+
export UNAME=Android
36+
export CROSS_COMPILE=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-
37+
export CC=x86_64-linux-android34-clang
38+
if [ ! -e ${WORKSPACE}/wolfssl ]; then
39+
git clone https://github.com/wolfssl/wolfssl ${WORKSPACE}/wolfssl
40+
cd ${WORKSPACE}/wolfssl && \
41+
./autogen.sh && \
42+
./configure ${WOLFSSL_CONFIG_OPTS} "${WOLFSSL_CONFIG_CPPFLAGS}" -prefix=${WORKSPACE}/wolfssl-install --host=x86_64-linux-android --disable-asm CFLAGS=-fPIC && \
43+
make -j install
44+
fi
45+
export LD_LIBRARY_PATH="${WORKSPACE}/wolfssl-install/lib:$LD_LIBRARY_PATH"
46+
export LIBRARY_PATH="${WORKSPACE}/wolfssl-install/lib:$LIBRARY_PATH"
47+
48+
# If running in wolfProvider/IDE/Android, then 'ln -s ../../ wolfProvider'
49+
if [ ! -e ${WORKSPACE}/wolfProvider ]; then
50+
git clone https://github.com/wolfssl/wolfProvider ${WORKSPACE}/wolfProvider
51+
fi
52+
cd ${WORKSPACE}/wolfProvider && \
53+
./autogen.sh && \
54+
./configure --with-openssl=${WORKSPACE}/openssl-install --with-wolfssl=${WORKSPACE}/wolfssl-install --host=x86_64-linux-android CFLAGS="-lm -fPIC" --enable-debug && \
55+
make -j

IDE/Android/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
WORKSPACE=$(pwd)
5+
6+
# Prepare to copy over and run on an Android system
7+
rm -rf ${WORKSPACE}/openssl-install/share
8+
rm -rf ${WORKSPACE}/openssl-install/ssl/misc/tsget
9+
10+
adb push --sync ${WORKSPACE}/openssl-install ${WORKSPACE}/wolfssl/src/.libs/libwolfssl.so ${WORKSPACE}/wolfProvider/.libs/libwolfprov.so ${WORKSPACE}/wolfProvider/provider.conf ${WORKSPACE}/wolfProvider/scripts run_helper.sh /data/local/tmp/.
11+
12+
adb shell "cd /data/local/tmp/ && ./run_helper.sh"
13+

IDE/Android/run_helper.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
RUNDIR=/data/local/tmp/
2+
export LD_LIBRARY_PATH=${RUNDIR}:${RUNDIR}/openssl-install/lib
3+
export OPENSSL_MODULES=${RUNDIR}
4+
export OPENSSL_CONF=${RUNDIR}/provider.conf
5+
${RUNDIR}/openssl-install/bin/openssl list -provider-path ${RUNDIR} -providers -verbose
6+
#${RUNDIR}/openssl-install/bin/openssl help list
7+
8+
EVP_TESTS=(
9+
# evpciph_aes_ccm_cavs.txt
10+
# evpciph_aes_common.txt
11+
evpciph_aes_wrap.txt
12+
evpencod.txt
13+
evpkdf_hkdf.txt
14+
evpkdf_pbkdf2.txt
15+
evpkdf_tls11_prf.txt
16+
evpkdf_tls12_prf.txt
17+
evpkdf_tls13_kdf.txt
18+
# evpmac_common.txt
19+
evpmd_md.txt
20+
evpmd_sha.txt
21+
evppbe_pbkdf2.txt
22+
evppbe_pkcs12.txt
23+
# evppkey_dh.txt
24+
# evppkey_ecc.txt
25+
# evppkey_ecdh.txt
26+
# evppkey_ecdsa.txt
27+
# evppkey_ecx.txt
28+
# evppkey_ffdhe.txt
29+
# evppkey_kas.txt
30+
evppkey_kdf_hkdf.txt
31+
evppkey_kdf_tls1_prf.txt
32+
# evppkey_mismatch.txt
33+
# evppkey_rsa_common.txt
34+
# evppkey_rsa.txt
35+
)
36+
for T in ${EVP_TESTS[@]}
37+
do
38+
printf "\t\t$T ... "
39+
${RUNDIR}/openssl/test/evp_test -config ${RUNDIR}/provider.conf \
40+
${RUNDIR}/scripts/evp_test/$T \
41+
>$T.log 2>&1
42+
if [ "$?" = "0" ]; then
43+
echo "PASS"
44+
else
45+
echo "ERROR"
46+
FAIL_CNT=$((FAIL_CNT+1))
47+
fi
48+
done
49+

0 commit comments

Comments
 (0)