Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

  1. #
  2. # $Id: https.pm,v 1.8 1999/09/20 12:48:37 gisle Exp $
  3. use strict;
  4. package LWP::Protocol::https;
  5. # Figure out which SSL implementation to use
  6. use vars qw($SSL_CLASS);
  7. if ($IO::Socket::SSL::VERSION) {
  8. $SSL_CLASS = "IO::Socket::SSL"; # it was already loaded
  9. } else {
  10. eval { require Net::SSL; }; # from Crypt-SSLeay
  11. if ($@) {
  12. require IO::Socket::SSL;
  13. $SSL_CLASS = "IO::Socket::SSL";
  14. } else {
  15. $SSL_CLASS = "Net::SSL";
  16. }
  17. }
  18. use vars qw(@ISA);
  19. require LWP::Protocol::http;
  20. @ISA=qw(LWP::Protocol::http);
  21. sub _new_socket
  22. {
  23. my($self, $host, $port, $timeout) = @_;
  24. local($^W) = 0; # IO::Socket::INET can be noisy
  25. my $sock = $SSL_CLASS->new(PeerAddr => $host,
  26. PeerPort => $port,
  27. Proto => 'tcp',
  28. Timeout => $timeout,
  29. );
  30. unless ($sock) {
  31. # IO::Socket::INET leaves additional error messages in $@
  32. $@ =~ s/^.*?: //;
  33. die "Can't connect to $host:$port ($@)";
  34. }
  35. $sock;
  36. }
  37. sub _check_sock
  38. {
  39. my($self, $req, $sock) = @_;
  40. my $check = $req->header("If-SSL-Cert-Subject");
  41. if (defined $check) {
  42. my $cert = $sock->get_peer_certificate ||
  43. die "Missing SSL certificate";
  44. my $subject = $cert->subject_name;
  45. die "Bad SSL certificate subject: '$subject' !~ /$check/"
  46. unless $subject =~ /$check/;
  47. $req->remove_header("If-SSL-Cert-Subject"); # don't pass it on
  48. }
  49. }
  50. sub _get_sock_info
  51. {
  52. my $self = shift;
  53. $self->SUPER::_get_sock_info(@_);
  54. my($res, $sock) = @_;
  55. $res->header("Client-SSL-Cipher" => $sock->get_cipher);
  56. my $cert = $sock->get_peer_certificate;
  57. if ($cert) {
  58. $res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
  59. $res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
  60. }
  61. $res->header("Client-SSL-Warning" => "Peer certificate not verified");
  62. }
  63. 1;