xref: /openbsd-src/regress/lib/libcrypto/x509/callback.pl (revision 8657d445586d25f617b087ef7ce0c4b2c5d06ea2)
1#!/usr/bin/perl
2#
3# Copyright (c) 2021 Bob Beck <beck@openbsd.org>
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
18# Validate that we call out with the same chain on the callback with the legacy
19# verifier as we do with the new verifier in compatibility mode. We ignore cases
20# where one of the tests does not succesd to find a chain, as the error paths
21# may be different. It's also ok for the new verifier to have signalled an
22# error before finding a chain since it may try something and then back up.
23
24my $Test;
25my $State = "Read";
26my @Legacy;
27my @Modern;
28my $Mfail;
29my @Lfail;
30my $Failures = "";
31
32while (<>) {
33    chomp;
34    print "$_\n";
35    if ($State eq "Read") {
36	if (/^== Test/) {
37	    $Test = $_;
38	    @Legacy = ();
39	    @Modern = ();
40	    $Mfail = 0;
41	    $Lfail = 0;
42	    $State = "Read";
43	    next;
44	}
45	if (/^== Legacy/) {
46	    $State = "Legacy";
47	    next;
48	}
49	if (/^== Modern/) {
50	    $State = "Modern";
51	    next;
52	}
53    }
54    if ($State eq "Legacy") {
55	if (/^INFO/) {
56	    $State = "Read";
57	    next;
58	}
59	if (/^FAIL/) {
60	    $Lfail = 1;
61	    $State = "Read";
62	    next;
63	}
64	push @Legacy, ($_);
65    }
66    if ($State eq "Modern") {
67	if (/^INFO/) {
68	    $State = "Process";
69	    next;
70	}
71	if (/^FAIL/) {
72	    $Mfail = 1;
73	    $State = "Process";
74	    next;
75	}
76	push @Modern, ($_);
77    }
78    if ($State eq "Process") {
79	my $mlen = scalar(@Modern);
80	my $llen = scalar(@Legacy);
81	print "$Test has $llen legacy lines and $mlen modern lines\n";
82	while ($mlen > 0 && $llen > 0) {
83	    my $lline = $Legacy[$llen - 1];
84	    my $mline = $Modern[$mlen - 1];
85
86	    if (!@Mfail && !$Lfail && $mline =~ /error 0 cert/ &&  $lline =~ /error 0 cert/) {
87		if ($lline ne $mline) {
88		    print "MISMATCH:  $lline VS $mline\n";
89		    $Failures .= "$Test ";
90		}
91	    }
92	    $mlen--;
93	    $llen--;
94	}
95	$State = "Read";
96	next;
97    }
98}
99print "=============Test Summary============\n";
100if ($Failures ne "") {
101    print "FAIL: Mismatech on $Failures\n";
102    exit 1;
103}
104print "Success: No Mismatches\n";
105exit 0;
106