|
| 1 | +{ |
| 2 | + openssl ? (import ./openssl-matrix.nix { }).openssl, |
| 3 | +}: |
| 4 | + |
| 5 | +openssl.overrideAttrs (oldAttrs: { |
| 6 | + pname = "openssl-fips"; |
| 7 | + |
| 8 | + doCheck = false; |
| 9 | + configureFlags = (oldAttrs.configureFlags or [ ]) ++ [ |
| 10 | + "no-docs" |
| 11 | + "no-tests" |
| 12 | + "enable-fips" |
| 13 | + ]; |
| 14 | + outputs = [ |
| 15 | + "bin" |
| 16 | + "out" |
| 17 | + "dev" |
| 18 | + ]; |
| 19 | + |
| 20 | + # Nix strips the provider after installation, invalidating the module MAC |
| 21 | + # generated by OpenSSL's install_fips target. Regenerate and verify it in |
| 22 | + # postFixup, after stripping has finished modifying the provider. |
| 23 | + postFixup = (oldAttrs.postFixup or "") + '' |
| 24 | + opensslConfig="$out/etc/ssl/openssl.cnf" |
| 25 | + fipsModule="$out/lib/ossl-modules/fips${openssl.stdenv.hostPlatform.extensions.sharedLibrary}" |
| 26 | + fipsConfig="$out/etc/ssl/fipsmodule.cnf" |
| 27 | +
|
| 28 | + substituteInPlace "$opensslConfig" \ |
| 29 | + --replace-fail 'openssl_conf = openssl_init' $'openssl_conf = openssl_init\nnodejs_conf = openssl_init' \ |
| 30 | + --replace-fail '# .include fipsmodule.cnf' ".include $fipsConfig" \ |
| 31 | + --replace-fail 'providers = provider_sect' $'providers = provider_sect\nalg_section = algorithm_sect' \ |
| 32 | + --replace-fail '# fips = fips_sect' 'fips = fips_sect' \ |
| 33 | + --replace-fail '# activate = 1' $'activate = 1\n\n[algorithm_sect]\ndefault_properties = fips=yes' |
| 34 | +
|
| 35 | + OPENSSL_CONF=/dev/null "$bin/bin/openssl" fipsinstall \ |
| 36 | + -module "$fipsModule" \ |
| 37 | + -out "$fipsConfig" |
| 38 | +
|
| 39 | + OPENSSL_CONF=/dev/null "$bin/bin/openssl" fipsinstall \ |
| 40 | + -config "$opensslConfig" |
| 41 | + ''; |
| 42 | + |
| 43 | + doInstallCheck = true; |
| 44 | + installCheckPhase = '' |
| 45 | + runHook preInstallCheck |
| 46 | +
|
| 47 | + export PATH="$bin/bin:$PATH" |
| 48 | +
|
| 49 | + openssl mac \ |
| 50 | + -digest SHA256 -macopt key:key HMAC </dev/null >/dev/null |
| 51 | + openssl md5 </dev/null >/dev/null 2>&1 \ |
| 52 | + && echo "MD5 unexpectedly available with FIPS properties enabled" >&2 \ |
| 53 | + && exit 1 |
| 54 | +
|
| 55 | + runHook postInstallCheck |
| 56 | + ''; |
| 57 | +}) |
0 commit comments