<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package LWP::Protocol::https;

use strict;
use warnings;

our $VERSION = '6.13';

use base qw(LWP::Protocol::http);
require Net::HTTPS;

sub socket_type
{
    return "https";
}

sub _extra_sock_opts
{
    my $self = shift;
    my %ssl_opts = %{$self-&gt;{ua}{ssl_opts} || {}};
    if (delete $ssl_opts{verify_hostname}) {
	$ssl_opts{SSL_verify_mode} ||= 1;
	$ssl_opts{SSL_verifycn_scheme} = 'www';
    }
    else {
        if ( $Net::HTTPS::SSL_SOCKET_CLASS eq 'Net::SSL' ) {
            $ssl_opts{SSL_verifycn_scheme} = '';
        } else {
            $ssl_opts{SSL_verifycn_scheme} = 'none';
        }
    }
    if ($ssl_opts{SSL_verify_mode}) {
        unless (exists $ssl_opts{SSL_ca_file} || exists $ssl_opts{SSL_ca_path}) {
            if ($Net::HTTPS::SSL_SOCKET_CLASS eq 'IO::Socket::SSL'
                &amp;&amp; defined &amp;IO::Socket::SSL::default_ca
                &amp;&amp; IO::Socket::SSL::default_ca() ) {
                # IO::Socket::SSL has a usable default CA
            } else {
              $ssl_opts{SSL_ca_file} = '/etc/ssl/certs/ca-certificates.crt';
            }
        }
    }
    $self-&gt;{ssl_opts} = \%ssl_opts;
    return (%ssl_opts, MultiHomed =&gt; 1, $self-&gt;SUPER::_extra_sock_opts);
}

# This is a subclass of LWP::Protocol::http.
# That parent class calls -&gt;_check_sock() during the
# request method. This allows us to hook in and run checks
# sub _check_sock
# {
#     my($self, $req, $sock) = @_;
# }

sub _get_sock_info
{
    my $self = shift;
    $self-&gt;SUPER::_get_sock_info(@_);
    my($res, $sock) = @_;
    if ($sock-&gt;can('get_sslversion') and my $sslversion = $sock-&gt;get_sslversion) {
        $res-&gt;header("Client-SSL-Version" =&gt; $sslversion);
    }
    $res-&gt;header("Client-SSL-Cipher" =&gt; $sock-&gt;get_cipher);
    my $cert = $sock-&gt;get_peer_certificate;
    if ($cert) {
	$res-&gt;header("Client-SSL-Cert-Subject" =&gt; $cert-&gt;subject_name);
	$res-&gt;header("Client-SSL-Cert-Issuer" =&gt; $cert-&gt;issuer_name);
    }
    if (!$self-&gt;{ssl_opts}{SSL_verify_mode}) {
	$res-&gt;push_header("Client-SSL-Warning" =&gt; "Peer certificate not verified");
    }
    elsif (!$self-&gt;{ssl_opts}{SSL_verifycn_scheme}) {
	$res-&gt;push_header("Client-SSL-Warning" =&gt; "Peer hostname match with certificate not verified");
    }
    $res-&gt;header("Client-SSL-Socket-Class" =&gt; $Net::HTTPS::SSL_SOCKET_CLASS);
}

# upgrade plain socket to SSL, used for CONNECT tunnel when proxying https
# will only work if the underlying socket class of Net::HTTPS is
# IO::Socket::SSL, but code will only be called in this case
if ( $Net::HTTPS::SSL_SOCKET_CLASS-&gt;can('start_SSL')) {
    *_upgrade_sock = sub {
	my ($self,$sock,$url) = @_;
    # SNI should be passed there only if it is not an IP address.
    # Details: https://github.com/libwww-perl/libwww-perl/issues/449#issuecomment-1896175509
	my $host = $url-&gt;host() =~ m/:|^[\d.]+$/s ? undef : $url-&gt;host();
	$sock = LWP::Protocol::https::Socket-&gt;start_SSL( $sock,
	    SSL_verifycn_name =&gt; $url-&gt;host,
	    SSL_hostname =&gt; $host,
	    $self-&gt;_extra_sock_opts,
	);
	$@ = LWP::Protocol::https::Socket-&gt;errstr if ! $sock;
	return $sock;
    }
}

#-----------------------------------------------------------
package LWP::Protocol::https::Socket;

use base qw(Net::HTTPS LWP::Protocol::http::SocketMethods);

1;

__END__

=head1 NAME

LWP::Protocol::https - Provide https support for LWP::UserAgent

=head1 SYNOPSIS

  use LWP::UserAgent;

  $ua = LWP::UserAgent-&gt;new(ssl_opts =&gt; { verify_hostname =&gt; 1 });
  $res = $ua-&gt;get("https://www.example.com");

  # specify a CA path
  $ua = LWP::UserAgent-&gt;new(
      ssl_opts =&gt; {
          SSL_ca_path     =&gt; '/etc/ssl/certs',
          verify_hostname =&gt; 1,
      }
  );

=head1 DESCRIPTION

The LWP::Protocol::https module provides support for using https schemed
URLs with LWP.  This module is a plug-in to the LWP protocol handling, so
you don't use it directly.  Once the module is installed LWP is able
to access sites using HTTP over SSL/TLS.

If hostname verification is requested by LWP::UserAgent's C&lt;ssl_opts&gt;, and
neither C&lt;SSL_ca_file&gt; nor C&lt;SSL_ca_path&gt; is set, then C&lt;SSL_ca_file&gt; is
implied to be the one provided by L&lt;Mozilla::CA&gt;.  If the Mozilla::CA module
isn't available SSL requests will fail.  Either install this module, set up an
alternative C&lt;SSL_ca_file&gt; or disable hostname verification.

This module used to be bundled with the libwww-perl, but it was unbundled in
v6.02 in order to be able to declare its dependencies properly for the CPAN
tool-chain.  Applications that need https support can just declare their
dependency on LWP::Protocol::https and will no longer need to know what
underlying modules to install.

=head1 SEE ALSO

L&lt;IO::Socket::SSL&gt;, L&lt;Crypt::SSLeay&gt;, L&lt;Mozilla::CA&gt;

=head1 COPYRIGHT &amp; LICENSE

Copyright (c) 1997-2011 Gisle Aas.

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut
</pre></body></html>