Skip to content

Commit 2666f3c

Browse files
atoomicgaru
authored andcommitted
Raise warnings when fail to use SSL
If none of the available clients from HTTP::Tinyish support SSL then we should die with a better error message rather than trying to use 'undef' as a backend (which fix an error when calling $backend->new a few lines later). This is also adding an extra check inside the 'mirror' function. That function is used in multiple locations without checking directly the error status. The goal is to detect invalid certificate errors when SSL is supported by the backend.. Note that depending on the backend and probably client version the error message can differ. `HTTP::Tiny` Internal Exception raised with invalid certificates: SSL connection failed for cpan.metacpan.org: Invalid certificate authority locations error:0D07A086:asn1 ... `HTTP::Tinyish::LWP` Internal Exception raised with invalid certificates: 500 Can't connect to cpan.metacpan.org:443 () `HTTP::Tinyish::Curl` Internal Exception raised with invalid certificates: curl: (60) Peer certificate cannot be authenticated with known CA certificates More details here: http://curl.haxx.se/docs/sslcerts.html `HTTP::Tinyish::Wget` Internal Exception raised with invalid certificates: ... ERROR: cannot verify cpan.metacpan.org’s certificate, issued by ... This patch accounts for all the scenarios above. Signed-off-by: Breno G. de Oliveira <[email protected]>
1 parent 6a3853c commit 2666f3c

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Menlo-Legacy/lib/Menlo/CLI/Compat.pm

+31-4
Original file line numberDiff line numberDiff line change
@@ -2650,11 +2650,34 @@ sub DESTROY {
26502650

26512651
sub mirror {
26522652
my($self, $uri, $local) = @_;
2653-
if ($uri =~ /^file:/) {
2654-
$self->file_mirror($uri, $local);
2655-
} else {
2656-
$self->{http}->mirror($uri, $local);
2653+
2654+
die( "mirror: Undefined URI\n" ) unless defined $uri && length $uri;
2655+
2656+
if ( $uri =~ /^file:/) {
2657+
return $self->file_mirror($uri, $local);
2658+
}
2659+
2660+
my $reply = $self->{http}->mirror($uri, $local);
2661+
2662+
if ( $uri =~ /^https:/ && ref $reply
2663+
&& $reply->{status} && $reply->{status} == 599
2664+
&& $reply->{content}
2665+
) {
2666+
my $invalid_cert;
2667+
if ( ref($self->{http}) =~ m{(?:Curl|HTTPTiny|Wget)} ) {
2668+
$invalid_cert = 1 if $reply->{content} =~ m{certificate}mi;
2669+
} elsif ( ref($self->{http}) =~ m{LWP} ) {
2670+
$invalid_cert = 1 if $reply->{content} =~ m{Can't connect.+?:443}mi;
2671+
}
2672+
if ( $invalid_cert ) {
2673+
die <<"DIE";
2674+
SSL certificate verification failed for: $uri
2675+
Please update your certificates or force an HTTP-only request/mirror at your own risk.
2676+
DIE
2677+
}
26572678
}
2679+
2680+
return $reply;
26582681
}
26592682

26602683
sub untar { $_[0]->{_backends}{untar}->(@_) };
@@ -2721,6 +2744,10 @@ sub configure_http {
27212744
}
27222745
}
27232746

2747+
if ( !$backend ) {
2748+
$self->diag_fail( join( ', ', @protocol )." not supported by available HTTP Clients." );
2749+
}
2750+
27242751
$backend->new(agent => "Menlo/$Menlo::VERSION", verify_SSL => 1);
27252752
}
27262753

0 commit comments

Comments
 (0)