CertificateVerify.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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::CertificateVerify;
  9. use vars '@ISA';
  10. push @ISA, 'TLSProxy::Message';
  11. sub new
  12. {
  13. my $class = shift;
  14. my ($isdtls,
  15. $server,
  16. $msgseq,
  17. $msgfrag,
  18. $msgfragoffs,
  19. $data,
  20. $records,
  21. $startoffset,
  22. $message_frag_lens) = @_;
  23. my $self = $class->SUPER::new(
  24. $isdtls,
  25. $server,
  26. TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  27. $msgseq,
  28. $msgfrag,
  29. $msgfragoffs,
  30. $data,
  31. $records,
  32. $startoffset,
  33. $message_frag_lens);
  34. $self->{sigalg} = -1;
  35. $self->{signature} = "";
  36. return $self;
  37. }
  38. sub parse
  39. {
  40. my $self = shift;
  41. my $sigalg = -1;
  42. my $remdata = $self->data;
  43. my $record = ${$self->records}[0];
  44. if (TLSProxy::Proxy->is_tls13()
  45. || $record->version() == TLSProxy::Record::VERS_TLS_1_2
  46. || $record->version() == TLSProxy::Record::VERS_DTLS_1_2) {
  47. $sigalg = unpack('n', $remdata);
  48. $remdata = substr($remdata, 2);
  49. }
  50. my $siglen = unpack('n', substr($remdata, 0, 2));
  51. my $sig = substr($remdata, 2);
  52. die "Invalid CertificateVerify signature length" if length($sig) != $siglen;
  53. print " SigAlg:".$sigalg."\n";
  54. print " Signature Len:".$siglen."\n";
  55. $self->sigalg($sigalg);
  56. $self->signature($sig);
  57. }
  58. #Reconstruct the on-the-wire message data following changes
  59. sub set_message_contents
  60. {
  61. my $self = shift;
  62. my $data = "";
  63. my $sig = $self->signature();
  64. my $olddata = $self->data();
  65. $data .= pack("n", $self->sigalg()) if ($self->sigalg() != -1);
  66. $data .= pack("n", length($sig));
  67. $data .= $sig;
  68. $self->data($data);
  69. }
  70. #Read/write accessors
  71. sub sigalg
  72. {
  73. my $self = shift;
  74. if (@_) {
  75. $self->{sigalg} = shift;
  76. }
  77. return $self->{sigalg};
  78. }
  79. sub signature
  80. {
  81. my $self = shift;
  82. if (@_) {
  83. $self->{signature} = shift;
  84. }
  85. return $self->{signature};
  86. }
  87. 1;