82-test_tfo_cli.t 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #! /usr/bin/env perl
  2. # Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use warnings;
  10. use IPC::Open2;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_tfo");
  14. plan skip_all => "test_tfo_cli needs tfo enabled" if disabled("tfo");
  15. plan skip_all => "test_tfo_cli needs sock enabled" if disabled("sock");
  16. plan skip_all => "test_tfo_cli needs tls < 1.3 enabled"
  17. if disabled("tls1") && disabled("tls1_1") && disabled("tls1_2");
  18. plan skip_all => "test_tfo_cli does not run on Windows nor VMS"
  19. if $^O =~ /^(VMS|MSWin32|msys)$/;
  20. plan tests => 8;
  21. my $shlib_wrap = bldtop_file("util", "shlib_wrap.sh");
  22. my $apps_openssl = bldtop_file("apps", "openssl");
  23. my $cert = srctop_file("apps", "server.pem");
  24. sub run_test {
  25. my $tfo = shift;
  26. my $client_good = ! $tfo;
  27. my $server_good = ! $tfo;
  28. my $connect_good = 0;
  29. my $port = "0";
  30. # Not using TLSv1.3 allows the test to work with "no-ec"
  31. my @s_cmd = ("s_server", "-accept", ":0", "-cert", $cert, "-www", "-no_tls1_3", "-naccept", "1");
  32. push @s_cmd, "-tfo" if ($tfo);
  33. my $spid = open2(my $sout, my $sin, $shlib_wrap, $apps_openssl, @s_cmd);
  34. # Read until we get the port, TFO is output before the ACCEPT line
  35. while (<$sout>) {
  36. chomp;
  37. $server_good = $tfo if /^Listening for TFO$/;
  38. if (/^ACCEPT\s.*:(\d+)$/) {
  39. $port = $1;
  40. last;
  41. }
  42. }
  43. print STDERR "Port: $port\n";
  44. print STDERR "Invalid port\n" if ! ok($port);
  45. # Start up the client
  46. my @c_cmd = ("s_client", "-connect", ":$port", "-no_tls1_3");
  47. push @c_cmd, "-tfo" if ($tfo);
  48. my $cpid = open2(my $cout, my $cin, $shlib_wrap, $apps_openssl, @c_cmd);
  49. # Do the "GET", which will cause the client to finish
  50. print $cin "GET /\r\n";
  51. waitpid($cpid, 0);
  52. waitpid($spid, 0);
  53. # Check the client output
  54. while (<$cout>) {
  55. chomp;
  56. $client_good = $tfo if /^Connecting via TFO$/;
  57. $connect_good = 1 if /^Content-type: text/;
  58. }
  59. print STDERR "Client TFO check failed\n" if ! ok($client_good);
  60. print STDERR "Server TFO check failed\n" if ! ok($server_good);
  61. print STDERR "Connection failed\n" if ! ok($connect_good);
  62. }
  63. for my $tfo (0..1) {
  64. SKIP:
  65. {
  66. skip "TFO not enabled", 4 if disabled("tfo") && $tfo;
  67. run_test($tfo);
  68. }
  69. }