TLSProxy/Record.pm: add is_fatal_alert method.
authorAndy Polyakov <appro@openssl.org>
Mon, 16 Apr 2018 12:08:35 +0000 (14:08 +0200)
committerAndy Polyakov <appro@openssl.org>
Wed, 18 Apr 2018 17:57:14 +0000 (19:57 +0200)
(resolve uninitialized variable warning and harmonize output).

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5975)

util/perl/TLSProxy/Record.pm

index 49a0084d36a83774bca3eceb4168b59f5e347abe..8ff948b82f17cdc1aca86d9b56fa4c120f099a40 100644 (file)
@@ -67,17 +67,13 @@ sub get_records
 
     my $recnum = 1;
     while (length ($packet) > 0) {
-        print " Record $recnum";
-        if ($server) {
-            print " (server -> client)\n";
-        } else {
-            print " (client -> server)\n";
-        }
+        print " Record $recnum ", $server ? "(server -> client)\n"
+                                          : "(client -> server)\n";
 
         #Get the record header (unpack can't fail if $packet is too short)
         my ($content_type, $version, $len) = unpack('Cnn', $packet);
 
-        if (length($packet) < TLS_RECORD_HEADER_LENGTH + $len) {
+        if (length($packet) < TLS_RECORD_HEADER_LENGTH + ($len // 0)) {
             print "Partial data : ".length($packet)." bytes\n";
             $partial = $packet;
             last;
@@ -389,4 +385,16 @@ sub outer_content_type
     }
     return $self->{outer_content_type};
 }
+sub is_fatal_alert
+{
+    my $self = shift;
+    my $server = shift;
+
+    if (($self->{flight} & 1) == $server
+        && $self->{content_type} == TLSProxy::Record::RT_ALERT) {
+        my ($level, $alert) = unpack('CC', $self->decrypt_data);
+        return $alert if ($level == 2);
+    }
+    return 0;
+}
 1;