CertificateRequest.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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::CertificateRequest;
  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_CERTIFICATE_REQUEST,
  22. $data,
  23. $records,
  24. $startoffset,
  25. $message_frag_lens);
  26. $self->{extension_data} = "";
  27. return $self;
  28. }
  29. sub parse
  30. {
  31. my $self = shift;
  32. my $ptr = 1;
  33. if (TLSProxy::Proxy->is_tls13()) {
  34. my $request_ctx_len = unpack('C', $self->data);
  35. my $request_ctx = substr($self->data, $ptr, $request_ctx_len);
  36. $ptr += $request_ctx_len;
  37. my $extensions_len = unpack('n', substr($self->data, $ptr));
  38. $ptr += 2;
  39. my $extension_data = substr($self->data, $ptr);
  40. if (length($extension_data) != $extensions_len) {
  41. die "Invalid extension length\n";
  42. }
  43. my %extensions = ();
  44. while (length($extension_data) >= 4) {
  45. my ($type, $size) = unpack("nn", $extension_data);
  46. my $extdata = substr($extension_data, 4, $size);
  47. $extension_data = substr($extension_data, 4 + $size);
  48. $extensions{$type} = $extdata;
  49. }
  50. $self->extension_data(\%extensions);
  51. print " Extensions Len:".$extensions_len."\n";
  52. }
  53. # else parse TLSv1.2 version - we don't support that at the moment
  54. }
  55. #Reconstruct the on-the-wire message data following changes
  56. sub set_message_contents
  57. {
  58. my $self = shift;
  59. my $data;
  60. my $extensions = "";
  61. foreach my $key (keys %{$self->extension_data}) {
  62. my $extdata = ${$self->extension_data}{$key};
  63. $extensions .= pack("n", $key);
  64. $extensions .= pack("n", length($extdata));
  65. $extensions .= $extdata;
  66. }
  67. $data = pack('n', length($extensions));
  68. $data .= $extensions;
  69. $self->data($data);
  70. }
  71. #Read/write accessors
  72. sub extension_data
  73. {
  74. my $self = shift;
  75. if (@_) {
  76. $self->{extension_data} = shift;
  77. }
  78. return $self->{extension_data};
  79. }
  80. sub set_extension
  81. {
  82. my ($self, $ext_type, $ext_data) = @_;
  83. $self->{extension_data}{$ext_type} = $ext_data;
  84. }
  85. sub delete_extension
  86. {
  87. my ($self, $ext_type) = @_;
  88. delete $self->{extension_data}{$ext_type};
  89. }
  90. 1;