Skip to content

Commit

Permalink
New test for nss crypto policies
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmanzo committed Jan 16, 2025
1 parent 94bc815 commit 5553980
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
19 changes: 19 additions & 0 deletions data/security/crypto_policies/nss.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/bash
OUTFILE=$1
set -eux
# create NSS database
rm -rf nssdb && mkdir -p nssdb
certutil -N -d sql:./nssdb --empty-password
# generate an openssl keypair
# (size 2048 to cover also FUTURE cryptopolicy)
openssl req -new -newkey rsa:2048 -x509 -days 7 -nodes -subj "/CN=localhost" -out localhost.pem -keyout localhost.key
# import this certificate into the NSS database and mark it as trusted
certutil -d ./nssdb -A -a -i localhost.pem -t TCP -n localhost
# spin up a temp TLS server
openssl s_server -accept 4443 -cert localhost.pem -key localhost.key -www &
SERVER_PID=$!
# call the server with nss client
(echo "GET / HTTP/1.0" | /usr/lib/nss/tstclnt -d ./nssdb -h localhost -p 4443 2>&1 > $OUTFILE) &
sleep 5
kill $SERVER_PID
killall tstclnt
26 changes: 25 additions & 1 deletion tests/security/crypto_policies/crypto_policies_tests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# Maintainer: QE Security <[email protected]>

use base 'opensusebasetest';
use strict;
use warnings;
use strict;
use v5.20;
use feature qw(signatures);
no warnings qw(experimental::signatures);
use testapi;
use serial_terminal 'select_serial_terminal';
use utils;
Expand All @@ -20,6 +23,7 @@ sub run {
select_serial_terminal;
setup_bind();
setup_gnutls();
setup_nss();
foreach my $s (@services) {
systemctl "enable --now $s.service";
}
Expand All @@ -31,6 +35,7 @@ sub run {
}
ensure_bind_is_working();
ensure_gnutls_is_working();
ensure_nss_is_working_with($policy);
}
}

Expand All @@ -55,6 +60,25 @@ sub setup_gnutls {
zypper_call 'in gnutls';
}

sub setup_nss {
zypper_call 'in mozilla-nss mozilla-nss-tools';
assert_script_run 'curl -O ' . data_url('security/crypto_policies/nss.sh');
assert_script_run 'chmod +x nss.sh';
}

sub ensure_nss_is_working_with($policy) {
# call the server with nss client
my $logfile = "nss_client_${policy}_policy.txt";
assert_script_run("./nss.sh $logfile");
# stop child processes
upload_logs $logfile;
# check if result is good
assert_script_run('grep "HTTP/1.0 200 ok" ' . $logfile);
assert_script_run('grep "1 server accepts (SSL_accept())" ' . $logfile);
# cleanup for next run
assert_script_run "rm -rf localhost.pem localhost.key nssdb";
}

sub ensure_gnutls_is_working {
# generate a CA, and a server certificate
my $ca_key_file = 'x509-ca-key.pem';
Expand Down

0 comments on commit 5553980

Please sign in to comment.