libwww perl in ubuntu always enforces HTTPS server certificate
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| libwww-perl (Ubuntu) |
Undecided
|
Unassigned |
Bug Description
Given this simple code:
$ua = LWP::UserAgent-
$ua-
$ua-
$ua->ssl_opts( verify_hostname => 0 );
push @{ $ua->requests_
my $req = HTTP::Request->new( GET =>
$req-
$req-
my $res = $ua->request($req);
LOGDIE "Error getting PE routers via REST to $server: ".$res-
"
if ! $res->is_success;
I get this message:
Error getting PE routers via REST to blc.serv.
LWP::Protocol:
Strace shows that the code is looking for a CA file from the OpenSSL package. blc.serv.
BUT it should not be trying to verify this at all due to the verify_hostname setting.
In HTTP::Protocol:
sub _extra_sock_opts
{
my $self = shift;
my %ssl_opts = %{$self-
if (delete $ssl_opts{
$ssl_opts{
$ssl_opts{
}
else {
$ssl_opts{
}
if ($ssl_opts{
unless (exists $ssl_opts{
eval {
require Mozilla::CA;
};
if ($@) {
if ($@ =! /^Can't locate Mozilla\/CA\.pm/) {
$@ = <<'EOT';
Can't verify SSL peers without knowing which Certificate Authorities to trust
This problem can be fixed by either setting the PERL_LWP_
envirionment variable or by installing the Mozilla::CA module.
To disable verification of SSL peers set the PERL_LWP_
envirionment variable to 0. If you do this you can't be sure that you
communicate with the expected peer.
EOT
}
die $@;
}
$ssl_
}
}
$self-
return (%ssl_opts, $self->
}
Then I get this instead
Error getting PE routers via REST to blc.serv.
which means that the SSL handshake was completed.
ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: libwww-perl 6.05-2
ProcVersionSign
Uname: Linux 3.13.0-43-generic x86_64
ApportVersion: 2.14.1-0ubuntu3.6
Architecture: amd64
Date: Wed Jan 7 16:05:09 2015
InstallationDate: Installed on 2014-12-19 (19 days ago)
InstallationMedia: Ubuntu-Server 14.04 LTS "Trusty Tahr" - Release amd64 (20140416.2)
PackageArchitec
SourcePackage: libwww-perl
UpgradeStatus: No upgrade log present (probably fresh install)
janl (janl) wrote : | #1 |
sullr (coyote-frank) wrote : | #2 |
janl (janl) wrote : | #3 |
So I changed LWP::Porotocol:
# $ua->ssl_opts( verify_hostname => 0 );
$ua->ssl_opts( SSL_verify_mode => 0 );
This causes the same error:
Error getting PE routers via REST to blc.serv.
So it's still not possible to disable the certificate check. Not to mention that the documentation in the package hasn't been updated to reflect this.
# $ua->ssl_opts( verify_hostname => 0 );
$ua->ssl_opts( SSL_verify_mode => 0 );
$ua->ssl_opts( SSL_verifycn_scheme => 'none' );
Additionally it seems to break the principle of least surprise, if someone has working code tested with CPAN LWP and then tries to run it on Ubuntu it will fail without explanation (or any documentation).
janl (janl) wrote : | #4 |
I forgot to write that the SSL_vrifycn_scheme => none setting was tested on a whim and it also did not help. That's why the code fragment is there.
Launchpad Janitor (janitor) wrote : | #5 |
Status changed to 'Confirmed' because the bug affects multiple users.
Changed in libwww-perl (Ubuntu): | |
status: | New → Confirmed |
Erik Squires (erik-squires) wrote : | #6 |
The problem is fixed by LWP::Protocol:
sub _extra_sock_opts
{
my $self = shift;
my %ssl_opts = %{$self-
if (delete $ssl_opts{
$ssl_opts{
$ssl_opts{
}
else {
$ssl_opts{
}
if ($ssl_opts{
unless (exists $ssl_opts{
eval {
require Mozilla::CA;
};
if ($@) {
if ($@ =! /^Can't locate Mozilla\/CA\.pm/) {
$@ = <<'EOT';
Can't verify SSL peers without knowing which Certificate Authorities to trust
This problem can be fixed by either setting the PERL_LWP_
environment variable or by installing the Mozilla::CA module.
To disable verification of SSL peers set the PERL_LWP_
environment variable to 0. If you do this you can't be sure that you
communicate with the expected peer.
EOT
}
die $@;
}
$ssl_
}
}
$self-
return (%ssl_opts, $self->
}
Erik Squires (erik-squires) wrote : | #7 |
er, by "there" I meant from CPAN.
The option verify_hostname is like the name suggests only responsible for verifying the host name against the certificate. It does not control the verification of the certificate chain or any other certificate validations, even if it can be used like this in some versions of LWP::Protocol: :https. But this is actually a bug, see https:/ /github. com/libwww- perl/lwp- protocol- https/pull/ 14 (very long discussion).
The only documentation of the option verify_hostname in LWP::UserAgent says:
When TRUE LWP will for secure protocol schemes ensure it connects to servers that have a valid certificate
Which confirms that this option cares about verifying the host name only.
To disable any kind of certificate validation you have to use ssl_opts to set SSL_verify_mode to 0 (i.e. SSL_VERIFY_NONE).