xref: /freebsd-src/crypto/openssl/util/perl/TLSProxy/NewSessionTicket.pm (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
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::NewSessionTicket;
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_NEW_SESSION_TICKET,
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->{ticket_lifetime_hint} = 0;
33*e0c4386eSCy Schubert    $self->{ticket} = "";
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 $ticket_lifetime_hint = unpack('N', $self->data);
43*e0c4386eSCy Schubert    my $ticket_len = unpack('n', $self->data);
44*e0c4386eSCy Schubert    my $ticket = substr($self->data, 6, $ticket_len);
45*e0c4386eSCy Schubert
46*e0c4386eSCy Schubert    $self->ticket_lifetime_hint($ticket_lifetime_hint);
47*e0c4386eSCy Schubert    $self->ticket($ticket);
48*e0c4386eSCy Schubert}
49*e0c4386eSCy Schubert
50*e0c4386eSCy Schubert
51*e0c4386eSCy Schubert#Reconstruct the on-the-wire message data following changes
52*e0c4386eSCy Schubertsub set_message_contents
53*e0c4386eSCy Schubert{
54*e0c4386eSCy Schubert    my $self = shift;
55*e0c4386eSCy Schubert    my $data;
56*e0c4386eSCy Schubert
57*e0c4386eSCy Schubert    $data = pack('N', $self->ticket_lifetime_hint);
58*e0c4386eSCy Schubert    $data .= pack('n', length($self->ticket));
59*e0c4386eSCy Schubert    $data .= $self->ticket;
60*e0c4386eSCy Schubert
61*e0c4386eSCy Schubert    $self->data($data);
62*e0c4386eSCy Schubert}
63*e0c4386eSCy Schubert
64*e0c4386eSCy Schubert#Read/write accessors
65*e0c4386eSCy Schubertsub ticket_lifetime_hint
66*e0c4386eSCy Schubert{
67*e0c4386eSCy Schubert    my $self = shift;
68*e0c4386eSCy Schubert    if (@_) {
69*e0c4386eSCy Schubert      $self->{ticket_lifetime_hint} = shift;
70*e0c4386eSCy Schubert    }
71*e0c4386eSCy Schubert    return $self->{ticket_lifetime_hint};
72*e0c4386eSCy Schubert}
73*e0c4386eSCy Schubertsub ticket
74*e0c4386eSCy Schubert{
75*e0c4386eSCy Schubert    my $self = shift;
76*e0c4386eSCy Schubert    if (@_) {
77*e0c4386eSCy Schubert      $self->{ticket} = shift;
78*e0c4386eSCy Schubert    }
79*e0c4386eSCy Schubert    return $self->{ticket};
80*e0c4386eSCy Schubert}
81*e0c4386eSCy Schubert1;
82