summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <>2021-02-16 21:39:17 +0000
committerjan <>2021-02-16 21:39:17 +0000
commiteae607b14c32520d0f00ba84ea11eab9af6f151c (patch)
tree376c45d2715913e4d706075a999dcb5067ec8d62
parent972d2a7aab0f7cf4db8798e6f47311550728f254 (diff)
downloadopenbsd-eae607b14c32520d0f00ba84ea11eab9af6f151c.tar.gz
openbsd-eae607b14c32520d0f00ba84ea11eab9af6f151c.tar.bz2
openbsd-eae607b14c32520d0f00ba84ea11eab9af6f151c.zip
Add x509 certificate validation regression tests
The validation tests are originaly createtd by Steffen Ullrich. OK tb@ No objection jsing@
-rw-r--r--src/regress/usr.bin/openssl/Makefile4
-rw-r--r--src/regress/usr.bin/openssl/x509/Makefile129
-rwxr-xr-xsrc/regress/usr.bin/openssl/x509/create-libressl-test-certs.pl111
3 files changed, 242 insertions, 2 deletions
diff --git a/src/regress/usr.bin/openssl/Makefile b/src/regress/usr.bin/openssl/Makefile
index 0ef7928ea4..d41b65a3f4 100644
--- a/src/regress/usr.bin/openssl/Makefile
+++ b/src/regress/usr.bin/openssl/Makefile
@@ -1,6 +1,6 @@
1# $OpenBSD: Makefile,v 1.6 2018/03/19 03:41:40 beck Exp $ 1# $OpenBSD: Makefile,v 1.7 2021/02/16 21:39:17 jan Exp $
2 2
3SUBDIR= options 3SUBDIR= options x509
4 4
5CLEANFILES+= testdsa.key testdsa.pem rsakey.pem rsacert.pem dsa512.pem 5CLEANFILES+= testdsa.key testdsa.pem rsakey.pem rsacert.pem dsa512.pem
6CLEANFILES+= appstest_dir 6CLEANFILES+= appstest_dir
diff --git a/src/regress/usr.bin/openssl/x509/Makefile b/src/regress/usr.bin/openssl/x509/Makefile
new file mode 100644
index 0000000000..b20cb1d9bd
--- /dev/null
+++ b/src/regress/usr.bin/openssl/x509/Makefile
@@ -0,0 +1,129 @@
1# $OpenBSD: Makefile,v 1.1 2021/02/16 21:39:17 jan Exp $
2
3# Copyright (c) 2021 Jan Klemkow <j.klemkow@wemelug.de>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17# This regression test is based on manual test descriptions from:
18# https://github.com/noxxi/libressl-tests
19
20# The following port must be installed for the regression tests:
21# p5-IO-Socket-SSL perl interface to SSL sockets
22
23PERL = perl
24OPENSSL ?= openssl
25
26PKG_REQUIRE != pkg_info -e 'p5-IO-Socket-SSL-*'
27.if empty (PKG_REQUIRE)
28regress:
29 @echo "missing package p5-IO-Socket-SSL"
30 @echo SKIPPED
31.endif
32
33REGRESS_TARGETS += test-inlabel-wildcard-cert-no-CA-client
34REGRESS_TARGETS += test-inlabel-wildcard-cert-CA-client
35REGRESS_TARGETS += test-common-wildcard-cert-no-CA-client
36REGRESS_TARGETS += test-common-wildcard-cert-CA-client
37REGRESS_TARGETS += test-verify-unusual-wildcard-cert
38REGRESS_TARGETS += test-openssl-verify-common-wildcard-cert
39REGRESS_TARGETS += test-chain-certificates-s_server
40REGRESS_TARGETS += test-alternative-chain
41REGRESS_CLEANUP = cleanup-ssl
42REGRESS_SETUP_ONCE = create-libressl-test-certs
43
44REGRESS_EXPECTED_FAILURES += test-unusual-wildcard-cert-no-CA-client
45REGRESS_EXPECTED_FAILURES += test-common-wildcard-cert-no-CA-client
46REGRESS_EXPECTED_FAILURES += test-common-wildcard-cert-CA-client
47REGRESS_EXPECTED_FAILURES += test-verify-unusual-wildcard-cert
48
49create-libressl-test-certs: create-libressl-test-certs.pl
50 ${PERL} ${.CURDIR}/$@.pl
51
52cleanup-ssl:
53 rm *.pem *.key
54
55test-inlabel-wildcard-cert-no-CA-client:
56 # unusual wildcard cert, no CA given to client
57 # start server
58 ${OPENSSL} s_server -cert server-unusual-wildcard.pem \
59 -key server-unusual-wildcard.pem & \
60 timeout=$$(($$(date +%s) + 5)); \
61 while fstat -p $$! | ! grep -q 'tcp .* \*:4433$$'; \
62 do test $$(date +%s) -lt $$timeout || exit 1; done
63 # start client
64 echo "Q" | ${OPENSSL} s_client -verify_return_error \
65 | grep "Verify return code: 21"
66
67test-inlabel-wildcard-cert-CA-client:
68 # unusual wildcard cert, CA given to client
69 # start server
70 ${OPENSSL} s_server -cert server-unusual-wildcard.pem \
71 -key server-unusual-wildcard.pem & \
72 timeout=$$(($$(date +%s) + 5)); \
73 while fstat -p $$! | ! grep -q 'tcp .* \*:4433$$'; \
74 do test $$(date +%s) -lt $$timeout || exit 1; done
75 # start client
76 echo "Q" | ${OPENSSL} s_client -CAfile caR.pem \
77 | grep "Verify return code: 0"
78
79test-common-wildcard-cert-no-CA-client:
80 # common wildcard cert, no CA given to client
81 # start server
82 ${OPENSSL} s_server -cert server-common-wildcard.pem \
83 -key server-common-wildcard.pem & \
84 timeout=$$(($$(date +%s) + 5)); \
85 while fstat -p $$! | ! grep -q 'tcp .* \*:4433$$'; \
86 do test $$(date +%s) -lt $$timeout || exit 1; done
87 # start client
88 echo "Q" | ${OPENSSL} s_client \
89 | grep "Verify return code: 21"
90
91test-common-wildcard-cert-CA-client:
92 # common wildcard cert, CA given to client
93 # start server
94 ${OPENSSL} s_server -cert server-unusual-wildcard.pem \
95 -key server-unusual-wildcard.pem & \
96 timeout=$$(($$(date +%s) + 5)); \
97 while fstat -p $$! | ! grep -q 'tcp .* \*:4433$$'; \
98 do test $$(date +%s) -lt $$timeout || exit 1; done
99 # start client
100 echo "Q" | ${OPENSSL} s_client -CAfile caR.pem \
101 | grep "Verify return code: 21"
102
103test-verify-unusual-wildcard-cert:
104 # openssl verify, unusual wildcard cert
105 ${OPENSSL} verify -CAfile caR.pem server-unusual-wildcard.pem \
106 | grep "server-unusual-wildcard.pem: OK"
107
108test-openssl-verify-common-wildcard-cert:
109 # openssl verify, common wildcard cert
110 ${OPENSSL} verify -CAfile caR.pem server-common-wildcard.pem \
111 | grep "server-common-wildcard.pem: OK"
112
113test-chain-certificates-s_server:
114 # Not all chain certificates are sent in s_server
115 # start server
116 # ${OPENSSL} s_server -cert server-subca.pem -CAfile subcaR.pem
117 ${OPENSSL} s_server -cert server-subca-chainS.pem -CAfile subcaR.pem & \
118 timeout=$$(($$(date +%s) + 5)); \
119 while fstat -p $$! | ! grep -q 'tcp .* \*:4433$$'; \
120 do test $$(date +%s) -lt $$timeout || exit 1; done
121 # start client
122 ${OPENSSL} s_client -CAfile caR.pem | grep "Verify return code: 0"
123
124test-alternative-chain:
125 # alternative chain not found
126 ${OPENSSL} verify -verbose -trusted caR.pem -untrusted chainSX.pem \
127 server-subca.pem | grep "server-subca.pem: OK"
128
129.include <bsd.regress.mk>
diff --git a/src/regress/usr.bin/openssl/x509/create-libressl-test-certs.pl b/src/regress/usr.bin/openssl/x509/create-libressl-test-certs.pl
new file mode 100755
index 0000000000..fdb718aadc
--- /dev/null
+++ b/src/regress/usr.bin/openssl/x509/create-libressl-test-certs.pl
@@ -0,0 +1,111 @@
1#!/usr/bin/perl
2
3# Copyright (c) 2021 Steffen Ullrich <sullr@cpan.org>
4# Public Domain
5
6use strict;
7use warnings;
8use IO::Socket::SSL::Utils;
9
10# primitive CA - ROOT
11my @ca = cert(
12 CA => 1,
13 subject => { CN => 'ROOT' }
14);
15out('caR.pem', pem(crt => $ca[0]));
16out('caR.key', pem(key => $ca[1]));
17
18# server certificate where SAN contains in-label wildcards, which a
19# client MAY choose to accept as per RFC 6125 section 6.4.3.
20my @leafcert = cert(
21 issuer => \@ca,
22 purpose => 'server',
23 subject => { CN => 'server.local' },
24 subjectAltNames => [
25 [ DNS => 'bar.server.local' ],
26 [ DNS => 'www*.server.local'],
27 [ DNS => '*.www.server.local'],
28 [ DNS => 'foo.server.local' ],
29 [ DNS => 'server.local' ],
30 ]
31);
32out('server-unusual-wildcard.pem', pem(@leafcert));
33
34@leafcert = cert(
35 issuer => \@ca,
36 purpose => 'server',
37 subject => { CN => 'server.local' },
38 subjectAltNames => [
39 [ DNS => 'bar.server.local' ],
40 [ DNS => '*.www.server.local'],
41 [ DNS => 'foo.server.local' ],
42 [ DNS => 'server.local' ],
43 ]
44);
45out('server-common-wildcard.pem', pem(@leafcert));
46
47# alternative CA - OLD_ROOT
48my @caO = cert(
49 CA => 1,
50 subject => { CN => 'OLD_ROOT' }
51);
52out('caO.pem', pem(crt => $caO[0]));
53out('caO.key', pem(key => $caO[1]));
54
55# alternative ROOT CA, signed by OLD_ROOT, same key as other ROOT CA
56my @caX = cert(
57 issuer => \@caO,
58 CA => 1,
59 subject => { CN => 'ROOT' },
60 key => $ca[1],
61);
62out('caX.pem', pem(crt => $caX[0]));
63out('caX.key', pem(key => $caX[1]));
64
65# subCA below ROOT
66my @subcaR = cert(
67 issuer => \@ca,
68 CA => 1,
69 subject => { CN => 'SubCA.of.ROOT' }
70);
71out('subcaR.pem', pem(crt => $subcaR[0]));
72out('subcaR.key', pem(key => $subcaR[1]));
73out('chainSX.pem', pem($subcaR[0]), pem($caX[0]));
74
75@leafcert = cert(
76 issuer => \@subcaR,
77 purpose => 'server',
78 subject => { CN => 'server.subca.local' },
79 subjectAltNames => [
80 [ DNS => 'server.subca.local' ],
81 ]
82);
83out('server-subca.pem', pem(@leafcert));
84out('server-subca-chainSX.pem', pem(@leafcert, $subcaR[0], $caX[0]));
85out('server-subca-chainS.pem', pem(@leafcert, $subcaR[0]));
86
87
88sub cert { CERT_create(not_after => 10*365*86400+time(), @_) }
89sub pem {
90 my @default = qw(crt key);
91 my %m = (key => \&PEM_key2string, crt => \&PEM_cert2string);
92 my $result = '';
93 while (my $f = shift(@_)) {
94 my $v;
95 if ($f =~m{^(key|crt)$}) {
96 $v = shift(@_);
97 } else {
98 $v = $f;
99 $f = shift(@default) || 'crt';
100 }
101 $f = $m{$f} || die "wrong key $f";
102 $result .= $f->($v);
103 }
104 return $result;
105}
106
107sub out {
108 my $file = shift;
109 open(my $fh,'>',"$file") or die "failed to create $file: $!";
110 print $fh @_
111}