NewSessionTicket.pm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. use strict;
  8. package TLSProxy::NewSessionTicket;
  9. use vars '@ISA';
  10. push @ISA, 'TLSProxy::Message';
  11. sub new
  12. {
  13. my $class = shift;
  14. my ($server,
  15. $data,
  16. $records,
  17. $startoffset,
  18. $message_frag_lens) = @_;
  19. my $self = $class->SUPER::new(
  20. $server,
  21. TLSProxy::Message::MT_NEW_SESSION_TICKET,
  22. $data,
  23. $records,
  24. $startoffset,
  25. $message_frag_lens);
  26. $self->{ticket_lifetime_hint} = 0;
  27. $self->{ticket} = "";
  28. return $self;
  29. }
  30. sub parse
  31. {
  32. my $self = shift;
  33. my $ticket_lifetime_hint = unpack('N', $self->data);
  34. my $ticket_len = unpack('n', $self->data);
  35. my $ticket = substr($self->data, 6, $ticket_len);
  36. $self->ticket_lifetime_hint($ticket_lifetime_hint);
  37. $self->ticket($ticket);
  38. }
  39. #Reconstruct the on-the-wire message data following changes
  40. sub set_message_contents
  41. {
  42. my $self = shift;
  43. my $data;
  44. $data = pack('N', $self->ticket_lifetime_hint);
  45. $data .= pack('n', length($self->ticket));
  46. $data .= $self->ticket;
  47. $self->data($data);
  48. }
  49. #Read/write accessors
  50. sub ticket_lifetime_hint
  51. {
  52. my $self = shift;
  53. if (@_) {
  54. $self->{ticket_lifetime_hint} = shift;
  55. }
  56. return $self->{ticket_lifetime_hint};
  57. }
  58. sub ticket
  59. {
  60. my $self = shift;
  61. if (@_) {
  62. $self->{ticket} = shift;
  63. }
  64. return $self->{ticket};
  65. }
  66. 1;