test.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. #!/bin/sh
  2. # Build script for Travis CI
  3. build_botan()
  4. {
  5. # same revision used in the build recipe of the testing environment
  6. BOTAN_REV=2.11.0
  7. BOTAN_DIR=$TRAVIS_BUILD_DIR/../botan
  8. if test -d "$BOTAN_DIR"; then
  9. return
  10. fi
  11. echo "$ build_botan()"
  12. # if the leak detective is enabled we have to disable threading support
  13. # (used for std::async) as that causes invalid frees somehow, the
  14. # locking allocator causes a static leak via the first function that
  15. # references it (e.g. crypter or hasher), so we disable that too
  16. if test "$LEAK_DETECTIVE" = "yes"; then
  17. BOTAN_CONFIG="--without-os-features=threads
  18. --disable-modules=locking_allocator"
  19. fi
  20. # disable some larger modules we don't need for the tests
  21. BOTAN_CONFIG="$BOTAN_CONFIG --disable-modules=pkcs11,tls,x509,xmss"
  22. git clone https://github.com/randombit/botan.git $BOTAN_DIR &&
  23. cd $BOTAN_DIR &&
  24. git checkout -qf $BOTAN_REV &&
  25. python ./configure.py --amalgamation $BOTAN_CONFIG &&
  26. make -j4 libs >/dev/null &&
  27. sudo make install >/dev/null &&
  28. sudo ldconfig || exit $?
  29. cd -
  30. }
  31. build_wolfssl()
  32. {
  33. WOLFSSL_REV=v4.1.0-stable
  34. WOLFSSL_DIR=$TRAVIS_BUILD_DIR/../wolfssl
  35. if test -d "$WOLFSSL_DIR"; then
  36. return
  37. fi
  38. echo "$ build_wolfssl()"
  39. WOLFSSL_CFLAGS="-DWOLFSSL_PUBLIC_MP -DWOLFSSL_DES_ECB"
  40. WOLFSSL_CONFIG="--enable-keygen --enable-rsapss --enable-aesccm
  41. --enable-aesctr --enable-des3 --enable-camellia
  42. --enable-curve25519 --enable-ed25519"
  43. git clone https://github.com/wolfSSL/wolfssl.git $WOLFSSL_DIR &&
  44. cd $WOLFSSL_DIR &&
  45. git checkout -qf $WOLFSSL_REV &&
  46. ./autogen.sh &&
  47. ./configure C_EXTRA_FLAGS="$WOLFSSL_CFLAGS" $WOLFSSL_CONFIG &&
  48. make -j4 >/dev/null &&
  49. sudo make install >/dev/null &&
  50. sudo ldconfig || exit $?
  51. cd -
  52. }
  53. build_tss2()
  54. {
  55. TSS2_REV=2.1.0
  56. TSS2_PKG=tpm2-tss-$TSS2_REV
  57. TSS2_DIR=$TRAVIS_BUILD_DIR/../$TSS2_PKG
  58. TSS2_SRC=https://github.com/tpm2-software/tpm2-tss/releases/download/$TSS2_REV/$TSS2_PKG.tar.gz
  59. if test -d "$TSS2_DIR"; then
  60. return
  61. fi
  62. echo "$ build_tss2()"
  63. # the default version of libgcrypt in Ubuntu 16.04 is too old
  64. sudo apt-get update -qq && \
  65. sudo apt-get install -qq libgcrypt20-dev &&
  66. curl -L $TSS2_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
  67. cd $TSS2_DIR &&
  68. ./configure &&
  69. make -j4 >/dev/null &&
  70. sudo make install >/dev/null &&
  71. sudo ldconfig || exit $?
  72. cd -
  73. }
  74. build_openssl()
  75. {
  76. SSL_REV=1.1.1c
  77. SSL_PKG=openssl-$SSL_REV
  78. SSL_DIR=$TRAVIS_BUILD_DIR/../$SSL_PKG
  79. SSL_SRC=https://www.openssl.org/source/$SSL_PKG.tar.gz
  80. SSL_INS=/usr/local/ssl
  81. SSL_OPT="shared no-tls no-dtls no-ssl3 no-zlib no-comp no-idea no-psk no-srp
  82. no-stdio no-tests enable-rfc3779 enable-ec_nistp_64_gcc_128
  83. --api=1.1.0"
  84. if test -d "$SSL_DIR"; then
  85. return
  86. fi
  87. echo "$ build_openssl()"
  88. curl -L $SSL_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
  89. cd $SSL_DIR &&
  90. ./config --prefix=$SSL_INS --openssldir=$SSL_INS $SSL_OPT &&
  91. make -j4 >/dev/null &&
  92. sudo make install_sw >/dev/null &&
  93. echo $SSL_INS/lib | sudo tee /etc/ld.so.conf.d/openssl-$SSL_REV.conf >/dev/null &&
  94. sudo ldconfig || exit $?
  95. cd -
  96. }
  97. use_custom_openssl()
  98. {
  99. CFLAGS="$CFLAGS -I/usr/local/ssl/include"
  100. LDFLAGS="$LDFLAGS -L/usr/local/ssl/lib"
  101. export LDFLAGS
  102. if test "$1" = "deps"; then
  103. build_openssl
  104. fi
  105. }
  106. if test -z $TRAVIS_BUILD_DIR; then
  107. TRAVIS_BUILD_DIR=$PWD
  108. fi
  109. cd $TRAVIS_BUILD_DIR
  110. TARGET=check
  111. DEPS="libgmp-dev"
  112. CFLAGS="-g -O2 -Wall -Wno-format -Wno-format-security -Wno-pointer-sign -Werror"
  113. case "$TEST" in
  114. default)
  115. # should be the default, but lets make sure
  116. CONFIG="--with-printf-hooks=glibc"
  117. ;;
  118. openssl*)
  119. CONFIG="--disable-defaults --enable-pki --enable-openssl --enable-pem"
  120. export TESTS_PLUGINS="test-vectors pem openssl!"
  121. DEPS="libssl-dev"
  122. if test "$TEST" != "openssl-1.0"; then
  123. DEPS=""
  124. use_custom_openssl $1
  125. fi
  126. ;;
  127. gcrypt)
  128. CONFIG="--disable-defaults --enable-pki --enable-gcrypt --enable-pkcs1"
  129. export TESTS_PLUGINS="test-vectors pkcs1 gcrypt!"
  130. DEPS="libgcrypt11-dev"
  131. ;;
  132. botan)
  133. CONFIG="--disable-defaults --enable-pki --enable-botan --enable-pem"
  134. export TESTS_PLUGINS="test-vectors pem botan!"
  135. # we can't use the old package that comes with Ubuntu so we build from
  136. # the current master until 2.8.0 is released and then probably switch to
  137. # that unless we need newer features (at least 2.7.0 plus PKCS#1 patch is
  138. # currently required)
  139. DEPS=""
  140. if test "$1" = "deps"; then
  141. build_botan
  142. fi
  143. ;;
  144. wolfssl)
  145. CONFIG="--disable-defaults --enable-pki --enable-wolfssl --enable-pem"
  146. export TESTS_PLUGINS="test-vectors pem wolfssl!"
  147. # build with custom options to enable all the features the plugin supports
  148. DEPS=""
  149. if test "$1" = "deps"; then
  150. build_wolfssl
  151. fi
  152. ;;
  153. printf-builtin)
  154. CONFIG="--with-printf-hooks=builtin"
  155. ;;
  156. all|coverage|sonarcloud)
  157. CONFIG="--enable-all --disable-android-dns --disable-android-log
  158. --disable-kernel-pfroute --disable-keychain
  159. --disable-lock-profiler --disable-padlock --disable-fuzzing
  160. --disable-osx-attr --disable-tkm --disable-uci
  161. --disable-soup --disable-unwind-backtraces
  162. --disable-svc --disable-dbghelp-backtraces --disable-socket-win
  163. --disable-kernel-wfp --disable-kernel-iph --disable-winhttp"
  164. # not enabled on the build server
  165. CONFIG="$CONFIG --disable-af-alg"
  166. if test "$TEST" != "coverage"; then
  167. CONFIG="$CONFIG --disable-coverage"
  168. else
  169. # not actually required but configure checks for it
  170. DEPS="$DEPS lcov"
  171. fi
  172. DEPS="$DEPS libcurl4-gnutls-dev libsoup2.4-dev libunbound-dev libldns-dev
  173. libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
  174. libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev
  175. libjson0-dev iptables-dev python-pip libtspi-dev libsystemd-dev"
  176. PYDEPS="pytest"
  177. if test "$1" = "deps"; then
  178. build_botan
  179. build_wolfssl
  180. build_tss2
  181. fi
  182. use_custom_openssl $1
  183. ;;
  184. win*)
  185. CONFIG="--disable-defaults --enable-svc --enable-ikev2
  186. --enable-ikev1 --enable-static --enable-test-vectors --enable-nonce
  187. --enable-constraints --enable-revocation --enable-pem --enable-pkcs1
  188. --enable-pkcs8 --enable-x509 --enable-pubkey --enable-acert
  189. --enable-eap-tnc --enable-eap-ttls --enable-eap-identity
  190. --enable-updown --enable-ext-auth --enable-libipsec
  191. --enable-tnccs-20 --enable-imc-attestation --enable-imv-attestation
  192. --enable-imc-os --enable-imv-os --enable-tnc-imv --enable-tnc-imc
  193. --enable-pki --enable-swanctl --enable-socket-win
  194. --enable-kernel-iph --enable-kernel-wfp --enable-winhttp"
  195. # no make check for Windows binaries unless we run on a windows host
  196. if test "$APPVEYOR" != "True"; then
  197. TARGET=
  198. CCACHE=ccache
  199. else
  200. CONFIG="$CONFIG --enable-openssl"
  201. CFLAGS="$CFLAGS -I/c/OpenSSL-$TEST/include"
  202. LDFLAGS="-L/c/OpenSSL-$TEST"
  203. export LDFLAGS
  204. fi
  205. CFLAGS="$CFLAGS -mno-ms-bitfields"
  206. DEPS="gcc-mingw-w64-base"
  207. case "$TEST" in
  208. win64)
  209. CONFIG="--host=x86_64-w64-mingw32 $CONFIG --enable-dbghelp-backtraces"
  210. DEPS="gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev $DEPS"
  211. CC="$CCACHE x86_64-w64-mingw32-gcc"
  212. ;;
  213. win32)
  214. CONFIG="--host=i686-w64-mingw32 $CONFIG"
  215. DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-i686-dev $DEPS"
  216. CC="$CCACHE i686-w64-mingw32-gcc"
  217. ;;
  218. esac
  219. ;;
  220. osx)
  221. # this causes a false positive in ip-packet.c since Xcode 8.3
  222. CFLAGS="$CFLAGS -Wno-address-of-packed-member"
  223. # use the same options as in the Homebrew Formula
  224. CONFIG="--disable-defaults --enable-charon --enable-cmd --enable-constraints
  225. --enable-curl --enable-eap-gtc --enable-eap-identity
  226. --enable-eap-md5 --enable-eap-mschapv2 --enable-ikev1 --enable-ikev2
  227. --enable-kernel-libipsec --enable-kernel-pfkey
  228. --enable-kernel-pfroute --enable-nonce --enable-openssl
  229. --enable-osx-attr --enable-pem --enable-pgp --enable-pkcs1
  230. --enable-pkcs8 --enable-pki --enable-pubkey --enable-revocation
  231. --enable-scepclient --enable-socket-default --enable-sshkey
  232. --enable-stroke --enable-swanctl --enable-unity --enable-updown
  233. --enable-x509 --enable-xauth-generic"
  234. DEPS="bison gettext openssl curl"
  235. BREW_PREFIX=$(brew --prefix)
  236. export PATH=$BREW_PREFIX/opt/bison/bin:$PATH
  237. export ACLOCAL_PATH=$BREW_PREFIX/opt/gettext/share/aclocal:$ACLOCAL_PATH
  238. for pkg in openssl curl
  239. do
  240. PKG_CONFIG_PATH=$BREW_PREFIX/opt/$pkg/lib/pkgconfig:$PKG_CONFIG_PATH
  241. CPPFLAGS="-I$BREW_PREFIX/opt/$pkg/include $CPPFLAGS"
  242. LDFLAGS="-L$BREW_PREFIX/opt/$pkg/lib $LDFLAGS"
  243. done
  244. export PKG_CONFIG_PATH
  245. export CPPFLAGS
  246. export LDFLAGS
  247. ;;
  248. freebsd)
  249. # use the options of the FreeBSD port (including options), except smp,
  250. # which requires a patch but is deprecated anyway, only using the builtin
  251. # printf hooks
  252. CONFIG="--enable-kernel-pfkey --enable-kernel-pfroute --disable-scripts
  253. --disable-kernel-netlink --enable-openssl --enable-eap-identity
  254. --enable-eap-md5 --enable-eap-tls --enable-eap-mschapv2
  255. --enable-eap-peap --enable-eap-ttls --enable-md4 --enable-blowfish
  256. --enable-addrblock --enable-whitelist --enable-cmd --enable-curl
  257. --enable-eap-aka --enable-eap-aka-3gpp2 --enable-eap-dynamic
  258. --enable-eap-radius --enable-eap-sim --enable-eap-sim-file
  259. --enable-gcm --enable-ipseckey --enable-kernel-libipsec
  260. --enable-load-tester --enable-ldap --enable-mediation
  261. --enable-mysql --enable-sqlite --enable-tpm --enable-unbound
  262. --enable-unity --enable-xauth-eap --enable-xauth-pam
  263. --with-printf-hooks=builtin --enable-attr-sql --enable-sql"
  264. DEPS="gmp openldap-client libxml2 mysql80-client sqlite3 unbound ldns"
  265. export GPERF=/usr/local/bin/gperf
  266. export LEX=/usr/local/bin/flex
  267. ;;
  268. fuzzing)
  269. CFLAGS="$CFLAGS -DNO_CHECK_MEMWIPE"
  270. CONFIG="--enable-fuzzing --enable-static --disable-shared --disable-scripts
  271. --enable-imc-test --enable-tnccs-20"
  272. # don't run any of the unit tests
  273. export TESTS_RUNNERS=
  274. # prepare corpora
  275. if test -z "$1"; then
  276. if test -z "$FUZZING_CORPORA"; then
  277. git clone --depth 1 https://github.com/strongswan/fuzzing-corpora.git fuzzing-corpora
  278. export FUZZING_CORPORA=$TRAVIS_BUILD_DIR/fuzzing-corpora
  279. fi
  280. # these are about the same as those on OSS-Fuzz (except for the
  281. # symbolize options and strip_path_prefix)
  282. export ASAN_OPTIONS=redzone=16:handle_sigill=1:strict_string_check=1:\
  283. allocator_release_to_os_interval_ms=500:strict_memcmp=1:detect_container_overflow=1:\
  284. coverage=0:allocator_may_return_null=1:use_sigaltstack=1:detect_stack_use_after_return=1:\
  285. alloc_dealloc_mismatch=0:detect_leaks=1:print_scariness=1:max_uar_stack_size_log=16:\
  286. handle_abort=1:check_malloc_usable_size=0:quarantine_size_mb=10:detect_odr_violation=0:\
  287. symbolize=1:handle_segv=1:fast_unwind_on_fatal=0:external_symbolizer_path=/usr/bin/llvm-symbolizer-3.5
  288. fi
  289. ;;
  290. dist)
  291. TARGET=distcheck
  292. ;;
  293. apidoc)
  294. DEPS="doxygen"
  295. CONFIG="--disable-defaults"
  296. TARGET=apidoc
  297. ;;
  298. *)
  299. echo "$0: unknown test $TEST" >&2
  300. exit 1
  301. ;;
  302. esac
  303. if test "$1" = "deps"; then
  304. case "$TRAVIS_OS_NAME" in
  305. linux)
  306. sudo apt-get update -qq && \
  307. sudo apt-get install -qq bison flex gperf gettext $DEPS
  308. ;;
  309. osx)
  310. brew update && \
  311. # workaround for issue #6352
  312. brew uninstall --force libtool && brew install libtool && \
  313. brew install $DEPS
  314. ;;
  315. freebsd)
  316. pkg install -y automake autoconf libtool pkgconf && \
  317. pkg install -y bison flex gperf gettext $DEPS
  318. ;;
  319. esac
  320. exit $?
  321. fi
  322. if test "$1" = "pydeps"; then
  323. test -z "$PYDEPS" || pip -q install --user $PYDEPS
  324. exit $?
  325. fi
  326. CONFIG="$CONFIG
  327. --disable-dependency-tracking
  328. --enable-silent-rules
  329. --enable-test-vectors
  330. --enable-monolithic=${MONOLITHIC-no}
  331. --enable-leak-detective=${LEAK_DETECTIVE-no}"
  332. echo "$ ./autogen.sh"
  333. ./autogen.sh || exit $?
  334. echo "$ CC=$CC CFLAGS=\"$CFLAGS\" ./configure $CONFIG"
  335. CC="$CC" CFLAGS="$CFLAGS" ./configure $CONFIG || exit $?
  336. case "$TEST" in
  337. apidoc)
  338. exec 2>make.warnings
  339. ;;
  340. *)
  341. ;;
  342. esac
  343. echo "$ make $TARGET"
  344. case "$TEST" in
  345. sonarcloud)
  346. # without target, coverage is currently not supported anyway because
  347. # sonarqube only supports gcov, not lcov
  348. build-wrapper-linux-x86-64 --out-dir bw-output make -j4 || exit $?
  349. ;;
  350. *)
  351. make -j4 $TARGET || exit $?
  352. ;;
  353. esac
  354. case "$TEST" in
  355. apidoc)
  356. if test -s make.warnings; then
  357. cat make.warnings
  358. exit 1
  359. fi
  360. rm make.warnings
  361. ;;
  362. sonarcloud)
  363. sonar-scanner \
  364. -Dsonar.projectKey=strongswan \
  365. -Dsonar.projectVersion=$(git describe)+${TRAVIS_BUILD_NUMBER} \
  366. -Dsonar.sources=. \
  367. -Dsonar.cfamily.threads=2 \
  368. -Dsonar.cfamily.build-wrapper-output=bw-output || exit $?
  369. rm -r bw-output .scannerwork
  370. ;;
  371. *)
  372. ;;
  373. esac
  374. # ensure there are no unignored build artifacts (or other changes) in the Git repo
  375. unclean="$(git status --porcelain)"
  376. if test -n "$unclean"; then
  377. echo "Unignored build artifacts or other changes:"
  378. echo "$unclean"
  379. exit 1
  380. fi