Skip to content

Commit a5e6efa

Browse files
committed
Tests: adjusted ssl_engine_keys.t to run on Linux and macOS.
Previously, library paths were hardcoded to FreeBSD. Further, a new TEST_NGINX_SOFTHSM environment variable is used to append the softhsm search path as needed. Also, the "dynamic_path" command appears to be required on FreeBSD only, where OpenSSL looks for the pkcs11 engine in a path different from where it is installed. Based on a patch by Oksana Deeva.
1 parent 8c799c5 commit a5e6efa

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

ssl_engine_keys.t

+29-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ plan(skip_all => 'may not work, leaves coredump')
2828
unless $ENV{TEST_NGINX_UNSAFE};
2929

3030
my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl')
31-
->has_daemon('softhsm2-util')->has_daemon('pkcs11-tool')->plan(2);
31+
->has_daemon('softhsm2-util')->has_daemon('pkcs11-tool');
3232

3333
$t->write_file_expand('nginx.conf', <<'EOF');
3434
@@ -86,10 +86,29 @@ EOF
8686
#
8787
# http://mailman.nginx.org/pipermail/nginx-devel/2014-October/006151.html
8888
#
89-
# Note that library paths may differ on different systems,
89+
# Note that library paths vary on different systems,
9090
# and may need to be adjusted.
9191

92-
$t->write_file('openssl.conf', <<EOF);
92+
my $libsofthsm2_path;
93+
my @so_paths = (
94+
'/usr/lib/softhsm', # Debian-based
95+
'/usr/local/lib/softhsm', # FreeBSD
96+
'/opt/local/lib/softhsm', # MacPorts
97+
'/lib64', # RHEL-based
98+
split /:/, $ENV{TEST_NGINX_SOFTHSM} || ''
99+
);
100+
101+
for my $so_path (@so_paths) {
102+
$so_path .= '/libsofthsm2.so';
103+
if (-e $so_path) {
104+
$libsofthsm2_path = $so_path;
105+
last;
106+
}
107+
};
108+
109+
plan(skip_all => "libsofthsm2.so not found") unless $libsofthsm2_path;
110+
111+
my $openssl_conf = <<EOF;
93112
openssl_conf = openssl_def
94113
95114
[openssl_def]
@@ -101,7 +120,7 @@ pkcs11 = pkcs11_section
101120
[pkcs11_section]
102121
engine_id = pkcs11
103122
dynamic_path = /usr/local/lib/engines/pkcs11.so
104-
MODULE_PATH = /usr/local/lib/softhsm/libsofthsm2.so
123+
MODULE_PATH = $libsofthsm2_path
105124
init = 1
106125
PIN = 1234
107126
@@ -112,6 +131,9 @@ distinguished_name = req_distinguished_name
112131
[ req_distinguished_name ]
113132
EOF
114133

134+
$openssl_conf =~ s|^(?=dynamic_path)|# |m if $^O ne 'freebsd';
135+
$t->write_file('openssl.conf', $openssl_conf);
136+
115137
my $d = $t->testdir();
116138

117139
$t->write_file('softhsm2.conf', <<EOF);
@@ -129,18 +151,18 @@ foreach my $name ('localhost') {
129151
. '--pin 1234 --so-pin 1234 '
130152
. ">>$d/openssl.out 2>&1");
131153

132-
system('pkcs11-tool --module=/usr/local/lib/softhsm/libsofthsm2.so '
154+
system("pkcs11-tool --module=$libsofthsm2_path "
133155
. '-p 1234 -l -k -d 0 -a nx_key_0 --key-type rsa:2048 '
134156
. ">>$d/openssl.out 2>&1");
135157

136158
system('openssl req -x509 -new '
137159
. "-subj /CN=$name/ -out $d/$name.crt -text "
138160
. "-engine pkcs11 -keyform engine -key id_00 "
139161
. ">>$d/openssl.out 2>&1") == 0
140-
or die "Can't create certificate for $name: $!\n";
162+
or plan(skip_all => "missing engine");
141163
}
142164

143-
$t->run();
165+
$t->run()->plan(2);
144166

145167
$t->write_file('index.html', '');
146168

0 commit comments

Comments
 (0)