@@ -11,7 +11,7 @@ BEGIN {
1111 } elsif (not can_fork()) {
1212 plan skip_all => " fork() not supported on this system" ;
1313 } else {
14- plan tests => 16 ;
14+ plan tests => 19 ;
1515 }
1616}
1717
@@ -25,6 +25,19 @@ my $key_pem = data_file_path('simple-cert.key.pem');
2525
2626my $cb_test_arg = [1, ' string for hello cb test arg' ];
2727
28+ # As of 2023-08, even the latest in-development OpenSSL allows
29+ # connections with SSLv2 ClientHello. Tested with OpenSSL 0.9.8f as
30+ # client and OpenSSL 3.2.0-dev from git master branch as
31+ # server. Trigger alert 42 as a marker.
32+ sub client_hello_cb_v2hello_detection
33+ {
34+ my ($ssl , $arg ) = @_ ;
35+
36+ is(Net::SSLeay::client_hello_isv2($ssl ), 1, ' SSLv2 ClientHello' );
37+ my $al = Net::SSLeay::AD_BAD_CERTIFICATE();
38+ return (Net::SSLeay::CLIENT_HELLO_ERROR(), $al );
39+ }
40+
2841# See that the exact same reference with unchanged contents are made
2942# available for the callback. Allow handshake to proceed.
3043sub client_hello_cb_value_passing
@@ -86,6 +99,7 @@ my @cb_tests = (
8699 # argument passed to the callback
87100 # true if the callback function triggers croak()
88101 # true if the client needs to test that ALPN alert (120) is received
102+ [ \&client_hello_cb_v2hello_detection, undef , 0 ],
89103 [ \&client_hello_cb_value_passing, \$cb_test_arg , 0 ],
90104 [ \&client_hello_cb_alert_alpn, undef , 0, ' alerts' ],
91105 [ \&client_hello_cb_alert_alpn, undef , 0, ' alerts' ], # Call again to increase alert counter
@@ -147,6 +161,7 @@ my @results;
147161}
148162
149163{
164+ # SSL client
150165 my $alpn_alert_count = 0;
151166
152167 # Use info callback to count TLS alert 120 occurences (ALPN alert).
@@ -158,7 +173,21 @@ my @results;
158173 }
159174 };
160175
161- # SSL client
176+ # Start with SSLv2 ClientHello detection test. Send a canned SSLv2
177+ # ClientHello.
178+ {
179+ my $s_clientv2 = $server -> connect ();
180+ my $clientv2_hello = get_sslv2_hello();
181+ syswrite ($s_clientv2 , $clientv2_hello , length $clientv2_hello );
182+ sysread ($s_clientv2 , my $buf , 16384);
183+
184+ # Alert (15), version (0303|4), length (0002), level fatal (02), bad cert(2a)
185+ push @results , [unpack (' H*' , $buf ) =~ m / ^15030.0002022a\z / , ' Alert from SSLv2 ClientHello' ];
186+ close ($s_clientv2 ) || die (" s_clientv2 close" );
187+ shift @cb_tests ;
188+ }
189+
190+ # The rest of tests use client's TLS stack
162191 foreach my $cb_test (@cb_tests ) {
163192 my $s_c = $server -> connect ();
164193
@@ -187,6 +216,30 @@ my @results;
187216waitpid $pid , 0;
188217push @results , [$? == 0, ' server exited with 0' ];
189218END {
190- Test::More-> builder-> current_test(14 );
219+ Test::More-> builder-> current_test(16 );
191220 ok( $_ -> [0], $_ -> [1] ) for (@results );
192221}
222+
223+ # Use a canned SSLv2 ClientHello for testing OpenSSL's
224+ # SSL_client_hello_isv2()
225+ sub get_sslv2_hello
226+ {
227+ # Captures with OpenSSL 0.9.8f. The second capture uses TLSv1.0 as
228+ # Version but still includes a number of SSLv2 ciphersuites.
229+ #
230+ # openssl s_client -connect 127.0.0.1:443 -ssl2
231+ # openssl s_client -connect 127.0.0.1:443
232+ my $sslv2_sslv2_hex_f = ' 802e0100020015000000100700c00500800300800100800600400400800200808f11701ccdc4eab421b6d03e4942ea98' ;
233+ my $sslv2_tlsv1_hex_f = ' 807a01030100510000002000003900003800003500001600001300000a0700c000003300003200002f0000070500800300800000050000040100800000150000120000090600400000140000110000080000060400800000030200807f0913623fe5e84de01bc7733ae8fcdcefda1ef60a4c960ac7251f6560841566' ;
234+
235+ # Captures with OpenSSL 0.9.8zh.
236+ #
237+ # The first capture is similar to 0.9.8f but the ciphersuites are
238+ # now ordered with the strongest first.The second capture uses
239+ # TLSv1.0 as Version but compared to 0.9.8f has a more modern set
240+ # of ciphers and includes TLS_EMPTY_RENEGOTIATION_INFO_SCSV.
241+ my $sslv2_sslv2_hex_zh = ' 802e0100020015000000100700c006004005008004008003008002008001008015c9eb78cbf9702542ac2d4c46b6101a' ;
242+ my $sslv2_tlsv1_hex_zh = ' 805901030100300000002000003900003800003500001600001300000a00003300003200002f0000070000050000040000150000120000090000ff1f90dda05ec4a857523dcc0ae06c461a99c36ce647a84aa64061c054333376b9' ;
243+
244+ return pack (' H*' , $sslv2_tlsv1_hex_zh );
245+ }
0 commit comments