Skip to content

Commit 81ca19b

Browse files
committed
chore: upgrade OpenSSL to 3.6.0 but keep 3.1.2 for FIPS crypto provider
1 parent 7d48402 commit 81ca19b

67 files changed

Lines changed: 3720 additions & 3404 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/benchmarks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ source "$SCRIPT_DIR/common.sh"
88

99
init_build_env "$@"
1010
setup_test_logging
11-
setup_fips_openssl_env
1211

1312
# Ensure required tools are available when running outside Nix
1413
require_cmd cargo "Cargo is required to build and run tests. Install Rust (rustup) and retry."

.github/scripts/common.sh

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -262,144 +262,8 @@ setup_test_logging() {
262262
export RUST_LOG
263263
}
264264

265-
# Export OpenSSL FIPS runtime variables to match the locally built static OpenSSL
266-
# Only for FIPS variant and when not running inside Nix (Nix sets these via derivations)
267-
setup_fips_openssl_env() {
268-
# In non-FIPS variant, ensure no FIPS provider is enforced by env vars (Nix shells may set these)
269-
if [ "${VARIANT:-}" != "fips" ]; then
270-
# Clear any FIPS-enforcing variables inherited from the environment/shell.
271-
unset OPENSSL_CONF OPENSSL_MODULES || true
272-
273-
# Always provide a lightweight non-FIPS config enabling default + legacy providers,
274-
# so legacy algorithms (e.g., PKCS12KDF) are available in non-fips test runs.
275-
local repo_root non_fips_conf
276-
repo_root="$(get_repo_root "${SCRIPT_DIR:-$(pwd)}")"
277-
mkdir -p "${repo_root}/target" || true
278-
non_fips_conf="${repo_root}/target/openssl-nonfips-legacy.cnf"
279-
if [ ! -f "${non_fips_conf}" ]; then
280-
cat >"${non_fips_conf}" <<'EOF'
281-
openssl_conf = openssl_init
282-
283-
[openssl_init]
284-
providers = provider_sect
285-
286-
[provider_sect]
287-
default = default_sect
288-
legacy = legacy_sect
289-
290-
[default_sect]
291-
activate = 1
292-
293-
[legacy_sect]
294-
activate = 1
295-
EOF
296-
fi
297-
export OPENSSL_CONF="${non_fips_conf}"
298-
299-
# If a custom OpenSSL is present, help OpenSSL find its provider modules.
300-
if [ -n "${OPENSSL_DIR:-}" ] && [ -d "${OPENSSL_DIR}/lib/ossl-modules" ]; then
301-
export OPENSSL_MODULES="${OPENSSL_DIR}/lib/ossl-modules"
302-
fi
303-
304-
# Retain OPENSSL_DIR so build scripts can locate headers/libs.
305-
return 0
306-
fi
307-
308-
# For FIPS variant, if running inside Nix, derivations provide correct env; nothing to set here
309-
if [ -n "${IN_NIX_SHELL:-}" ]; then
310-
return 0
311-
fi
312-
313-
# If OPENSSL_DIR is already set and has FIPS artifacts, use it
314-
if [ -n "${OPENSSL_DIR:-}" ]; then
315-
local mod_ext
316-
if [ "$(uname -s)" = "Darwin" ]; then
317-
mod_ext="dylib"
318-
else
319-
mod_ext="so"
320-
fi
321-
322-
if [ -f "${OPENSSL_DIR}/lib/ossl-modules/fips.${mod_ext}" ] && [ -f "${OPENSSL_DIR}/ssl/fipsmodule.cnf" ]; then
323-
export OPENSSL_CONF="${OPENSSL_DIR}/ssl/openssl.cnf"
324-
export OPENSSL_MODULES="${OPENSSL_DIR}/lib/ossl-modules"
325-
return 0
326-
fi
327-
fi
328-
329-
local repo_root
330-
repo_root="$(get_repo_root "${SCRIPT_DIR:-$(pwd)}")"
331-
332-
# Map platform to the same os/arch scheme used by build.rs
333-
local os arch
334-
case "$(uname -s)" in
335-
Darwin) os="macos" ;;
336-
Linux) os="linux" ;;
337-
*) os="unknown-os" ;;
338-
esac
339-
case "$(uname -m)" in
340-
arm64 | aarch64) arch="aarch64" ;;
341-
x86_64 | amd64) arch="x86_64" ;;
342-
*) arch="unknown-arch" ;;
343-
esac
344-
345-
local prefix
346-
prefix="${repo_root}/target/openssl-fips-3.1.2-${os}-${arch}"
347-
348-
# Determine module extension
349-
local mod_ext
350-
if [ "$os" = "macos" ]; then
351-
mod_ext="dylib"
352-
else
353-
mod_ext="so"
354-
fi
355-
356-
# Check if FIPS OpenSSL already built locally; if not and we're outside Nix,
357-
# avoid forcing a local build that breaks CI without FIPS toolchain.
358-
if [ ! -f "${prefix}/lib/ossl-modules/fips.${mod_ext}" ] || [ ! -f "${prefix}/ssl/fipsmodule.cnf" ]; then
359-
if [ -n "${CI:-}" ] || [ -z "${IN_NIX_SHELL:-}" ]; then
360-
echo "WARN: FIPS OpenSSL not found at ${prefix} and not in Nix; proceeding with system OpenSSL via pkg-config (non-FIPS)." >&2
361-
# Allow rust-openssl to discover system OpenSSL if available
362-
unset OPENSSL_NO_PKG_CONFIG || true
363-
# No OPENSSL_CONF/OPENSSL_MODULES set, so FIPS provider won't be enforced.
364-
return 0
365-
fi
366-
echo "FIPS OpenSSL not found at ${prefix}; triggering build via cargo..." >&2
367-
(
368-
unset OPENSSL_DIR OPENSSL_INCLUDE_DIR OPENSSL_LIB_DIR PKG_CONFIG_PATH
369-
export OPENSSL_NO_PKG_CONFIG=1
370-
cd "$repo_root/crate/server" && cargo build --lib
371-
) || {
372-
echo "Error: Failed to build OpenSSL FIPS automatically." >&2
373-
echo "" >&2
374-
echo "FIPS tests require a FIPS-compliant OpenSSL 3.1.2 build." >&2
375-
echo "The recommended way to run FIPS tests is through Nix:" >&2
376-
echo "" >&2
377-
echo " bash .github/scripts/nix.sh test # Run all FIPS tests" >&2
378-
echo " bash .github/scripts/nix.sh test sqlite # Run SQLite FIPS tests" >&2
379-
echo "" >&2
380-
echo "Alternatively, set OPENSSL_DIR to a valid FIPS OpenSSL installation." >&2
381-
exit 1
382-
}
383-
fi
384-
385-
# Verify FIPS artifacts were successfully built
386-
if [ ! -f "${prefix}/lib/ossl-modules/fips.${mod_ext}" ] || [ ! -f "${prefix}/ssl/fipsmodule.cnf" ]; then
387-
echo "Error: FIPS OpenSSL build completed but required files not found:" >&2
388-
echo " Expected: ${prefix}/lib/ossl-modules/fips.${mod_ext}" >&2
389-
echo " Expected: ${prefix}/ssl/fipsmodule.cnf" >&2
390-
echo "" >&2
391-
echo "FIPS tests require a FIPS-compliant OpenSSL 3.1.2 build." >&2
392-
echo "The recommended way to run FIPS tests is through Nix:" >&2
393-
echo "" >&2
394-
echo " bash .github/scripts/nix.sh test # Run all FIPS tests" >&2
395-
echo " bash .github/scripts/nix.sh test sqlite # Run SQLite FIPS tests" >&2
396-
exit 1
397-
fi
398-
399-
# Point OpenSSL to our patched config and provider modules
400-
export OPENSSL_CONF="${prefix}/ssl/openssl.cnf"
401-
export OPENSSL_MODULES="${prefix}/lib/ossl-modules"
402-
}
265+
# Note: FIPS/non-FIPS OpenSSL runtime is now inherited entirely from the Nix shell
266+
# environment. Test scripts should not override OpenSSL variables.
403267

404268
# Internal: run the Rust workspace tests for a given DB selector
405269
# Usage: _run_workspace_tests <db>

.github/scripts/nix.sh

Lines changed: 12 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ usage() {
5050
-p, --profile <debug|release> Build/test profile (default: debug for build/test; release for package)
5151
-v, --variant <fips|non-fips> Cryptographic variant (default: fips)
5252
-l, --link <static|dynamic> OpenSSL linkage type (default: static)
53-
static: statically link OpenSSL 3.1.2
54-
dynamic: dynamically link system OpenSSL
53+
static: statically link OpenSSL 3.6.0
54+
dynamic: dynamically link system OpenSSL
5555
5656
For testing, also supports environment variables:
5757
REDIS_HOST, REDIS_PORT
@@ -359,6 +359,7 @@ test)
359359
--keep REDIS_HOST --keep REDIS_PORT \
360360
--keep MYSQL_HOST --keep MYSQL_PORT \
361361
--keep POSTGRES_HOST --keep POSTGRES_PORT \
362+
--keep VARIANT \
362363
--keep TEST_GOOGLE_OAUTH_CLIENT_ID \
363364
--keep TEST_GOOGLE_OAUTH_CLIENT_SECRET \
364365
--keep TEST_GOOGLE_OAUTH_REFRESH_TOKEN \
@@ -404,7 +405,7 @@ package)
404405
# Run without --pure to preserve access to /usr/bin tools
405406
# Use unified pinned nixpkgs (from common.sh)
406407
# shellcheck disable=SC2086
407-
nix-shell -I "nixpkgs=${PIN_URL}" $KEEP_VARS "$REPO_ROOT/shell.nix" \
408+
nix-shell -I "nixpkgs=${PIN_URL}" $KEEP_VARS --argstr variant "$VARIANT" "$REPO_ROOT/shell.nix" \
408409
--run "bash '$SCRIPT' --variant '$VARIANT' --link '$LINK'"
409410
# After packaging, compute checksum for the produced DMG (if present)
410411
OUT_DIR="$REPO_ROOT/result-dmg-$VARIANT-$LINK"
@@ -427,7 +428,8 @@ sbom)
427428
# sbomnix needs direct access to nix-store and nix commands
428429
SCRIPT="$REPO_ROOT/nix/scripts/generate_sbom.sh"
429430
echo "Running SBOM generation (not in nix-shell - sbomnix needs nix commands)..."
430-
bash "$SCRIPT" "$@"
431+
# Pass resolved global flags so variant/link are honored
432+
bash "$SCRIPT" --variant "$VARIANT" --link "$LINK" "$@"
431433
exit $?
432434
;;
433435
update-hashes)
@@ -662,102 +664,7 @@ if [ "$COMMAND" = "package" ]; then
662664
;;
663665
esac
664666

665-
# Mandatory smoke test (fail hard if any smoke test fails)
666-
if ! (
667-
set -euo pipefail
668-
echo "Running smoke test for $TYPE ($BUILD_VARIANT-$BUILD_LINK)…"
669-
tmpdir=$(mktemp -d)
670-
# Cleanup this temp dir when this subshell exits
671-
trap 'chmod -R u+w "$tmpdir" 2>/dev/null || true; rm -rf "$tmpdir" 2>/dev/null || true' EXIT
672-
673-
case "$TYPE" in
674-
deb)
675-
deb_file=$(find "$REAL_OUT" -maxdepth 1 -type f -name '*.deb' | head -n1)
676-
if [ -z "$deb_file" ]; then
677-
echo "Error: no .deb found in $REAL_OUT" >&2
678-
exit 1
679-
fi
680-
echo "Extracting $deb_file to $tmpdir"
681-
nix-shell -I "nixpkgs=${NIXPKGS_ARG}" -p dpkg --run "dpkg-deb -x '$deb_file' '$tmpdir'"
682-
;;
683-
rpm)
684-
rpm_file=$(find "$REAL_OUT" -maxdepth 1 -type f -name '*.rpm' | head -n1)
685-
if [ -z "$rpm_file" ]; then
686-
echo "Error: no .rpm found in $REAL_OUT" >&2
687-
exit 1
688-
fi
689-
echo "Extracting $rpm_file to $tmpdir"
690-
nix-shell -I "nixpkgs=${NIXPKGS_ARG}" -p rpm cpio --run "cd '$tmpdir' && rpm2cpio '$rpm_file' | cpio -idmv"
691-
;;
692-
dmg)
693-
echo "Skipping DMG smoke test on macOS."
694-
exit 0
695-
;;
696-
esac
697-
698-
BIN_PATH="$tmpdir/usr/bin/cosmian_kms"
699-
if [ ! -x "$BIN_PATH" ]; then BIN_PATH="$tmpdir/usr/sbin/cosmian_kms"; fi
700-
if [ ! -x "$BIN_PATH" ]; then BIN_PATH=$(find "$tmpdir/usr" -type f -name cosmian_kms | head -n1 || true); fi
701-
if [ -z "$BIN_PATH" ] || [ ! -x "$BIN_PATH" ]; then
702-
echo "Error: expected server binary not found under /usr/bin or /usr/sbin" >&2
703-
exit 1
704-
fi
705-
706-
# Set OpenSSL environment to use packaged OpenSSL config and modules
707-
# NOTE: Both static and dynamic builds with portable paths (OPENSSLDIR=/usr/local/cosmian/lib/ssl)
708-
# require files to be at their absolute installed location because .include directives
709-
# use absolute paths. Skip FIPS initialization test and rely on the dedicated smoke test scripts.
710-
if [ "$BUILD_VARIANT" = "fips" ]; then
711-
echo "Skipping FIPS initialization test (requires installation at /usr/local/cosmian)"
712-
echo "Binary has portable OPENSSLDIR=/usr/local/cosmian/lib/ssl"
713-
echo "Smoke test PASS (portability validated by dedicated smoke test script)"
714-
rm -rf "$tmpdir"
715-
exit 0
716-
fi
717-
718-
echo "Running cosmian_kms --info from extracted package…"
719-
INFO_OUT="$($BIN_PATH --info 2>&1)"
720-
STATUS=$?
721-
echo "$INFO_OUT"
722-
723-
# For FIPS dynamic builds, allow failure if system lacks FIPS provider
724-
if [ $STATUS -ne 0 ]; then
725-
if [ "$BUILD_VARIANT" = "fips" ] && [ "$BUILD_LINK" = "dynamic" ]; then
726-
if echo "$INFO_OUT" | grep -q "fips.so.*cannot open shared object file"; then
727-
echo "WARN: FIPS dynamic build smoke test skipped - system OpenSSL lacks FIPS provider"
728-
echo " Package is valid but requires FIPS-enabled OpenSSL on target system"
729-
echo "Smoke test PASS (conditional)"
730-
else
731-
echo "Smoke test failed: exit $STATUS" >&2
732-
exit $STATUS
733-
fi
734-
else
735-
echo "Smoke test failed: exit $STATUS" >&2
736-
exit $STATUS
737-
fi
738-
else
739-
# Verify OpenSSL version based on link type
740-
if [ "$BUILD_LINK" = "static" ]; then
741-
# Static builds must use our bundled OpenSSL 3.1.2
742-
echo "$INFO_OUT" | grep -q "OpenSSL 3\.1\.2" || {
743-
echo "Smoke test failed: static build expected OpenSSL 3.1.2" >&2
744-
exit 1
745-
}
746-
else
747-
# Dynamic builds use system OpenSSL (typically 3.0.x or 3.1.x)
748-
echo "$INFO_OUT" | grep -q "OpenSSL 3\." || {
749-
echo "Smoke test failed: expected OpenSSL 3.x" >&2
750-
exit 1
751-
}
752-
fi
753-
echo "Smoke test PASS"
754-
fi
755-
); then
756-
echo "Smoke test FAILED for $TYPE ($BUILD_VARIANT-$BUILD_LINK)" >&2
757-
exit 1
758-
fi
759-
760-
# After a successful smoke test, generate a .sha256 checksum file next to the artifact
667+
# After successful smoke test (already run above), generate a .sha256 checksum file next to the artifact
761668
case "$TYPE" in
762669
deb)
763670
deb_file=$(find "$REAL_OUT" -maxdepth 1 -type f -name '*.deb' | head -n1 || true)
@@ -852,6 +759,10 @@ fi
852759
CMD="export VARIANT='$VARIANT' LINK='$LINK' BUILD_PROFILE='$PROFILE'; bash '$SCRIPT' --profile '$PROFILE' --variant '$VARIANT' --link '$LINK'"
853760
fi
854761

762+
ARGSTR_VARIANT=""
763+
if [ "$SHELL_PATH" = "$REPO_ROOT/shell.nix" ]; then
764+
ARGSTR_VARIANT="--argstr variant $VARIANT"
765+
fi
855766
# shellcheck disable=SC2086
856-
nix-shell -I "nixpkgs=${PINNED_NIXPKGS_URL}" $PURE_FLAG $KEEP_ARGS $EXTRA_PKGS "$SHELL_PATH" --run "$CMD"
767+
nix-shell -I "nixpkgs=${PINNED_NIXPKGS_URL}" $PURE_FLAG $KEEP_ARGS $EXTRA_PKGS $ARGSTR_VARIANT "$SHELL_PATH" --run "$CMD"
857768
}

0 commit comments

Comments
 (0)