| 1 | echoscip-shell system . . echo. nix/shell.sh: Entering a devShell |
| 2 | export SRC_ROOT=$(pwdscip-shell system . . pwd.) |
| 3 | export PATH=$SRC_ROOT/build/bin:$PATH |
| 4 | |
| 5 | # The GnuTlS config may restrict TLS versions in some environments, |
| 6 | # so do not use any existing config file. |
| 7 | export GNUTLS_SYSTEM_PRIORITY_FILE= |
| 8 | |
| 9 | # Function to create aliases for different libcrypto implementations |
| 10 | function libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). { |
| 11 | local libcrypto_name=$1 |
| 12 | local libcrypto_binary_path=$2 |
| 13 | # Check both bin and lib directories for the binary |
| 14 | local binary_dir=$(dirnamescip-shell system . . dirname. $libcrypto_binary_path) |
| 15 | local install_dir=$(dirnamescip-shell system . . dirname. $binary_dir) |
| 16 | local lib_binary_path="$install_dir/lib/$(basenamescip-shell system . . basename. $libcrypto_binary_path)" |
| 17 | |
| 18 | if [[ -f $libcrypto_binary_path ]]; then |
| 19 | alias $libcrypto_name=$libcrypto_binary_path |
| 20 | echoscip-shell system . . echo. "Libcrypto binary $libcrypto_binary_path available as $libcrypto_name" |
| 21 | elif [[ -f $lib_binary_path ]]; then |
| 22 | alias $libcrypto_name=$lib_binary_path |
| 23 | echoscip-shell system . . echo. "Libcrypto binary $lib_binary_path available as $libcrypto_name" |
| 24 | else |
| 25 | echoscip-shell system . . echo. "Could not find libcrypto binary for $libcrypto_name" |
| 26 | fi |
| 27 | } |
| 28 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). openssl102 "${OPENSSL_1_0_2_INSTALL_DIR}/bin/openssl" |
| 29 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). openssl111 "${OPENSSL_1_1_1_INSTALL_DIR}/bin/openssl" |
| 30 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). openssl30 "${OPENSSL_3_0_INSTALL_DIR}/bin/openssl" |
| 31 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). awslc "${AWSLC_INSTALL_DIR}/bin/bssl" |
| 32 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). awslcfips2022 "${AWSLC_FIPS_2022_INSTALL_DIR}/bin/bssl" |
| 33 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). awslcfips2024 "${AWSLC_FIPS_2024_INSTALL_DIR}/bin/bssl" |
| 34 | libcrypto_aliasscip-shell shell shell-project 0.0.0 libcrypto_alias(). libressl "${LIBRESSL_INSTALL_DIR}/bin/openssl" |
| 35 | # No need to alias gnutls because it is included in common_packages (see flake.nix). |
| 36 | |
| 37 | function cleanscip-shell shell shell-project 0.0.0 clean(). {(set -e |
| 38 | echoscip-shell system . . echo. "Cleaning up build, s2n_head and the apache2 configs" |
| 39 | rmscip-shell system . . rm. -rf ./build ./s2n_head |
| 40 | if [scip-shell system . . `[`. -d "/usr/local/apache2scip-shell filesystem . . `/usr/local/apache2`." ]; then |
| 41 | rmscip-shell system . . rm. -rf /usr/local/apache2scip-shell filesystem . . `/usr/local/apache2`. |
| 42 | fi |
| 43 | )} |
| 44 | |
| 45 | function configurescip-shell shell shell-project 0.0.0 configure(). {(set -e |
| 46 | echoscip-shell system . . echo. "Configuring with cmake" |
| 47 | cmakescip-shell system . . cmake. -S . -B./build \ |
| 48 | -DBUILD_TESTING=ON \ |
| 49 | -DS2N_INTEG_TESTS=ON \ |
| 50 | -DS2N_INSTALL_S2NC_S2ND=ON \ |
| 51 | -DS2N_INTEG_NIX=ON \ |
| 52 | -DBUILD_SHARED_LIBS=ON \ |
| 53 | -DCMAKE_C_COMPILER="$CC" \ |
| 54 | -DCMAKE_CXX_COMPILER="$CXX" \ |
| 55 | -DS2N_ENFORCE_PROPER_LIBCRYPTO_FEATURE_PROBE=ON \ |
| 56 | "$S2N_CMAKE_OPTIONS" \ |
| 57 | -DCMAKE_BUILD_TYPE=RelWithDebInfo |
| 58 | )} |
| 59 | |
| 60 | function buildscip-shell shell shell-project 0.0.0 build(). {(set -e |
| 61 | echoscip-shell system . . echo. "Running Build" |
| 62 | javacscip-shell system . . javac. tests/integrationv2/bin/SSLSocketClient.java |
| 63 | cmakescip-shell system . . cmake. --build ./build -j $(nprocscip-shell system . . nproc.) |
| 64 | # Build s2n from HEAD |
| 65 | if [[ -z "${S2N_KTLS_TESTING_EXPECTED}" && -z "${S2N_NO_HEADBUILD}" ]]; then |
| 66 | $SRC_ROOT/codebuild/bin/install_s2n_head.sh $(mktempscip-shell system . . mktemp. -d) |
| 67 | fi |
| 68 | )} |
| 69 | |
| 70 | function unitscip-shell shell shell-project 0.0.0 unit(). {(set -e |
| 71 | if [[ -z "$1" ]]; then |
| 72 | cmakescip-shell system . . cmake. --build build -j $(nprocscip-shell system . . nproc.) |
| 73 | ctestscip-shell system . . ctest. --test-dir build -L unit -j $(nprocscip-shell system . . nproc.) --verbose |
| 74 | else |
| 75 | tests=$(ctestscip-shell system . . ctest. --test-dir build -N -L unit | grepscip-shell system . . grep. -E "Test +#" | grepscip-shell system . . grep. -Eo "[^ ]+_test$" | grepscip-shell system . . grep. "$1") |
| 76 | # Split the tests string into words |
| 77 | for test in $tests |
| 78 | do |
| 79 | cmakescip-shell system . . cmake. --build build -j $(nprocscip-shell system . . nproc.) --target $test |
| 80 | done |
| 81 | ctestscip-shell system . . ctest. --test-dir build -L unit -R "$1" -j $(nprocscip-shell system . . nproc.) --verbose |
| 82 | fi |
| 83 | )} |
| 84 | |
| 85 | # Function to launch pytest with uv. |
| 86 | function uvintegscip-shell shell shell-project 0.0.0 uvinteg(). {( |
| 87 | set -eu |
| 88 | TESTS="${1:-all}" |
| 89 | apache2_startscip-shell shell shell-project 0.0.0 apache2_start(). |
| 90 | PYTEST_ARGS="--provider-version $S2N_LIBCRYPTO -x -n auto --durations=10 -rpfs" |
| 91 | cd ./tests/integrationv2 |
| 92 | echoscip-shell system . . echo. -n "Comparing the current list of integ tests against what is checked-in..." |
| 93 | PYTHONPATH="" uv run pytest --collect-only $PYTEST_ARGS | grepscip-shell system . . grep. Module > /tmp/uvinteg_tests.txtscip-shell filesystem . . `/tmp/uvinteg_tests.txt`. |
| 94 | diffscip-shell system . . diff. -q /tmp/uvinteg_tests.txtscip-shell filesystem . . `/tmp/uvinteg_tests.txt`. uvinteg_tests.txt |
| 95 | echoscip-shell system . . echo. "tests to run match uvinteg_tests.txt." |
| 96 | if [[ "$TESTS" == "all" ]]; then |
| 97 | echoscip-shell system . . echo. "Running all integ tests with uv" |
| 98 | # If the first attempt has any failures, try rerunning with only the failed tests. |
| 99 | PYTHONPATH="" uv run pytest --cache-clear $PYTEST_ARGS --junitxml=../../build/junit/uv_integ.xml || \ |
| 100 | PYTHONPATH="" uv run pytest --last-failed --last-failed-no-failures none $PYTEST_ARGS --junitxml=../../build/junit/uv_integ_retry.xml |
| 101 | else |
| 102 | # We're clearing state between test runs when individual tests are specified. |
| 103 | for test in "$@"; do |
| 104 | PYTHONPATH="" uv run pytest --cache-clear $PYTEST_ARGS --junitxml=../../build/junit/$test.xml -k $test |
| 105 | done |
| 106 | fi |
| 107 | )} |
| 108 | |
| 109 | # Wrap a command with stress to simulate a high-load environment. |
| 110 | # Not intended for CI, but local troubleshooting. |
| 111 | function highstressscip-shell shell shell-project 0.0.0 highstress(). {( |
| 112 | set -e |
| 113 | local STRESSARGS="--cpu $(nprocscip-shell system . . nproc.) --io $(nprocscip-shell system . . nproc.) --quiet" |
| 114 | echoscip-shell system . . echo. "Running: stress $STRESSARGS" |
| 115 | stress $STRESSARGS & |
| 116 | trap 'pkill stress' ERR EXIT |
| 117 | "$@" |
| 118 | )} |
| 119 | |
| 120 | function check-clang-formatscip-shell shell shell-project 0.0.0 check-clang-format(). {(set -e |
| 121 | echoscip-shell system . . echo. "Dry run of clang-format" |
| 122 | (cd $SRC_ROOT; |
| 123 | include_regex=".*\.(c|h)$"; |
| 124 | src_files=`findscip-shell system . . find. ./api -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 125 | src_files+=" "; |
| 126 | src_files+=`findscip-shell system . . find. ./bin -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 127 | src_files+=" "; |
| 128 | src_files+=`findscip-shell system . . find. ./crypto -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 129 | src_files+=" "; |
| 130 | src_files+=`findscip-shell system . . find. ./stuffer -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 131 | src_files+=" "; |
| 132 | src_files+=`findscip-shell system . . find. ./error -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 133 | src_files+=" "; |
| 134 | src_files+=`findscip-shell system . . find. ./tls -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 135 | src_files+=" "; |
| 136 | src_files+=`findscip-shell system . . find. ./utils -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 137 | src_files+=" "; |
| 138 | src_files+=`findscip-shell system . . find. ./tests/unit -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 139 | src_files+=" "; |
| 140 | src_files+=`findscip-shell system . . find. ./tests/testlib -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 141 | echoscip-shell system . . echo. $src_files | xargsscip-shell system . . xargs. -n 1 -P $(nprocscip-shell system . . nproc.) clang-format --dry-run -style=file) |
| 142 | )} |
| 143 | |
| 144 | function do-clang-formatscip-shell shell shell-project 0.0.0 do-clang-format(). {(set -e |
| 145 | echoscip-shell system . . echo. "In place clang-format" |
| 146 | (cd $SRC_ROOT; |
| 147 | include_regex=".*\.(c|h)$"; |
| 148 | src_files=`findscip-shell system . . find. ./api -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 149 | src_files+=" "; |
| 150 | src_files+=`findscip-shell system . . find. ./bin -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 151 | src_files+=" "; |
| 152 | src_files+=`findscip-shell system . . find. ./crypto -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 153 | src_files+=" "; |
| 154 | src_files+=`findscip-shell system . . find. ./stuffer -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 155 | src_files+=" "; |
| 156 | src_files+=`findscip-shell system . . find. ./error -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 157 | src_files+=" "; |
| 158 | src_files+=`findscip-shell system . . find. ./tls -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 159 | src_files+=" "; |
| 160 | src_files+=`findscip-shell system . . find. ./utils -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 161 | src_files+=" "; |
| 162 | src_files+=`findscip-shell system . . find. ./tests/unit -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 163 | src_files+=" "; |
| 164 | src_files+=`findscip-shell system . . find. ./tests/testlib -name .git -prune -o -regextype posix-egrep -regex "$include_regex" -print`; |
| 165 | echoscip-shell system . . echo. $src_files | xargsscip-shell system . . xargs. -n 1 -P $(nprocscip-shell system . . nproc.) clang-format -style=file -i) |
| 166 | )} |
| 167 | |
| 168 | function test_toolchain_countsscip-shell shell shell-project 0.0.0 test_toolchain_counts(). {(set -e |
| 169 | # This is a starting point for a unit test of the devShell. |
| 170 | # The chosen S2N_LIBCRYPTO should be 2, and the others should be zero. |
| 171 | echoscip-shell system . . echo. "Checking the CMAKE_INCLUDE_PATH for libcrypto counts" |
| 172 | echoscip-shell system . . echo. $CMAKE_INCLUDE_PATH|gawkscip-shell system . . gawk. 'BEGIN{RS=":"; o10=0; o11=0; o3=0;awslc=0;libre=0} |
| 173 | /openssl-3.0/{o3++} |
| 174 | /openssl-1.1/{o11++} |
| 175 | /openssl-1.0/{o10++} |
| 176 | /aws-lc/{awslc++} |
| 177 | /libressl/{libre++} |
| 178 | END{print "\nOpenssl3:\t",o3,"\nOpenssl1.1:\t",o11,"\nOpenssl1.0.2:\t",o10,"\nAws-lc:\t\t",awslc,"\nLibreSSL:\t", libre}' |
| 179 | echoscip-shell system . . echo. "Checking tooling counts (these should all be 1)" |
| 180 | echoscip-shell system . . echo. -e "\nOpenssl integ:\t $(opensslscip-shell system . . openssl. version|grepscip-shell system . . grep. -c '1.1.1')" |
| 181 | echoscip-shell system . . echo. -e "Corretto 17:\t $(javascip-shell system . . java. -version 2>&1|grepscip-shell system . . grep. -ce 'Runtime.*Corretto-17')" |
| 182 | echoscip-shell system . . echo. -e "gnutls-cli:\t $(gnutls-cli --version |grepscip-shell system . . grep. -c 'gnutls-cli 3.7')" |
| 183 | echoscip-shell system . . echo. -e "gnutls-serv:\t $(gnutls-serv --version |grepscip-shell system . . grep. -c 'gnutls-serv 3.7')" |
| 184 | echoscip-shell system . . echo. -e "Nix Python:\t $(whichscip-shell system . . which. python|grepscip-shell system . . grep. -c '/nix/storescip-shell filesystem . . `/nix/store`.')" |
| 185 | echoscip-shell system . . echo. -e "Nix pytest:\t $(whichscip-shell system . . which. pytest|grepscip-shell system . . grep. -c '/nix/storescip-shell filesystem . . `/nix/store`.')" |
| 186 | echoscip-shell system . . echo. -e "Nix sslyze:\t $(whichscip-shell system . . which. sslyze|grepscip-shell system . . grep. -c '/nix/storescip-shell filesystem . . `/nix/store`.')" |
| 187 | echoscip-shell system . . echo. -e "python nassl:\t $(pipscip-shell system . . pip. freeze|grepscip-shell system . . grep. -c 'nassl')" |
| 188 | echoscip-shell system . . echo. -e "valgrind:\t $(valgrind --version|grepscip-shell system . . grep. -c 'valgrind-3.19.0')" |
| 189 | )} |
| 190 | |
| 191 | function test_nonstandard_compilationscip-shell shell shell-project 0.0.0 test_nonstandard_compilation(). {(set -e |
| 192 | # Any script that needs to compile s2n in a non-standard way can run here |
| 193 | ./codebuild/bin/test_dynamic_load.sh $(mktempscip-shell system . . mktemp. -d) |
| 194 | )} |
| 195 | |
| 196 | function apache2_configscip-shell shell shell-project 0.0.0 apache2_config().(){ |
| 197 | export APACHE_NIX_STORE=$(dirnamescip-shell system . . dirname. $(dirnamescip-shell system . . dirname. $(whichscip-shell system . . which. httpd))) |
| 198 | export APACHE2_INSTALL_DIR=/usr/local/apache2scip-shell filesystem . . `/usr/local/apache2`. |
| 199 | export APACHE_SERVER_ROOT="$APACHE2_INSTALL_DIR" |
| 200 | export APACHE_RUN_USER=nobody |
| 201 | # Unprivileged groupname differs |
| 202 | export APACHE_RUN_GROUP=$(awkscip-shell system . . awk. 'BEGIN{FS=":"} /65534/{print $1}' /etc/groupscip-shell filesystem . . `/etc/group`.) |
| 203 | export APACHE_PID_FILE="${APACHE2_INSTALL_DIR}/run/apache2.pid" |
| 204 | export APACHE_RUN_DIR="${APACHE2_INSTALL_DIR}/run" |
| 205 | export APACHE_LOCK_DIR="${APACHE2_INSTALL_DIR}/lock" |
| 206 | export APACHE_LOG_DIR="${APACHE2_INSTALL_DIR}/log" |
| 207 | export APACHE_CERT_DIR="$SRC_ROOT/tests/pems" |
| 208 | } |
| 209 | |
| 210 | function apache2_startscip-shell shell shell-project 0.0.0 apache2_start().(){ |
| 211 | if [[ "$(pgrep -c httpd)" -eq "0" ]]; then |
| 212 | apache2_configscip-shell shell shell-project 0.0.0 apache2_config(). |
| 213 | if [[ ! -f "$APACHE2_INSTALL_DIR/conf/apache2.conf" ]]; then |
| 214 | mkdirscip-shell system . . mkdir. -p $APACHE2_INSTALL_DIR/{run,log,lock} |
| 215 | # NixOs specific base apache config |
| 216 | cpscip-shell system . . cp. -R ./tests/integrationv2/apache2/nix/* $APACHE2_INSTALL_DIR |
| 217 | # Integrationv2::renegotiate site |
| 218 | cpscip-shell system . . cp. -R ./codebuild/bin/apache2/{www,sites-enabled} $APACHE2_INSTALL_DIR |
| 219 | fi |
| 220 | httpd -k start -f "${APACHE2_INSTALL_DIR}/conf/apache2.conf" |
| 221 | trap 'pkill httpd' ERR EXIT |
| 222 | else |
| 223 | echoscip-shell system . . echo. "Apache is already running. If \"$APACHE2_INSTALL_DIR\" is stale, it might be in an unknown state." |
| 224 | fi |
| 225 | } |
| 226 | |
| 227 | function rust_configurescip-shell shell shell-project 0.0.0 rust_configure(). {(set -e |
| 228 | echoscip-shell system . . echo. "rust_configure: Cleaning previous build" |
| 229 | rmscip-shell system . . rm. -rf build/ |
| 230 | echoscip-shell system . . echo. "rust_configure: Configuring with CMake (RelWithDebInfo, intern libcrypto)" |
| 231 | cmakescip-shell system . . cmake. -B build . \ |
| 232 | -D CMAKE_C_COMPILER=clang \ |
| 233 | -D CMAKE_BUILD_TYPE=RelWithDebInfo \ |
| 234 | -D BUILD_TESTING=OFF \ |
| 235 | -D S2N_INTERN_LIBCRYPTO=ON |
| 236 | )} |
| 237 | |
| 238 | function rust_buildscip-shell shell shell-project 0.0.0 rust_build(). {(set -e |
| 239 | echoscip-shell system . . echo. "rust_build: Building s2n-tls" |
| 240 | cmakescip-shell system . . cmake. --build ./build -j $(nprocscip-shell system . . nproc.) |
| 241 | echoscip-shell system . . echo. "rust_build: Generating Rust bindings (bindgen)" |
| 242 | bindings/rust/extended/generate.sh --skip-tests |
| 243 | )} |
| 244 | |
| 245 | function rust_testscip-shell shell shell-project 0.0.0 rust_test(). {(set -e |
| 246 | echoscip-shell system . . echo. "rust_test: Setting up local Rust toolchain (rustup stable)" |
| 247 | export RUSTUP_HOME=$(pwdscip-shell system . . pwd.)/.rustup |
| 248 | export CARGO_HOME=$(pwdscip-shell system . . pwd.)/.cargo |
| 249 | export PATH=$(pwdscip-shell system . . pwd.)/.cargo/bin:$PATH |
| 250 | echoscip-shell system . . echo. "rust_test: Exporting s2n-tls headers and libs for Cargo" |
| 251 | export S2N_TLS_LIB_DIR=$(pwdscip-shell system . . pwd.)/build/lib |
| 252 | export S2N_TLS_INCLUDE_DIR=$(pwdscip-shell system . . pwd.)/api |
| 253 | echoscip-shell system . . echo. "rust_test: Running Rust integration tests" |
| 254 | cargoscip-shell system . . cargo. test --manifest-path bindings/rust/standard/integration/Cargo.toml --features boringssl |
| 255 | )} |