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.

41 lines
1.4 KiB

  1. commit 3b266f17ccd5613a9c42d1e04118e94ca6467489
  2. Author: Gisle Aas <gisle@aas.no>
  3. Date: Sun Jan 16 12:56:30 2011 +0100
  4. Call IO::Socket::SSL's verify_hostname when available
  5. --- a/lib/LWP/Protocol/https.pm
  6. +++ b/lib/LWP/Protocol/https.pm
  7. @@ -14,6 +14,15 @@ sub socket_type
  8. sub _check_sock
  9. {
  10. my($self, $req, $sock) = @_;
  11. + if ($sock->can("verify_hostname")) {
  12. + if (!$sock->verify_hostname($req->uri->host, "www")) {
  13. + my $subject = $sock->peer_certificate("subject");
  14. + die "SSL-peer fails verification [subject=$subject]\n";
  15. + }
  16. + else {
  17. + $req->{ssl_sock_verified}++;
  18. + }
  19. + }
  20. my $check = $req->header("If-SSL-Cert-Subject");
  21. if (defined $check) {
  22. my $cert = $sock->get_peer_certificate ||
  23. @@ -36,9 +45,14 @@ sub _get_sock_info
  24. $res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
  25. $res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
  26. }
  27. - if(! eval { $sock->get_peer_verify }) {
  28. - $res->header("Client-SSL-Warning" => "Peer certificate not verified");
  29. + if (!$res->request->{ssl_sock_verified}) {
  30. + if(! eval { $sock->get_peer_verify }) {
  31. + my $msg = "Peer certificate not verified";
  32. + $msg .= " [$@]" if $@;
  33. + $res->header("Client-SSL-Warning" => $msg);
  34. + }
  35. }
  36. + $res->header("Client-SSL-Socket-Class" => $Net::HTTPS::SSL_SOCKET_CLASS);
  37. }
  38. #-----------------------------------------------------------