Skip to content

Commit

Permalink
Add NSS Mozilla cert test for FIPS. Fixes #615
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Herranz Ramírez authored and pablo-herranz committed Oct 28, 2024
1 parent adc5653 commit 6c426e4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,35 @@ def test_icainfo_binary(container_per_test: ContainerData) -> None:
)
container_per_test.connection.check_output("icastats -k")
container_per_test.connection.check_output("icastats -S")


@pytest.mark.parametrize(
"container_per_test", FIPS_TESTER_IMAGES, indirect=True
)
def test_nss_firefox_cert(container_per_test: ContainerData) -> None:
container_per_test.connection.check_output(
"zypper -n install mozilla-nss mozilla-nss-tools"
)
# Seed file
container_per_test.connection.check_output(
"cat /dev/urandom | head -n 120 > seedfile.dat"
)
# Empty password
container_per_test.connection.check_output('echo "" > password.txt')
# Create database, needed prerequisite, needs one <enter> as interaction
assert (
container_per_test.connection.check_output(
'rm -rf nssdb && mkdir -p nssdb && certutil -N -d "${PWD}/nssdb" --empty-password && modutil -fips true -dbdir "${PWD}/nssdb" -force'
)
== "FIPS mode enabled."
), "FIPS mode not enabled properly"
# Following will fail in FIPS mode because to short rsa keylength (1024)
assert container_per_test.connection.run_expect(
[255],
'NSS_FIPS=1 certutil -R -k rsa -g 1024 -s "CN=Daniel Duesentrieb3,O=Example Corp,L=Mountain View,ST=California,C=DE" -d "${PWD}/nssdb" -o cert9.cer -f password.txt -z seedfile.dat',
), "RSA keylengths of 1024 or shorter must not be enabled in FIPS mode"

assert container_per_test.connection.run_expect(
[0],
'NSS_FIPS=1 certutil -R -k rsa -g 2048 -s "CN=Daniel Duesentrieb3,O=Example Corp,L=Mountain View,ST=California,C=DE" -d "${PWD}/nssdb" -o cert9.cer -f password.txt -z seedfile.dat',
), "RSA keylengths of 2048 or greater should work fine in FIPS mode"

0 comments on commit 6c426e4

Please sign in to comment.