• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eux
2#
3# Copyright 2018 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17################################################################################
18
19# Install Boost headers
20cd $SRC/
21tar jxf boost_1_74_0.tar.bz2
22cd boost_1_74_0/
23CFLAGS="" CXXFLAGS="" ./bootstrap.sh
24CFLAGS="" CXXFLAGS="" ./b2 headers
25cp -R boost/ /usr/include/
26
27mkdir -p $WORK/libressl
28cd $WORK/libressl
29
30CMAKE_DEFINES=""
31if [[ $CFLAGS = *sanitize=memory* ]]
32then
33  CMAKE_DEFINES+=" -DOPENSSL_NO_ASM=1"
34fi
35
36cmake -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \
37      -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
38      $CMAKE_DEFINES $SRC/libressl/
39make -j$(nproc)
40
41LIBRESSL_FUZZERS=$SRC/libressl.fuzzers
42fuzzerFiles=$(find $LIBRESSL_FUZZERS -name "*.c" | egrep -v 'driver.c|test-corpus.c')
43
44find . -name "*.a"
45
46$CC -c $CFLAGS \
47    -o $WORK/driver.o \
48    $LIBRESSL_FUZZERS/driver.c \
49    -I $SRC/libressl/include -I $SRC/libressl
50
51for F in $fuzzerFiles; do
52  fuzzerName=$(basename $F .c)
53  echo "Building fuzzer $fuzzerName"
54  $CC -c $CFLAGS \
55      -o $WORK/${fuzzerName}.o \
56      $F -I $SRC/libressl/include -I $SRC/libressl
57
58  $CXX $CXXFLAGS \
59      -o $OUT/${fuzzerName} -fsanitize-recover=address \
60      $WORK/driver.o $WORK/${fuzzerName}.o ./ssl/libssl.a ./crypto/libcrypto.a ./tls/libtls.a $LIB_FUZZING_ENGINE
61
62  if [ -d "$LIBRESSL_FUZZERS/corpora/${fuzzerName}/" ]; then
63    zip -j $OUT/${fuzzerName}_seed_corpus.zip $LIBRESSL_FUZZERS/corpora/${fuzzerName}/*
64  fi
65done
66
67cp $SRC/*.options $OUT/
68cp $LIBRESSL_FUZZERS/oids.txt $OUT/asn1.dict
69cp $LIBRESSL_FUZZERS/oids.txt $OUT/x509.dict
70
71# Cryptofuzz
72cd $SRC/cryptofuzz/
73if [[ $CFLAGS = *sanitize=memory* ]]
74then
75    export CXXFLAGS="$CXXFLAGS -DMSAN"
76fi
77# Generate lookup tables
78python3 gen_repository.py
79# Compile Cryptofuzz LibreSSL module
80cd $SRC/cryptofuzz/modules/openssl
81OPENSSL_INCLUDE_PATH="$SRC/libressl/include" OPENSSL_LIBCRYPTO_A_PATH="$WORK/libressl/crypto/libcrypto.a" CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBRESSL" make
82# Compile Cryptofuzz
83cd $SRC/cryptofuzz/
84LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBRESSL -I $SRC/libressl/include" make -j$(nproc)
85# Generate dictionary
86./generate_dict
87# Copy fuzzer
88cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz
89# Copy dictionary
90cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz.dict
91# Copy seed corpus
92cp $SRC/cryptofuzz-corpora/libressl_latest.zip $OUT/cryptofuzz_seed_corpus.zip
93