Fix some TLSProxy warnings
authorMatt Caswell <matt@openssl.org>
Tue, 15 Nov 2016 11:09:25 +0000 (11:09 +0000)
committerMatt Caswell <matt@openssl.org>
Wed, 23 Nov 2016 15:31:21 +0000 (15:31 +0000)
After the client processes the server's initial flight in TLS1.3 it may
respond with either an encrypted, or an unencrypted alert. We needed to
teach TLSProxy about this so that it didn't issue spurious warnings.

Reviewed-by: Rich Salz <rsalz@openssl.org>
util/TLSProxy/Proxy.pm
util/TLSProxy/Record.pm
util/TLSProxy/ServerHello.pm

index 16fd09463f896aa59c3a164e0f103f4e5623d877..be9f8f88a088ae4147a2f88965ab3b4d88c34493 100644 (file)
@@ -23,6 +23,8 @@ use TLSProxy::NewSessionTicket;
 my $have_IPv6 = 0;
 my $IP_factory;
 
+my $is_tls13 = 0;
+
 sub new
 {
     my $class = shift;
@@ -103,6 +105,7 @@ sub clearClient
     $self->{record_list} = [];
     $self->{message_list} = [];
     $self->{clientflags} = "";
+    $is_tls13 = 0;
 
     TLSProxy::Message->clear();
     TLSProxy::Record->clear();
@@ -503,5 +506,12 @@ sub fill_known_data
     }
     return $ret;
 }
-
+sub is_tls13
+{
+    my $class = shift;
+    if (@_) {
+      $is_tls13 = shift;
+    }
+    return $is_tls13;
+}
 1;
index 6d35f08bedb128c6b0d33e40fc3ffb8bc1b7c74f..7189035fb4afd15a6574236e99ee259617f2ed6c 100644 (file)
@@ -111,7 +111,7 @@ sub get_records
 
             if (($server && $server_encrypting)
                      || (!$server && $client_encrypting)) {
-                if ($version != VERS_TLS_1_3() && $etm) {
+                if (!TLSProxy::Proxy->is_tls13() && $etm) {
                     $record->decryptETM();
                 } else {
                     $record->decrypt();
@@ -229,7 +229,19 @@ sub decrypt()
     my $data = $self->data;
 
     #Throw away any IVs
-    if ($self->version >= VERS_TLS_1_3()) {
+    if (TLSProxy::Proxy->is_tls13()) {
+        #A TLS1.3 client, when processing the server's initial flight, could
+        #respond with either an encrypted or an unencrypted alert.
+        if ($self->content_type() == RT_ALERT) {
+            #TODO(TLS1.3): Eventually it is sufficient just to check the record
+            #content type. If an alert is encrypted it will have a record
+            #content type of application data. However we haven't done the
+            #record layer changes yet, so it's a bit more complicated. For now
+            #we will additionally check if the data length is 2 (1 byte for
+            #alert level, 1 byte for alert description). If it is, then this is
+            #an unecrypted alert, so don't try to decrypt
+            return $data if (length($data) == 2);
+        }
         #8 bytes for a GCM IV
         $data = substr($data, 8);
         $mactaglen = 16;
index 9d6ad385bbaf7929680dd77f3f1fc3555c71301c..a1bc7b3d484e7fa0540978a0f062ec92d20677f4 100644 (file)
@@ -98,6 +98,7 @@ sub parse
     if ($server_version == TLSProxy::Record::VERS_TLS_1_3_DRAFT) {
         TLSProxy::Record->server_encrypting(1);
         TLSProxy::Record->client_encrypting(1);
+        TLSProxy::Proxy->is_tls13(1);
     }
 
     print "    Server Version:".$server_version."\n";