Home | History | Annotate | Line # | Download | only in TLSProxy
      1 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License 2.0 (the "License").  You may not use
      4 # this file except in compliance with the License.  You can obtain a copy
      5 # in the file LICENSE in the source distribution or at
      6 # https://www.openssl.org/source/license.html
      7 
      8 use strict;
      9 
     10 package TLSProxy::NewSessionTicket;
     11 
     12 use vars '@ISA';
     13 push @ISA, 'TLSProxy::Message';
     14 
     15 sub new
     16 {
     17     my $class = shift;
     18     my ($server,
     19         $data,
     20         $records,
     21         $startoffset,
     22         $message_frag_lens) = @_;
     23 
     24     my $self = $class->SUPER::new(
     25         $server,
     26         TLSProxy::Message::MT_NEW_SESSION_TICKET,
     27         $data,
     28         $records,
     29         $startoffset,
     30         $message_frag_lens);
     31 
     32     $self->{ticket_lifetime_hint} = 0;
     33     $self->{ticket} = "";
     34 
     35     return $self;
     36 }
     37 
     38 sub parse
     39 {
     40     my $self = shift;
     41 
     42     my $ticket_lifetime_hint = unpack('N', $self->data);
     43     my $ticket_len = unpack('n', $self->data);
     44     my $ticket = substr($self->data, 6, $ticket_len);
     45 
     46     $self->ticket_lifetime_hint($ticket_lifetime_hint);
     47     $self->ticket($ticket);
     48 }
     49 
     50 
     51 #Reconstruct the on-the-wire message data following changes
     52 sub set_message_contents
     53 {
     54     my $self = shift;
     55     my $data;
     56 
     57     $data = pack('N', $self->ticket_lifetime_hint);
     58     $data .= pack('n', length($self->ticket));
     59     $data .= $self->ticket;
     60 
     61     $self->data($data);
     62 }
     63 
     64 #Read/write accessors
     65 sub ticket_lifetime_hint
     66 {
     67     my $self = shift;
     68     if (@_) {
     69       $self->{ticket_lifetime_hint} = shift;
     70     }
     71     return $self->{ticket_lifetime_hint};
     72 }
     73 sub ticket
     74 {
     75     my $self = shift;
     76     if (@_) {
     77       $self->{ticket} = shift;
     78     }
     79     return $self->{ticket};
     80 }
     81 1;
     82