2
0

70-test_sslsignature.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2018 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_sslsignature";
  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 TLS enabled"
  21. if alldisabled(available_protocols("tls"));
  22. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  23. my $proxy = TLSProxy::Proxy->new(
  24. undef,
  25. cmdstr(app(["openssl"]), display => 1),
  26. srctop_file("apps", "server.pem"),
  27. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  28. );
  29. use constant {
  30. NO_CORRUPTION => 0,
  31. CORRUPT_SERVER_CERT_VERIFY => 1,
  32. CORRUPT_CLIENT_CERT_VERIFY => 2,
  33. CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE => 3,
  34. };
  35. $proxy->filter(\&signature_filter);
  36. #Test 1: No corruption should succeed
  37. my $testtype = NO_CORRUPTION;
  38. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  39. plan tests => 4;
  40. ok(TLSProxy::Message->success, "No corruption");
  41. SKIP: {
  42. skip "TLSv1.3 disabled", 1 if disabled("tls1_3");
  43. #Test 2: Corrupting a server CertVerify signature in TLSv1.3 should fail
  44. $proxy->clear();
  45. $testtype = CORRUPT_SERVER_CERT_VERIFY;
  46. $proxy->start();
  47. ok(TLSProxy::Message->fail, "Corrupt server TLSv1.3 CertVerify");
  48. #Test x: Corrupting a client CertVerify signature in TLSv1.3 should fail
  49. #$proxy->clear();
  50. #$testtype = CORRUPT_CLIENT_CERT_VERIFY;
  51. #$proxy->serverflags("-Verify 5");
  52. #$proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
  53. #$proxy->start();
  54. #ok(TLSProxy::Message->fail, "Corrupt client TLSv1.3 CertVerify");
  55. #TODO(TLS1.3): This test fails due to a problem in s_server/TLSProxy.
  56. #Currently a connection is counted as "successful" if the client ends it
  57. #with a close_notify. In TLSProxy the client initiates the closure of the
  58. #connection so really we should not count it as successful until s_server
  59. #has also responded with a close_notify. However s_server never sends a
  60. #close_notify - it just closes the connection. Fixing this would be a
  61. #significant change to the long established behaviour of s_server.
  62. #Unfortunately in this test, it is the server that notices the incorrect
  63. #signature and responds with an appropriate alert. However s_client never
  64. #sees that because it occurs after the server Finished has been sent.
  65. #Therefore s_client just continues to send its application data and sends
  66. #its close_notify regardless. TLSProxy sees this and thinks that the
  67. #connection was successful when in fact it was not. There isn't an easy fix
  68. #for this, so leaving this test commented out for now.
  69. }
  70. SKIP: {
  71. skip "TLS <= 1.2 disabled", 2
  72. if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2"));
  73. #Test 3: Corrupting a CertVerify signature in <=TLSv1.2 should fail
  74. $proxy->clear();
  75. $testtype = CORRUPT_CLIENT_CERT_VERIFY;
  76. $proxy->serverflags("-Verify 5");
  77. $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
  78. $proxy->start();
  79. ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 CertVerify");
  80. SKIP: {
  81. skip "DH disabled", 1 if disabled("dh");
  82. #Test 4: Corrupting a ServerKeyExchange signature in <=TLSv1.2 should
  83. #fail
  84. $proxy->clear();
  85. $testtype = CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE;
  86. $proxy->clientflags("-no_tls1_3");
  87. $proxy->cipherc('DHE-RSA-AES128-SHA');
  88. $proxy->ciphers('DHE-RSA-AES128-SHA');
  89. $proxy->start();
  90. ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 ServerKeyExchange");
  91. }
  92. }
  93. sub signature_filter
  94. {
  95. my $proxy = shift;
  96. my $flight;
  97. my $mt = TLSProxy::Message::MT_CERTIFICATE_VERIFY;
  98. if ($testtype == CORRUPT_SERVER_CERT_VERIFY
  99. || $testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE
  100. || (!disabled("tls1_3") && $testtype == NO_CORRUPTION)) {
  101. $flight = 1;
  102. } else {
  103. $flight = 2;
  104. }
  105. # We're only interested in the initial server flight
  106. return if ($proxy->flight != $flight);
  107. $mt = TLSProxy::Message::MT_SERVER_KEY_EXCHANGE
  108. if ($testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE);
  109. foreach my $message (@{$proxy->message_list}) {
  110. if ($message->mt == $mt) {
  111. my $sig = $message->signature();
  112. my $sigbase = substr($sig, 0, -1);
  113. my $sigend = unpack("C", substr($sig, -1));
  114. #Flip bits in final byte of signature to corrupt the sig
  115. $sigend ^= 0xff unless $testtype == NO_CORRUPTION;
  116. $message->signature($sigbase.pack("C", $sigend));
  117. $message->repack();
  118. }
  119. }
  120. }