| 1 |
#!/bin/bash |
| 2 |
# Copyright 2020 The Go Authors. All rights reserved. |
| 3 |
# Use of this source code is governed by a BSD-style |
| 4 |
# license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
# Do not run directly; run build.sh, which runs this in Docker. |
| 7 |
# This script builds boringssl, which has already been unpacked in /boring/boringssl. |
| 8 |
|
| 9 |
set -e |
| 10 |
id |
| 11 |
date |
| 12 |
cd /boring |
| 13 |
|
| 14 |
# Go requires -fPIC for linux/amd64 cgo builds. |
| 15 |
# Setting -fPIC only affects the compilation of the non-module code in libcrypto.a, |
| 16 |
# because the FIPS module itself is already built with -fPIC. |
| 17 |
echo '#!/bin/bash |
| 18 |
exec clang-'$ClangV' -DGOBORING -fPIC "$@" |
| 19 |
' >/usr/local/bin/clang |
| 20 |
echo '#!/bin/bash |
| 21 |
exec clang++-'$ClangV' -DGOBORING -fPIC "$@" |
| 22 |
' >/usr/local/bin/clang++ |
| 23 |
chmod +x /usr/local/bin/clang /usr/local/bin/clang++ |
| 24 |
|
| 25 |
# The BoringSSL tests use Go, and cgo would look for gcc. |
| 26 |
export CGO_ENABLED=0 |
| 27 |
|
| 28 |
# Modify the support code crypto/mem.c (outside the FIPS module) |
| 29 |
# to not try to use weak symbols, because they don't work with some |
| 30 |
# Go toolchain / clang toolchain combinations. |
| 31 |
perl -p -i -e 's/defined.*ELF.*defined.*GNUC.*/$0 \&\& !defined(GOBORING)/' boringssl/crypto/mem.c |
| 32 |
|
| 33 |
# We build all of libcrypto, which includes a bunch of I/O operations that we |
| 34 |
# don't actually care about, since we only really want the BoringCrypto module. |
| 35 |
# In libcrypto, they use the LFS64 interfaces where available in order to |
| 36 |
# traverse files larger than 2GB. In some scenarios this can cause breakage, so |
| 37 |
# we comment out the _FILE_OFFSET_BITS definition which enables the LFS64 |
| 38 |
# interfaces. Since this code is outside of the FIPS module, it doesn't affect |
| 39 |
# the certification status of the module. See b/364606941 for additional context. |
| 40 |
perl -p -i -e 's/(#define _FILE_OFFSET_BITS 64)/\/\/ $1/' boringssl/crypto/bio/file.c |
| 41 |
|
| 42 |
# Verbatim instructions from BoringCrypto build docs. |
| 43 |
printf "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\n" >${HOME}/toolchain |
| 44 |
cd boringssl |
| 45 |
mkdir build && cd build && cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=${HOME}/toolchain -DFIPS=1 -DCMAKE_BUILD_TYPE=Release .. |
| 46 |
# SSLTest.HostMatching fails due to an expired certificate. |
| 47 |
ninja && faketime 2022-06-13 ninja run_tests |
| 48 |
cd ../.. |
| 49 |
|
| 50 |
if [ "$(./boringssl/build/tool/bssl isfips)" != 1 ]; then |
| 51 |
echo "NOT FIPS" |
| 52 |
exit 2 |
| 53 |
fi |