Skip to content

Commit 30508cf

Browse files
committed
tools: add an OpenSSL FIPS build to test-shared.yml
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 808904f commit 30508cf

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

tools/dep_updaters/update-nixpkgs-pin.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ nix-instantiate -I "nixpkgs=$NIXPKGS_PIN_FILE" --eval --strict --json -E "
7272
inherit (pkgs)
7373
\(.attrs | sort | join("\n "))
7474
;
75+
76+
# Keep this aligned with the bundled OpenSSL major/minor.
77+
openssl_3_5_fips = import ./openssl-fips.nix {
78+
inherit pkgs;
79+
openssl = pkgs.openssl_3_5;
80+
};
7581
}"' > "$OPENSSL_MATRIX_FILE"
7682

7783
cat -<<EOF

tools/nix/openssl-fips.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{ openssl }:
2+
3+
openssl.overrideAttrs (oldAttrs: {
4+
pname = "openssl-fips";
5+
6+
configureFlags = (oldAttrs.configureFlags or [ ]) ++ [ "enable-fips" ];
7+
8+
# Nix strips the provider after installation, invalidating the module MAC
9+
# generated by OpenSSL's install_fips target. Regenerate and verify it in
10+
# postFixup, after stripping has finished modifying the provider.
11+
postFixup = (oldAttrs.postFixup or "") + ''
12+
opensslConfig="$out/etc/ssl/openssl.cnf"
13+
fipsModule="$out/lib/ossl-modules/fips${openssl.stdenv.hostPlatform.extensions.sharedLibrary}"
14+
fipsConfig="$out/etc/ssl/fipsmodule.cnf"
15+
16+
substituteInPlace "$opensslConfig" \
17+
--replace-fail 'openssl_conf = openssl_init' $'openssl_conf = openssl_init\nnodejs_conf = openssl_init' \
18+
--replace-fail '# .include fipsmodule.cnf' ".include $fipsConfig" \
19+
--replace-fail 'providers = provider_sect' $'providers = provider_sect\nalg_section = algorithm_sect' \
20+
--replace-fail '# fips = fips_sect' 'fips = fips_sect' \
21+
--replace-fail '# activate = 1' $'activate = 1\n\n[algorithm_sect]\ndefault_properties = fips=yes'
22+
23+
OPENSSL_CONF=/dev/null "$bin/bin/openssl" fipsinstall \
24+
-module "$fipsModule" \
25+
-out "$fipsConfig"
26+
27+
OPENSSL_CONF=/dev/null "$bin/bin/openssl" fipsinstall \
28+
-config "$opensslConfig"
29+
30+
export OPENSSL_CONF="$opensslConfig"
31+
"$bin/bin/openssl" mac \
32+
-digest SHA256 -macopt key:key HMAC </dev/null >/dev/null
33+
if "$bin/bin/openssl" md5 </dev/null >/dev/null 2>&1; then
34+
echo "MD5 unexpectedly available with FIPS properties enabled" >&2
35+
exit 1
36+
fi
37+
'';
38+
})

tools/nix/openssl-matrix.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
openssl_3_6
1414
openssl_4_0
1515
;
16+
17+
# Keep this aligned with the bundled OpenSSL major/minor.
18+
openssl_3_5_fips = import ./openssl-fips.nix {
19+
openssl = pkgs.openssl_3_5;
20+
};
1621
}

0 commit comments

Comments
 (0)