1*e0c4386eSCy Schubert# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. 2*e0c4386eSCy Schubert# 3*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License"). You may not use 4*e0c4386eSCy Schubert# this file except in compliance with the License. You can obtain a copy 5*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at 6*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html 7*e0c4386eSCy Schubert 8*e0c4386eSCy Schubertuse strict; 9*e0c4386eSCy Schubert 10*e0c4386eSCy Schubertpackage TLSProxy::CertificateVerify; 11*e0c4386eSCy Schubert 12*e0c4386eSCy Schubertuse vars '@ISA'; 13*e0c4386eSCy Schubertpush @ISA, 'TLSProxy::Message'; 14*e0c4386eSCy Schubert 15*e0c4386eSCy Schubertsub new 16*e0c4386eSCy Schubert{ 17*e0c4386eSCy Schubert my $class = shift; 18*e0c4386eSCy Schubert my ($server, 19*e0c4386eSCy Schubert $data, 20*e0c4386eSCy Schubert $records, 21*e0c4386eSCy Schubert $startoffset, 22*e0c4386eSCy Schubert $message_frag_lens) = @_; 23*e0c4386eSCy Schubert 24*e0c4386eSCy Schubert my $self = $class->SUPER::new( 25*e0c4386eSCy Schubert $server, 26*e0c4386eSCy Schubert TLSProxy::Message::MT_CERTIFICATE_VERIFY, 27*e0c4386eSCy Schubert $data, 28*e0c4386eSCy Schubert $records, 29*e0c4386eSCy Schubert $startoffset, 30*e0c4386eSCy Schubert $message_frag_lens); 31*e0c4386eSCy Schubert 32*e0c4386eSCy Schubert $self->{sigalg} = -1; 33*e0c4386eSCy Schubert $self->{signature} = ""; 34*e0c4386eSCy Schubert 35*e0c4386eSCy Schubert return $self; 36*e0c4386eSCy Schubert} 37*e0c4386eSCy Schubert 38*e0c4386eSCy Schubertsub parse 39*e0c4386eSCy Schubert{ 40*e0c4386eSCy Schubert my $self = shift; 41*e0c4386eSCy Schubert 42*e0c4386eSCy Schubert my $sigalg = -1; 43*e0c4386eSCy Schubert my $remdata = $self->data; 44*e0c4386eSCy Schubert my $record = ${$self->records}[0]; 45*e0c4386eSCy Schubert 46*e0c4386eSCy Schubert if (TLSProxy::Proxy->is_tls13() 47*e0c4386eSCy Schubert || $record->version() == TLSProxy::Record::VERS_TLS_1_2) { 48*e0c4386eSCy Schubert $sigalg = unpack('n', $remdata); 49*e0c4386eSCy Schubert $remdata = substr($remdata, 2); 50*e0c4386eSCy Schubert } 51*e0c4386eSCy Schubert 52*e0c4386eSCy Schubert my $siglen = unpack('n', substr($remdata, 0, 2)); 53*e0c4386eSCy Schubert my $sig = substr($remdata, 2); 54*e0c4386eSCy Schubert 55*e0c4386eSCy Schubert die "Invalid CertificateVerify signature length" if length($sig) != $siglen; 56*e0c4386eSCy Schubert 57*e0c4386eSCy Schubert print " SigAlg:".$sigalg."\n"; 58*e0c4386eSCy Schubert print " Signature Len:".$siglen."\n"; 59*e0c4386eSCy Schubert 60*e0c4386eSCy Schubert $self->sigalg($sigalg); 61*e0c4386eSCy Schubert $self->signature($sig); 62*e0c4386eSCy Schubert} 63*e0c4386eSCy Schubert 64*e0c4386eSCy Schubert#Reconstruct the on-the-wire message data following changes 65*e0c4386eSCy Schubertsub set_message_contents 66*e0c4386eSCy Schubert{ 67*e0c4386eSCy Schubert my $self = shift; 68*e0c4386eSCy Schubert my $data = ""; 69*e0c4386eSCy Schubert my $sig = $self->signature(); 70*e0c4386eSCy Schubert my $olddata = $self->data(); 71*e0c4386eSCy Schubert 72*e0c4386eSCy Schubert $data .= pack("n", $self->sigalg()) if ($self->sigalg() != -1); 73*e0c4386eSCy Schubert $data .= pack("n", length($sig)); 74*e0c4386eSCy Schubert $data .= $sig; 75*e0c4386eSCy Schubert 76*e0c4386eSCy Schubert $self->data($data); 77*e0c4386eSCy Schubert} 78*e0c4386eSCy Schubert 79*e0c4386eSCy Schubert#Read/write accessors 80*e0c4386eSCy Schubertsub sigalg 81*e0c4386eSCy Schubert{ 82*e0c4386eSCy Schubert my $self = shift; 83*e0c4386eSCy Schubert if (@_) { 84*e0c4386eSCy Schubert $self->{sigalg} = shift; 85*e0c4386eSCy Schubert } 86*e0c4386eSCy Schubert return $self->{sigalg}; 87*e0c4386eSCy Schubert} 88*e0c4386eSCy Schubertsub signature 89*e0c4386eSCy Schubert{ 90*e0c4386eSCy Schubert my $self = shift; 91*e0c4386eSCy Schubert if (@_) { 92*e0c4386eSCy Schubert $self->{signature} = shift; 93*e0c4386eSCy Schubert } 94*e0c4386eSCy Schubert return $self->{signature}; 95*e0c4386eSCy Schubert} 96*e0c4386eSCy Schubert1; 97