1 # Written by Matt Caswell for the OpenSSL project.
2 # ====================================================================
3 # Copyright (c) 1998-2015 The OpenSSL Project. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
17 # 3. All advertising materials mentioning features or use of this
18 # software must display the following acknowledgment:
19 # "This product includes software developed by the OpenSSL Project
20 # for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 # endorse or promote products derived from this software without
24 # prior written permission. For written permission, please contact
25 # openssl-core@openssl.org.
27 # 5. Products derived from this software may not be called "OpenSSL"
28 # nor may "OpenSSL" appear in their names without prior written
29 # permission of the OpenSSL Project.
31 # 6. Redistributions of any form whatsoever must retain the following
33 # "This product includes software developed by the OpenSSL Project
34 # for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 # OF THE POSSIBILITY OF SUCH DAMAGE.
48 # ====================================================================
50 # This product includes cryptographic software written by Eric Young
51 # (eay@cryptsoft.com). This product includes software written by Tim
52 # Hudson (tjh@cryptsoft.com).
56 package TLSProxy::ClientHello;
58 use parent 'TLSProxy::Message';
61 EXT_ENCRYPT_THEN_MAC => 22
71 $message_frag_lens) = @_;
73 my $self = $class->SUPER::new(
81 $self->{client_version} = 0;
83 $self->{session_id_len} = 0;
84 $self->{session} = "";
85 $self->{ciphersuite_len} = 0;
86 $self->{ciphersuites} = [];
87 $self->{comp_meth_len} = 0;
88 $self->{comp_meths} = [];
89 $self->{extensions_len} = 0;
90 $self->{extensions_data} = "";
99 my ($client_version) = unpack('n', $self->data);
100 my $random = substr($self->data, $ptr, 32);
102 my $session_id_len = unpack('C', substr($self->data, $ptr));
104 my $session = substr($self->data, $ptr, $session_id_len);
105 $ptr += $session_id_len;
106 my $ciphersuite_len = unpack('n', substr($self->data, $ptr));
108 my @ciphersuites = unpack('n*', substr($self->data, $ptr,
110 $ptr += $ciphersuite_len;
111 my $comp_meth_len = unpack('C', substr($self->data, $ptr));
113 my @comp_meths = unpack('C*', substr($self->data, $ptr, $comp_meth_len));
114 $ptr += $comp_meth_len;
115 my $extensions_len = unpack('n', substr($self->data, $ptr));
117 #For now we just deal with this as a block of data. In the future we will
119 my $extension_data = substr($self->data, $ptr);
121 if (length($extension_data) != $extensions_len) {
122 die "Invalid extension length\n";
125 while (length($extension_data) >= 4) {
126 my ($type, $size) = unpack("nn", $extension_data);
127 my $extdata = substr($extension_data, 4, $size);
128 $extension_data = substr($extension_data, 4 + $size);
129 $extensions{$type} = $extdata;
132 $self->client_version($client_version);
133 $self->random($random);
134 $self->session_id_len($session_id_len);
135 $self->session($session);
136 $self->ciphersuite_len($ciphersuite_len);
137 $self->ciphersuites(\@ciphersuites);
138 $self->comp_meth_len($comp_meth_len);
139 $self->comp_meths(\@comp_meths);
140 $self->extensions_len($extensions_len);
141 $self->extension_data(\%extensions);
143 $self->process_extensions();
145 print " Client Version:".$client_version."\n";
146 print " Session ID Len:".$session_id_len."\n";
147 print " Ciphersuite len:".$ciphersuite_len."\n";
148 print " Compression Method Len:".$comp_meth_len."\n";
149 print " Extensions Len:".$extensions_len."\n";
152 #Perform any actions necessary based on the extensions we've seen
153 sub process_extensions
156 my %extensions = %{$self->extension_data};
158 #Clear any state from a previous run
159 TLSProxy::Record->etm(0);
161 if (exists $extensions{&EXT_ENCRYPT_THEN_MAC}) {
162 TLSProxy::Record->etm(1);
166 #Reconstruct the on-the-wire message data following changes
167 sub set_message_contents
172 $data = pack('n', $self->client_version);
173 $data .= $self->random;
174 $data .= pack('C', $self->session_id_len);
175 $data .= $self->session;
176 $data .= pack('n', $self->ciphersuite_len);
177 $data .= pack("n*", @{$self->ciphersuites});
178 $data .= pack('C', $self->comp_meth_len);
179 $data .= pack("C*", @{$self->comp_meths});
180 $data .= pack('n', $self->extensions_len);
181 foreach my $key (keys %{$self->extension_data}) {
182 my $extdata = ${$self->extension_data}{$key};
183 $data .= pack("n", $key);
184 $data .= pack("n", length($extdata));
191 #Read/write accessors
196 $self->{client_version} = shift;
198 return $self->{client_version};
204 $self->{random} = shift;
206 return $self->{random};
212 $self->{session_id_len} = shift;
214 return $self->{session_id_len};
220 $self->{session} = shift;
222 return $self->{session};
228 $self->{ciphersuite_len} = shift;
230 return $self->{ciphersuite_len};
236 $self->{ciphersuites} = shift;
238 return $self->{ciphersuites};
244 $self->{comp_meth_len} = shift;
246 return $self->{comp_meth_len};
252 $self->{comp_meths} = shift;
254 return $self->{comp_meths};
260 $self->{extensions_len} = shift;
262 return $self->{extensions_len};
268 $self->{extension_data} = shift;
270 return $self->{extension_data};