[PATCH] Tests: improved compatibility when using recent "openssl" app
Maxim Dounin
mdounin at mdounin.ru
Thu May 2 16:54:51 UTC 2024
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1714668482 -10800
# Thu May 02 19:48:02 2024 +0300
# Node ID 2578fe6a2d9e6b3a6206d56f09e1aaeb9f740a17
# Parent fe6f22da53ec760f7ab138d1d32b7a03ea7bdea3
Tests: improved compatibility when using recent "openssl" app.
Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys
in PKCS#8 format instead of previously used PKCS#1 format. Further,
since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256.
Such keys are not supported by old SSL libraries, notably by OpenSSL
before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL
before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c),
and trying to load such keys into nginx compiled with an old SSL library
results in "unsupported prf" errors.
To facilitate testing with old SSL libraries, keys are now generated
with "openssl genrsa -traditional" if the flag is available.
diff --git a/grpc_ssl.t b/grpc_ssl.t
--- a/grpc_ssl.t
+++ b/grpc_ssl.t
@@ -103,6 +103,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('localhost') {
system('openssl req -x509 -new '
@@ -114,7 +115,7 @@ foreach my $name ('localhost') {
foreach my $name ('client') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/mail_ssl.t b/mail_ssl.t
--- a/mail_ssl.t
+++ b/mail_ssl.t
@@ -115,10 +115,11 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('localhost', 'inherits') {
system("openssl genrsa -out $d/$name.key -passout pass:localhost "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/proxy_ssl_certificate.t b/proxy_ssl_certificate.t
--- a/proxy_ssl_certificate.t
+++ b/proxy_ssl_certificate.t
@@ -107,6 +107,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -118,7 +119,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/proxy_ssl_certificate_vars.t b/proxy_ssl_certificate_vars.t
--- a/proxy_ssl_certificate_vars.t
+++ b/proxy_ssl_certificate_vars.t
@@ -106,6 +106,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -117,7 +118,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/ssl_certificate.t b/ssl_certificate.t
--- a/ssl_certificate.t
+++ b/ssl_certificate.t
@@ -125,6 +125,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('one', 'two') {
system('openssl req -x509 -new '
@@ -136,7 +137,7 @@ foreach my $name ('one', 'two') {
foreach my $name ('pass') {
system("openssl genrsa -out $d/$name.key -passout pass:pass "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create $name key: $!\n";
system("openssl req -x509 -new -config $d/openssl.conf "
. "-subj /CN=$name/ -out $d/$name.crt -key $d/$name.key "
diff --git a/ssl_password_file.t b/ssl_password_file.t
--- a/ssl_password_file.t
+++ b/ssl_password_file.t
@@ -94,11 +94,13 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
+
mkfifo("$d/password_fifo", 0700);
foreach my $name ('localhost', 'inherits') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/stream_proxy_ssl_certificate.t b/stream_proxy_ssl_certificate.t
--- a/stream_proxy_ssl_certificate.t
+++ b/stream_proxy_ssl_certificate.t
@@ -113,6 +113,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -124,7 +125,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/stream_proxy_ssl_certificate_vars.t b/stream_proxy_ssl_certificate_vars.t
--- a/stream_proxy_ssl_certificate_vars.t
+++ b/stream_proxy_ssl_certificate_vars.t
@@ -120,6 +120,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -131,7 +132,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/stream_ssl.t b/stream_ssl.t
--- a/stream_ssl.t
+++ b/stream_ssl.t
@@ -90,11 +90,13 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
+
mkfifo("$d/password_fifo", 0700);
foreach my $name ('localhost', 'inherits') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/stream_ssl_certificate.t b/stream_ssl_certificate.t
--- a/stream_ssl_certificate.t
+++ b/stream_ssl_certificate.t
@@ -108,6 +108,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('one', 'two') {
system('openssl req -x509 -new '
@@ -119,7 +120,7 @@ foreach my $name ('one', 'two') {
foreach my $name ('pass') {
system("openssl genrsa -out $d/$name.key -passout pass:pass "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create $name key: $!\n";
system("openssl req -x509 -new -config $d/openssl.conf "
. "-subj /CN=$name/ -out $d/$name.crt -key $d/$name.key "
diff --git a/uwsgi_ssl_certificate.t b/uwsgi_ssl_certificate.t
--- a/uwsgi_ssl_certificate.t
+++ b/uwsgi_ssl_certificate.t
@@ -105,6 +105,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -116,7 +117,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
diff --git a/uwsgi_ssl_certificate_vars.t b/uwsgi_ssl_certificate_vars.t
--- a/uwsgi_ssl_certificate_vars.t
+++ b/uwsgi_ssl_certificate_vars.t
@@ -104,6 +104,7 @@ distinguished_name = req_distinguished_n
EOF
my $d = $t->testdir();
+my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
foreach my $name ('1.example.com', '2.example.com') {
system('openssl req -x509 -new '
@@ -115,7 +116,7 @@ foreach my $name ('1.example.com', '2.ex
foreach my $name ('3.example.com') {
system("openssl genrsa -out $d/$name.key -passout pass:$name "
- . "-aes128 2048 >>$d/openssl.out 2>&1") == 0
+ . "-aes128 $tr 2048 >>$d/openssl.out 2>&1") == 0
or die "Can't create private key: $!\n";
system('openssl req -x509 -new '
. "-config $d/openssl.conf -subj /CN=$name/ "
More information about the nginx-devel
mailing list