| 1 | #!/usr/bin/env bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | set -eu |
| 5 | |
| 6 | usage() { |
| 7 | echo -e "\ninstall_awslc_fips.sh build_dir install_dir version" |
| 8 | echo -e "\tversion: 2022|2024|next\n" |
| 9 | exit 1 |
| 10 | } |
| 11 | |
| 12 | check_dep(){ |
| 13 | if [[ ! -f "$(which $1)" ]]; then |
| 14 | echo "Could not find $1" |
| 15 | exit 1 |
| 16 | fi |
| 17 | } |
| 18 | |
| 19 | clone(){ |
| 20 | git clone https://github.com/awslabs/aws-lc.git --branch "$AWSLC_BRANCH" --depth 1 $BUILD_DIR |
| 21 | cd "$BUILD_DIR" |
| 22 | } |
| 23 | |
| 24 | build() { |
| 25 | echo "Building with shared library=$1" |
| 26 | cmake $BUILD_DIR \ |
| 27 | -Bbuild \ |
| 28 | -GNinja \ |
| 29 | -DBUILD_SHARED_LIBS=$1 \ |
| 30 | -DCMAKE_BUILD_TYPE=relwithdebinfo \ |
| 31 | -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ |
| 32 | -DCMAKE_C_COMPILER=$(which clang) \ |
| 33 | -DCMAKE_CXX_COMPILER=$(which clang++) \ |
| 34 | -DFIPS="true" |
| 35 | ninja -j "$(nproc)" -C build install |
| 36 | ninja -C build clean |
| 37 | } |
| 38 | |
| 39 | # main |
| 40 | if [ "$#" -ne "3" ]; then |
| 41 | usage |
| 42 | fi |
| 43 | |
| 44 | # Ensure tooling is available |
| 45 | check_dep clang |
| 46 | check_dep ninja |
| 47 | check_dep go |
| 48 | |
| 49 | BUILD_DIR=$1 |
| 50 | INSTALL_DIR=$2 |
| 51 | VERSION=$3 |
| 52 | # This url only returns the latest 30 releases (configurable via `per_page`). AWS-LC-FIPS-3.x is the current major version. |
| 53 | GH_RELEASE_URL="https://api.github.com/repos/aws/aws-lc/releases" |
| 54 | # Latest release of AWS-LC-FIPS-2.x |
| 55 | FIPS2_RELEASE_URL="https://api.github.com/repos/aws/aws-lc/releases/tags/AWS-LC-FIPS-2.0.17" |
| 56 | |
| 57 | # Map version to the latest release of the certificate year. |
| 58 | # Note: since the next FIPS validation will be split off from main |
| 59 | # building main with FIPS enabled is the next candidate FIPS branch. |
| 60 | case $VERSION in |
| 61 | "2022") |
| 62 | AWSLC_BRANCH=$(curl --silent $FIPS2_RELEASE_URL \ |
| 63 | |grep -Po '"tag_name": "\KAWS-LC-FIPS-2.*?(?=")' |head -1) |
| 64 | ;; |
| 65 | "2024") |
| 66 | AWSLC_BRANCH=$(curl --silent $GH_RELEASE_URL \ |
| 67 | |grep -Po '"tag_name": "\KAWS-LC-FIPS-3.*?(?=")' |head -1) |
| 68 | ;; |
| 69 | "next") |
| 70 | AWSLC_BRANCH=main |
| 71 | ;; |
| 72 | *) |
| 73 | echo "Unknown version: $VERSION" |
| 74 | usage |
| 75 | ;; |
| 76 | esac |
| 77 | |
| 78 | clone |
| 79 | # Static lib |
| 80 | build false |
| 81 | # Shared lib |
| 82 | build true |
| 83 | |
| 84 | rm -rf $BUILD_DIR |
| 85 |