Skip to content

Commit 5bd29bb

Browse files
author
Andras Fekete
committed
Cleaned up build.sh and updated README.md
1 parent 2401b2c commit 5bd29bb

3 files changed

Lines changed: 77 additions & 25 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ IDE/Android/openssl-install/
6262
IDE/Android/wolfssl-source/
6363
IDE/Android/wolfssl-install/
6464
IDE/Android/wolfProvider/
65+
66+
examples/openssl_example

IDE/Android/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ Providers:
4141
```
4242

4343
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.
44+
45+
# build.sh options
46+
There are a few environment flags that can be passed to the script to modify its execution. This section details the functionality.
47+
48+
## AUTO_INSTALL_TOOLS
49+
This setting will run on a Debian system the required commands to install the dependencies of this script.
50+
51+
## CLEAN_BUILD
52+
This will remove previous sources and binaries in the folder to have a clean start.
53+
54+
## USE_FIPS
55+
This sets WolfSSL to use the FIPS version. Note some algorithms are turned off as they are not FIPS certified (ie: ed25519 and ed448).
56+
57+
### USE_FIPS_CHECK
58+
If you have access to the official FIPS GitHub repository, you can use that as the source. Generally it is intended for internal use.

IDE/Android/build.sh

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,105 @@
11
#!/bin/bash
22

3-
set -e
43
WORKSPACE=$(pwd)
54

5+
function checkReturn() {
6+
if [ "$1" != "0" ]; then
7+
echo "Error on line ${BASH_LINENO[0]}: $1"
8+
exit $1
9+
fi
10+
}
11+
612
AUTO_INSTALL_TOOLS=${AUTO_INSTALL_TOOLS:-true}
713
if [ "${AUTO_INSTALL_TOOLS}" == "true" ]; then
14+
echo "=== Installing prerequisite tools ==="
815
DEBIAN_FRONTEND=noninteractive apt update && apt install -y git make autoconf libtool android-tools-adb unzip wget
16+
checkReturn $?
917
fi
1018

1119
# https://developer.android.com/ndk/downloads/
1220
export ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-${WORKSPACE}/android-ndk-r26b}
1321
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
22+
echo "=== Installing Android NDK ==="
23+
wget -q https://dl.google.com/android/repository/android-ndk-r26b-linux.zip && \
24+
unzip android-ndk-r26b-linux.zip
25+
checkReturn $?
1626
fi
1727
PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
1828

29+
if [ "${CLEAN_BUILD}" = "true" ]; then
30+
rm -rf ${WORKSPACE}/openssl-* ${WORKSPACE}/wolfssl-*
31+
fi
32+
1933
# 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"
2134
if [ ! -e ${WORKSPACE}/openssl-install ]; then
22-
git clone https://github.com/openssl/openssl.git ${WORKSPACE}/openssl-source
23-
cd ${WORKSPACE}/openssl-source && \
35+
echo "=== Installing OpenSSL ==="
36+
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"
37+
git clone https://github.com/openssl/openssl.git ${WORKSPACE}/openssl-source && \
38+
cd ${WORKSPACE}/openssl-source && \
2439
./Configure android-x86_64 --prefix=${WORKSPACE}/openssl-install && \
2540
sed -i 's/-ldl//g' Makefile && \
2641
sed -i 's/-pie//g' Makefile && \
2742
make -j && \
2843
make -j install
44+
checkReturn $?
2945
fi
3046
export LD_LIBRARY_PATH="${WORKSPACE}/openssl-install/lib64:$LD_LIBRARY_PATH"
3147

3248
# 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-pwdbased --enable-fips=ready'
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"
3549
export UNAME=Android
3650
export CROSS_COMPILE=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-
3751
if [ ! -e ${WORKSPACE}/wolfssl-install ]; then
38-
if [ ${USE_FIPS_CHECK} = "true" ]; then
39-
git clone https://github.com/wolfssl/wolfssl ${WORKSPACE}/wolfssl
40-
cd ${WORKSPACE}/wolfssl && ./fips-check.sh fips-ready keep
41-
mv ${WORKSPACE}/wolfssl/XXX-fips-test ${WORKSPACE}/wolfssl-source
42-
rm -rf ${WORKSPACE}/wolfssl
43-
cd ${WORKSPACE}/wolfssl-source && ./autogen.sh
52+
echo "=== Installing WolfSSL ==="
53+
export WOLFSSL_CONFIG_OPTS='--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-pwdbased'
54+
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"
55+
if [ "${USE_FIPS}" = "true" ]; then
56+
WOLFSSL_CONFIG_OPTS+=' --enable-fips=ready'
57+
if [ "${USE_FIPS_CHECK}" = "true" ]; then
58+
git clone https://github.com/wolfssl/wolfssl ${WORKSPACE}/wolfssl && \
59+
cd ${WORKSPACE}/wolfssl && ./fips-check.sh fips-ready keep && \
60+
mv ${WORKSPACE}/wolfssl/XXX-fips-test ${WORKSPACE}/wolfssl-source && \
61+
rm -rf ${WORKSPACE}/wolfssl && \
62+
cd ${WORKSPACE}/wolfssl-source && ./autogen.sh
63+
checkReturn $?
64+
else
65+
wget -O ${WORKSPACE}/wolfssl-fips.zip https://www.wolfssl.com/wolfssl-5.6.4-gplv3-fips-ready.zip && \
66+
cd ${WORKSPACE} && unzip wolfssl-fips.zip && \
67+
mv ${WORKSPACE}/wolfssl-5.6.4-gplv3-fips-ready ${WORKSPACE}/wolfssl-source && \
68+
rm ${WORKSPACE}/wolfssl-fips.zip
69+
checkReturn $?
70+
fi
4471
else
45-
wget -O ${WORKSPACE}/wolfssl-fips.zip https://www.wolfssl.com/wolfssl-5.6.4-gplv3-fips-ready.zip && \
46-
cd ${WORKSPACE} && unzip wolfssl-fips.zip && \
47-
mv ${WORKSPACE}/wolfssl-5.6.4-gplv3-fips-ready ${WORKSPACE}/wolfssl-source && \
48-
rm ${WORKSPACE}/wolfssl-fips.zip
72+
WOLFSSL_CONFIG_OPTS+=' --enable-curve25519 --enable-curve448 --enable-ed25519 --enable-ed448'
73+
git clone https://github.com/wolfssl/wolfssl ${WORKSPACE}/wolfssl-source && \
74+
cd ${WORKSPACE}/wolfssl-source && ./autogen.sh
75+
checkReturn $?
4976
fi
50-
cd ${WORKSPACE}/wolfssl-source
51-
CC=x86_64-linux-android34-clang ./configure ${WOLFSSL_CONFIG_OPTS} "${WOLFSSL_CONFIG_CPPFLAGS}" -prefix=${WORKSPACE}/wolfssl-install --host=x86_64-linux-android --disable-asm CFLAGS=-fPIC && \
52-
make && \
53-
adb push --sync src/.libs/libwolfssl.so ./wolfcrypt/test/.libs/testwolfcrypt /data/local/tmp/ && \
54-
NEWHASH=$(adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/testwolfcrypt 2>&1 | sed -n 's/hash = \(.*\)/\1/p'") && \
55-
sed -i "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c && \
56-
make -j install
77+
cd ${WORKSPACE}/wolfssl-source && \
78+
CC=x86_64-linux-android34-clang ./configure ${WOLFSSL_CONFIG_OPTS} "${WOLFSSL_CONFIG_CPPFLAGS}" -prefix=${WORKSPACE}/wolfssl-install --host=x86_64-linux-android --disable-asm CFLAGS=-fPIC && \
79+
make && \
80+
adb push --sync src/.libs/libwolfssl.so ./wolfcrypt/test/.libs/testwolfcrypt /data/local/tmp/ && \
81+
NEWHASH=$(adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/testwolfcrypt 2>&1 | sed -n 's/hash = \(.*\)/\1/p'") \
82+
sed -i "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c && \
83+
make -j install
84+
checkReturn $?
5785
fi
5886
export LD_LIBRARY_PATH="${WORKSPACE}/wolfssl-install/lib:$LD_LIBRARY_PATH"
5987
export LIBRARY_PATH="${WORKSPACE}/wolfssl-install/lib:$LIBRARY_PATH"
6088

89+
echo "=== Installing wolfProvider ==="
90+
6191
# If running in wolfProvider/IDE/Android, then 'ln -s ../../ wolfProvider'
6292
if [ ! -e ${WORKSPACE}/wolfProvider ]; then
6393
git clone https://github.com/wolfssl/wolfProvider ${WORKSPACE}/wolfProvider
94+
checkReturn $?
6495
fi
6596
cd ${WORKSPACE}/wolfProvider && \
6697
./autogen.sh && \
6798
CC=x86_64-linux-android34-clang ./configure --with-openssl=${WORKSPACE}/openssl-install --with-wolfssl=${WORKSPACE}/wolfssl-install --host=x86_64-linux-android CFLAGS="-lm -fPIC" --enable-debug && \
6899
make -j
100+
checkReturn $?
69101

70102
${CROSS_COMPILE}clang ${WORKSPACE}/wolfProvider/examples/openssl_example.c -I ${WORKSPACE}/openssl-install/include/ -L ${WORKSPACE}/openssl-install/lib/ -lcrypto -o ${WORKSPACE}/wolfProvider/examples/openssl_example
103+
checkReturn $?
104+
105+
exit 0

0 commit comments

Comments
 (0)