NewSessionTicket.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Copyright 2016-2024 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_dtls
  12. {
  13. my $class = shift;
  14. my ($server,
  15. $msgseq,
  16. $msgfrag,
  17. $msgfragoffs,
  18. $data,
  19. $records,
  20. $startoffset,
  21. $message_frag_lens) = @_;
  22. return $class->init(
  23. 1,
  24. $server,
  25. $msgseq,
  26. $msgfrag,
  27. $msgfragoffs,
  28. $data,
  29. $records,
  30. $startoffset,
  31. $message_frag_lens
  32. )
  33. }
  34. sub new
  35. {
  36. my $class = shift;
  37. my ($server,
  38. $data,
  39. $records,
  40. $startoffset,
  41. $message_frag_lens) = @_;
  42. return $class->init(
  43. 0,
  44. $server,
  45. 0, # msgseq
  46. 0, # msgfrag
  47. 0, # $msgfragoffs
  48. $data,
  49. $records,
  50. $startoffset,
  51. $message_frag_lens
  52. )
  53. }
  54. sub init{
  55. my $class = shift;
  56. my ($isdtls,
  57. $server,
  58. $msgseq,
  59. $msgfrag,
  60. $msgfragoffs,
  61. $data,
  62. $records,
  63. $startoffset,
  64. $message_frag_lens) = @_;
  65. my $self = $class->SUPER::new(
  66. $isdtls,
  67. $server,
  68. TLSProxy::Message::MT_NEW_SESSION_TICKET,
  69. $msgseq,
  70. $msgfrag,
  71. $msgfragoffs,
  72. $data,
  73. $records,
  74. $startoffset,
  75. $message_frag_lens);
  76. $self->{ticket_lifetime_hint} = 0;
  77. $self->{ticket} = "";
  78. return $self;
  79. }
  80. sub parse
  81. {
  82. my $self = shift;
  83. my $ticket_lifetime_hint = unpack('N', $self->data);
  84. my $ticket_len = unpack('n', $self->data);
  85. my $ticket = substr($self->data, 6, $ticket_len);
  86. $self->ticket_lifetime_hint($ticket_lifetime_hint);
  87. $self->ticket($ticket);
  88. }
  89. #Reconstruct the on-the-wire message data following changes
  90. sub set_message_contents
  91. {
  92. my $self = shift;
  93. my $data;
  94. $data = pack('N', $self->ticket_lifetime_hint);
  95. $data .= pack('n', length($self->ticket));
  96. $data .= $self->ticket;
  97. $self->data($data);
  98. }
  99. #Read/write accessors
  100. sub ticket_lifetime_hint
  101. {
  102. my $self = shift;
  103. if (@_) {
  104. $self->{ticket_lifetime_hint} = shift;
  105. }
  106. return $self->{ticket_lifetime_hint};
  107. }
  108. sub ticket
  109. {
  110. my $self = shift;
  111. if (@_) {
  112. $self->{ticket} = shift;
  113. }
  114. return $self->{ticket};
  115. }
  116. 1;