70-test_certtypeext.t 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #! /usr/bin/env perl
  2. # Copyright 2023 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 OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
  10. use OpenSSL::Test::Utils;
  11. use TLSProxy::Proxy;
  12. my $test_name = "test_certtypeext";
  13. setup($test_name);
  14. plan skip_all => "TLSProxy isn't usable on $^O"
  15. if $^O =~ /^(VMS)$/;
  16. plan skip_all => "$test_name needs the dynamic engine feature enabled"
  17. if disabled("engine") || disabled("dynamic-engine");
  18. plan skip_all => "$test_name needs the sock feature enabled"
  19. if disabled("sock");
  20. plan skip_all => "$test_name needs TLSv1.2 enabled"
  21. if disabled("tls1_2");
  22. my $proxy = TLSProxy::Proxy->new(
  23. \&certtype_filter,
  24. cmdstr(app(["openssl"]), display => 1),
  25. srctop_file("apps", "server.pem"),
  26. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  27. );
  28. use constant {
  29. SERVER_CERT_TYPE => 0,
  30. CLIENT_CERT_TYPE => 1,
  31. NO_CERT_TYPE => 2
  32. };
  33. my $testtype;
  34. # Test 1: Just do a verify without cert type
  35. $proxy->clear();
  36. $proxy->clientflags("-tls1_2 -cert ".srctop_file("apps", "server.pem"));
  37. $proxy->serverflags("-verify 4");
  38. $testtype = NO_CERT_TYPE;
  39. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  40. plan tests => 4;
  41. ok(TLSProxy::Message->success, "Simple verify");
  42. # Test 2: Set a bogus server cert type
  43. $proxy->clear();
  44. $proxy->serverflags("-enable_server_rpk");
  45. $testtype = SERVER_CERT_TYPE;
  46. $proxy->start();
  47. ok(TLSProxy::Message->fail, "Unsupported server cert type");
  48. # Test 3: Set a bogus client cert type
  49. $proxy->clear();
  50. $proxy->serverflags("-enable_client_rpk");
  51. $testtype = CLIENT_CERT_TYPE;
  52. $proxy->start();
  53. ok(TLSProxy::Message->success, "Unsupported client cert type, no verify");
  54. # Test 4: Set a bogus server cert type with verify
  55. $proxy->clear();
  56. $testtype = CLIENT_CERT_TYPE;
  57. $proxy->clientflags("-tls1_2 -cert ".srctop_file("apps", "server.pem"));
  58. $proxy->serverflags("-verify 4 -enable_client_rpk");
  59. $proxy->start();
  60. ok(TLSProxy::Message->fail, "Unsupported client cert type with verify");
  61. sub certtype_filter
  62. {
  63. my $proxy = shift;
  64. my $message;
  65. # We're only interested in the initial ClientHello
  66. return if $proxy->flight != 0;
  67. $message = ${$proxy->message_list}[0];
  68. # Add unsupported and bogus client and server cert type to the client hello.
  69. my $ct = pack "C5", 0x04, 0x01, 0x03, 0x55, 0x66;
  70. if ($testtype == CLIENT_CERT_TYPE) {
  71. print "SETTING CLIENT CERT TYPE\n";
  72. $message->set_extension(TLSProxy::Message::EXT_CLIENT_CERT_TYPE, $ct);
  73. }
  74. if ($testtype == SERVER_CERT_TYPE) {
  75. print "SETTING SERVER CERT TYPE\n";
  76. $message->set_extension(TLSProxy::Message::EXT_SERVER_CERT_TYPE, $ct);
  77. }
  78. $message->repack();
  79. }