#!/usr/bin/perl # (C) Sergey Kandaurov # (C) Aleksei Bavshin # (C) Nginx, Inc. # Tests for "ssl_provider" directive. ############################################################################### use warnings; use strict; use Test::More; BEGIN { use FindBin; chdir($FindBin::Bin); } use lib 'lib'; use Test::Nginx; ############################################################################### select STDERR; $| = 1; select STDOUT; $| = 1; plan(skip_all => 'win32') if $^O eq 'MSWin32'; plan(skip_all => 'may not work, incompatible with sanitizers') unless $ENV{TEST_NGINX_UNSAFE}; my $t = Test::Nginx->new()->has(qw/http proxy http_ssl openssl:3.2.0/) ->has_daemon('openssl')->has_daemon('softhsm2-util'); my $libsofthsm2_path; my @so_paths = ( '/usr/lib/softhsm', # Debian-based '/usr/local/lib/softhsm', # FreeBSD '/opt/local/lib/softhsm', # MacPorts '/lib64', # RHEL-based split /:/, $ENV{TEST_NGINX_SOFTHSM} || '' ); for my $so_path (@so_paths) { $so_path .= '/libsofthsm2.so'; if (-e $so_path) { $libsofthsm2_path = $so_path; last; } }; plan(skip_all => "libsofthsm2.so not found") unless $libsofthsm2_path; $t->write_file_expand('nginx.conf', <write_file('openssl.conf', $openssl_conf); my $d = $t->testdir(); $t->write_file('softhsm2.conf', <>$d/openssl.out 2>&1"); system("openssl genrsa -out $d/$name.key 2048 " . ">>$d/openssl.out 2>&1") == 0 or die "Can't create private key: $!\n"; system("softhsm2-util --import $d/$name.key --id 00 --label nx_key_0 " . '--token NginxZero --pin 1234 ' . ">>$d/openssl.out 2>&1") == 0 or die "Can't import private key: $!\n"; system("openssl req -x509 -new -config $d/openssl.conf " . "-subj /CN=$name/ -out $d/$name.crt -text -passin pass:1234 " . '-key "pkcs11:token=NginxZero;object=nx_key_0" ' . ">>$d/openssl.out 2>&1") == 0 or plan(skip_all => "missing pkcs11-provider"); } $t->write_file('pin.txt', '1234'); $t->write_file('index.html', ''); $t->run()->plan(2); ############################################################################### like(http_get('/proxy'), qr/200 OK/, 'ssl provider keys'); like(http_get('/var'), qr/200 OK/, 'ssl_certificate with variable'); ###############################################################################