| 1 | #!/bin/bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | # You may not use this file except in compliance with the License. |
| 6 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set -ex |
| 17 | pushd "$(pwd)" |
| 18 | |
| 19 | usage() { |
| 20 | echo "install_openssl_3_0.sh build_dir install_dir os_name [fips]" |
| 21 | exit 1 |
| 22 | } |
| 23 | |
| 24 | if [ "$#" -eq "3" ]; then |
| 25 | FIPS=false |
| 26 | elif [ "$#" -eq "4" ] && [ "$4" = "fips" ]; then |
| 27 | FIPS=true |
| 28 | else |
| 29 | usage |
| 30 | fi |
| 31 | |
| 32 | BUILD_DIR=$1 |
| 33 | INSTALL_DIR=$2 |
| 34 | OS_NAME=$3 |
| 35 | source codebuild/bin/jobs.sh |
| 36 | config=$(cat codebuild/bin/s2n_fips_openssl.cnf) |
| 37 | |
| 38 | # Only some versions of Openssl-3 are FIPS validated. |
| 39 | # The list can be found at https://openssl-library.org/source/ |
| 40 | # Maintain separate release versions so that we can change the non-FIPS version |
| 41 | # without worrying about whether or not the new version is FIPS validated. |
| 42 | if $FIPS; then |
| 43 | RELEASE=3.0.9 |
| 44 | else |
| 45 | RELEASE=3.0.7 |
| 46 | fi |
| 47 | |
| 48 | mkdir -p $BUILD_DIR |
| 49 | cd "$BUILD_DIR" |
| 50 | curl --retry 3 -L --output OpenSSL_${RELEASE}.zip \ |
| 51 | https://github.com/openssl/openssl/archive/refs/tags/openssl-${RELEASE}.zip |
| 52 | unzip OpenSSL_${RELEASE}.zip |
| 53 | cd openssl-openssl-${RELEASE} |
| 54 | |
| 55 | if $FIPS; then |
| 56 | CONFIGURE="./Configure enable-fips" |
| 57 | else |
| 58 | CONFIGURE="./Configure" |
| 59 | fi |
| 60 | |
| 61 | mkdir -p $INSTALL_DIR |
| 62 | # Use g3 to get debug symbols in libcrypto to chase memory leaks |
| 63 | $CONFIGURE shared -g3 -fPIC \ |
| 64 | no-md2 no-rc5 no-rfc3779 no-sctp no-ssl-trace no-zlib \ |
| 65 | no-hw no-mdc2 no-seed no-idea enable-ec_nistp_64_gcc_128 no-camellia\ |
| 66 | no-bf no-ripemd no-dsa no-ssl2 no-ssl3 no-capieng no-dtls \ |
| 67 | -DSSL_FORBID_ENULL -DOPENSSL_NO_DTLS1 -DOPENSSL_NO_HEARTBEATS \ |
| 68 | --prefix="$INSTALL_DIR" |
| 69 | |
| 70 | make -j $JOBS |
| 71 | make -j $JOBS test |
| 72 | make -j $JOBS install |
| 73 | |
| 74 | popd |
| 75 | |
| 76 | # sym-link lib -> lib64 since codebuild assumes /lib path |
| 77 | pushd $INSTALL_DIR |
| 78 | ln -s lib64 lib |
| 79 | popd |
| 80 | |
| 81 | # Openssl3 uses the openssl config file to enable fips |
| 82 | # See https://docs.openssl.org/master/man7/fips_module/#making-all-applications-use-the-fips-module-by-default |
| 83 | if $FIPS; then |
| 84 | # We assume that the configs are in the /ssl directory of $INSTALL_DIR |
| 85 | pushd $INSTALL_DIR |
| 86 | config_path=./ssl/openssl.cnf |
| 87 | # We need an absolute path for the fips config |
| 88 | fips_config_path=$(pwd)/ssl/fipsmodule.cnf |
| 89 | config=$(echo "$config" | sed "s,S2N_FIPS_CONFIG_PATH,$fips_config_path,") |
| 90 | echo "$config" > $config_path |
| 91 | popd |
| 92 | fi |
| 93 | |
| 94 | exit 0 |