OpenSSL 1.1.1-pre2
This commit is contained in:
+109
-54
@@ -11,8 +11,8 @@ use TLSProxy::Proxy;
|
||||
|
||||
package TLSProxy::Record;
|
||||
|
||||
my $server_ccs_seen = 0;
|
||||
my $client_ccs_seen = 0;
|
||||
my $server_encrypting = 0;
|
||||
my $client_encrypting = 0;
|
||||
my $etm = 0;
|
||||
|
||||
use constant TLS_RECORD_HEADER_LENGTH => 5;
|
||||
@@ -35,12 +35,14 @@ my %record_type = (
|
||||
);
|
||||
|
||||
use constant {
|
||||
VERS_TLS_1_3 => 772,
|
||||
VERS_TLS_1_2 => 771,
|
||||
VERS_TLS_1_1 => 770,
|
||||
VERS_TLS_1_0 => 769,
|
||||
VERS_SSL_3_0 => 768,
|
||||
VERS_SSL_LT_3_0 => 767
|
||||
VERS_TLS_1_4 => 0x0305,
|
||||
VERS_TLS_1_3_DRAFT => 0x7f17,
|
||||
VERS_TLS_1_3 => 0x0304,
|
||||
VERS_TLS_1_2 => 0x0303,
|
||||
VERS_TLS_1_1 => 0x0302,
|
||||
VERS_TLS_1_0 => 0x0301,
|
||||
VERS_SSL_3_0 => 0x0300,
|
||||
VERS_SSL_LT_3_0 => 0x02ff
|
||||
};
|
||||
|
||||
my %tls_version = (
|
||||
@@ -59,7 +61,6 @@ sub get_records
|
||||
my $server = shift;
|
||||
my $flight = shift;
|
||||
my $packet = shift;
|
||||
my $partial = "";
|
||||
my @record_list = ();
|
||||
my @message_list = ();
|
||||
my $data;
|
||||
@@ -78,10 +79,8 @@ sub get_records
|
||||
print " (client -> server)\n";
|
||||
}
|
||||
#Get the record header
|
||||
if (length($packet) < TLS_RECORD_HEADER_LENGTH
|
||||
|| length($packet) < 5 + unpack("n", substr($packet, 3, 2))) {
|
||||
if (length($packet) < TLS_RECORD_HEADER_LENGTH) {
|
||||
print "Partial data : ".length($packet)." bytes\n";
|
||||
$partial = $packet;
|
||||
$packet = "";
|
||||
} else {
|
||||
($content_type, $version, $len) = unpack('CnnC*', $packet);
|
||||
@@ -110,12 +109,20 @@ sub get_records
|
||||
substr($packet, TLS_RECORD_HEADER_LENGTH, $len_real)
|
||||
);
|
||||
|
||||
if (($server && $server_ccs_seen)
|
||||
|| (!$server && $client_ccs_seen)) {
|
||||
if ($etm) {
|
||||
$record->decryptETM();
|
||||
} else {
|
||||
$record->decrypt();
|
||||
if ($content_type != RT_CCS) {
|
||||
if (($server && $server_encrypting)
|
||||
|| (!$server && $client_encrypting)) {
|
||||
if (!TLSProxy::Proxy->is_tls13() && $etm) {
|
||||
$record->decryptETM();
|
||||
} else {
|
||||
$record->decrypt();
|
||||
}
|
||||
$record->encrypted(1);
|
||||
|
||||
if (TLSProxy::Proxy->is_tls13()) {
|
||||
print " Inner content type: "
|
||||
.$record_type{$record->content_type()}."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,31 +137,31 @@ sub get_records
|
||||
}
|
||||
}
|
||||
|
||||
return (\@record_list, \@message_list, $partial);
|
||||
return (\@record_list, \@message_list);
|
||||
}
|
||||
|
||||
sub clear
|
||||
{
|
||||
$server_ccs_seen = 0;
|
||||
$client_ccs_seen = 0;
|
||||
$server_encrypting = 0;
|
||||
$client_encrypting = 0;
|
||||
}
|
||||
|
||||
#Class level accessors
|
||||
sub server_ccs_seen
|
||||
sub server_encrypting
|
||||
{
|
||||
my $class = shift;
|
||||
if (@_) {
|
||||
$server_ccs_seen = shift;
|
||||
$server_encrypting = shift;
|
||||
}
|
||||
return $server_ccs_seen;
|
||||
return $server_encrypting;
|
||||
}
|
||||
sub client_ccs_seen
|
||||
sub client_encrypting
|
||||
{
|
||||
my $class = shift;
|
||||
if (@_) {
|
||||
$client_ccs_seen = shift;
|
||||
$client_encrypting= shift;
|
||||
}
|
||||
return $client_ccs_seen;
|
||||
return $client_encrypting;
|
||||
}
|
||||
#Enable/Disable Encrypt-then-MAC
|
||||
sub etm
|
||||
@@ -190,7 +197,8 @@ sub new
|
||||
data => $data,
|
||||
decrypt_data => $decrypt_data,
|
||||
orig_decrypt_data => $decrypt_data,
|
||||
sent => 0
|
||||
encrypted => 0,
|
||||
outer_content_type => RT_APPLICATION_DATA
|
||||
};
|
||||
|
||||
return bless $self, $class;
|
||||
@@ -227,22 +235,44 @@ sub decryptETM
|
||||
sub decrypt()
|
||||
{
|
||||
my ($self) = shift;
|
||||
|
||||
my $mactaglen = 20;
|
||||
my $data = $self->data;
|
||||
|
||||
if($self->version >= VERS_TLS_1_1()) {
|
||||
#TLS1.1+ has an explicit IV. Throw it away
|
||||
#Throw away any IVs
|
||||
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 unencrypted alert, so don't try to decrypt
|
||||
return $data if (length($data) == 2);
|
||||
}
|
||||
$mactaglen = 16;
|
||||
} elsif ($self->version >= VERS_TLS_1_1()) {
|
||||
#16 bytes for a standard IV
|
||||
$data = substr($data, 16);
|
||||
|
||||
#Find out what the padding byte is
|
||||
my $padval = unpack("C", substr($data, length($data) - 1));
|
||||
|
||||
#Throw away the padding
|
||||
$data = substr($data, 0, length($data) - ($padval + 1));
|
||||
}
|
||||
|
||||
#Find out what the padding byte is
|
||||
my $padval = unpack("C", substr($data, length($data) - 1));
|
||||
#Throw away the MAC or TAG
|
||||
$data = substr($data, 0, length($data) - $mactaglen);
|
||||
|
||||
#Throw away the padding
|
||||
$data = substr($data, 0, length($data) - ($padval + 1));
|
||||
|
||||
#Throw away the MAC (assumes MAC is 20 bytes for now. FIXME)
|
||||
$data = substr($data, 0, length($data) - 20);
|
||||
if (TLSProxy::Proxy->is_tls13()) {
|
||||
#Get the content type
|
||||
my $content_type = unpack("C", substr($data, length($data) - 1));
|
||||
$self->content_type($content_type);
|
||||
$data = substr($data, 0, length($data) - 1);
|
||||
}
|
||||
|
||||
$self->decrypt_data($data);
|
||||
$self->decrypt_len(length($data));
|
||||
@@ -254,17 +284,20 @@ sub decrypt()
|
||||
sub reconstruct_record
|
||||
{
|
||||
my $self = shift;
|
||||
my $server = shift;
|
||||
my $data;
|
||||
|
||||
if ($self->{sent}) {
|
||||
return "";
|
||||
}
|
||||
$self->{sent} = 1;
|
||||
|
||||
if ($self->sslv2) {
|
||||
$data = pack('n', $self->len | 0x8000);
|
||||
} else {
|
||||
$data = pack('Cnn', $self->content_type, $self->version, $self->len);
|
||||
if (TLSProxy::Proxy->is_tls13() && $self->encrypted) {
|
||||
$data = pack('Cnn', $self->outer_content_type, $self->version,
|
||||
$self->len);
|
||||
} else {
|
||||
$data = pack('Cnn', $self->content_type, $self->version,
|
||||
$self->len);
|
||||
}
|
||||
|
||||
}
|
||||
$data .= $self->data;
|
||||
|
||||
@@ -277,16 +310,6 @@ sub flight
|
||||
my $self = shift;
|
||||
return $self->{flight};
|
||||
}
|
||||
sub content_type
|
||||
{
|
||||
my $self = shift;
|
||||
return $self->{content_type};
|
||||
}
|
||||
sub version
|
||||
{
|
||||
my $self = shift;
|
||||
return $self->{version};
|
||||
}
|
||||
sub sslv2
|
||||
{
|
||||
my $self = shift;
|
||||
@@ -336,4 +359,36 @@ sub len
|
||||
}
|
||||
return $self->{len};
|
||||
}
|
||||
sub version
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{version} = shift;
|
||||
}
|
||||
return $self->{version};
|
||||
}
|
||||
sub content_type
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{content_type} = shift;
|
||||
}
|
||||
return $self->{content_type};
|
||||
}
|
||||
sub encrypted
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{encrypted} = shift;
|
||||
}
|
||||
return $self->{encrypted};
|
||||
}
|
||||
sub outer_content_type
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{outer_content_type} = shift;
|
||||
}
|
||||
return $self->{outer_content_type};
|
||||
}
|
||||
1;
|
||||
Reference in New Issue
Block a user