HelloVerifyRequest.pm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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::HelloVerifyRequest;
  9. use TLSProxy::Record;
  10. use vars '@ISA';
  11. push @ISA, 'TLSProxy::Message';
  12. sub new
  13. {
  14. my $class = shift;
  15. my ($isdtls,
  16. $server,
  17. $msgseq,
  18. $msgfrag,
  19. $msgfragoffs,
  20. $data,
  21. $records,
  22. $startoffset,
  23. $message_frag_lens) = @_;
  24. my $self = $class->SUPER::new(
  25. $isdtls,
  26. $server,
  27. TLSProxy::Message::MT_HELLO_VERIFY_REQUEST,
  28. $msgseq,
  29. $msgfrag,
  30. $msgfragoffs,
  31. $data,
  32. $records,
  33. $startoffset,
  34. $message_frag_lens);
  35. $self->{server_version} = 0;
  36. $self->{cookie_len} = 0;
  37. $self->{cookie} = "";
  38. return $self;
  39. }
  40. sub parse
  41. {
  42. my $self = shift;
  43. my ($server_version) = unpack('n', $self->data);
  44. my $ptr = 2;
  45. my $cookie_len = unpack('C', substr($self->data, $ptr));
  46. $ptr++;
  47. my $cookie = substr($self->data, $ptr, $cookie_len);
  48. $self->server_version($server_version);
  49. $self->cookie_len($cookie_len);
  50. $self->cookie($cookie);
  51. $self->process_data();
  52. print " Server Version:".$TLSProxy::Record::tls_version{$server_version}."\n";
  53. print " Cookie Len:".$cookie_len."\n";
  54. }
  55. #Perform any actions necessary based on the data we've seen
  56. sub process_data
  57. {
  58. my $self = shift;
  59. #Intentional no-op
  60. }
  61. #Reconstruct the on-the-wire message data following changes
  62. sub set_message_contents
  63. {
  64. my $self = shift;
  65. my $data;
  66. $data = pack('n', $self->server_version);
  67. $data .= pack('C', $self->cookie_len);
  68. $data .= $self->cookie;
  69. $self->data($data);
  70. }
  71. #Read/write accessors
  72. sub server_version
  73. {
  74. my $self = shift;
  75. if (@_) {
  76. $self->{server_version} = shift;
  77. }
  78. return $self->{server_version};
  79. }
  80. sub cookie_len
  81. {
  82. my $self = shift;
  83. if (@_) {
  84. $self->{cookie_len} = shift;
  85. }
  86. return $self->{cookie_len};
  87. }
  88. sub cookie
  89. {
  90. my $self = shift;
  91. if (@_) {
  92. $self->{cookie} = shift;
  93. }
  94. return $self->{cookie};
  95. }
  96. 1;