@@ -153,6 +153,7 @@ sub parse_options {
153
153
push @ARGV , grep length , split /\s +/, $self -> env(' OPT' );
154
154
push @ARGV , @_ ;
155
155
156
+ my $custom_cpanmetadb ;
156
157
Getopt::Long::Configure(" bundling" );
157
158
Getopt::Long::GetOptions(
158
159
' f|force' => sub { $self -> {skip_installed } = 0; $self -> {force } = 1 },
@@ -183,7 +184,7 @@ sub parse_options {
183
184
$self -> {mirrors } = [$_ [1]];
184
185
$self -> {mirror_only } = 1;
185
186
},
186
- ' cpanmetadb=s' => \$self -> { cpanmetadb } ,
187
+ ' cpanmetadb=s' => \$custom_cpanmetadb ,
187
188
' cascade-search!' => \$self -> {cascade_search },
188
189
' prompt!' => \$self -> {prompt },
189
190
' installdeps' => \$self -> {installdeps },
@@ -235,6 +236,14 @@ sub parse_options {
235
236
$self -> {load_from_stdin } = 1;
236
237
}
237
238
239
+ if ($custom_cpanmetadb ) {
240
+ $self -> {cpanmetadb } = $custom_cpanmetadb ;
241
+ $self -> {has_custom_cpanmetadb } = 1;
242
+ }
243
+ else {
244
+ $self -> {cpanmetadb } =~ s ! ^https:! http:! if $self -> {use_http };
245
+ }
246
+
238
247
$self -> {argv } = \@ARGV ;
239
248
}
240
249
@@ -611,7 +620,8 @@ Options:
611
620
-v,--verbose Turns on chatty output
612
621
-q,--quiet Turns off the most output
613
622
--interactive Turns on interactive configure (required for Task:: modules)
614
- -f,--force force install
623
+ --insecure Use HTTP-only requests instead of HTTPS
624
+ -f,--force Force install
615
625
-n,--notest Do not run unit tests
616
626
--test-only Run tests only, do not install
617
627
-S,--sudo sudo to run install commands
@@ -628,7 +638,7 @@ Options:
628
638
--auto-cleanup Number of days that cpanm's work directories expire in. Defaults to 7
629
639
630
640
Commands:
631
- --self-upgrade upgrades itself
641
+ --self-upgrade Upgrades itself
632
642
--info Displays distribution info on CPAN
633
643
--look Opens the distribution with your SHELL
634
644
-U,--uninstall Uninstalls the modules (EXPERIMENTAL)
@@ -1165,12 +1175,22 @@ sub chdir {
1165
1175
sub configure_mirrors {
1166
1176
my $self = shift ;
1167
1177
unless (@{$self -> {mirrors }}) {
1168
- $self -> {mirrors } = [ ' https://www.cpan.org' ];
1178
+ $self -> {mirrors } = [
1179
+ ($self -> {use_http } ? ' http' : ' https' ) . ' ://www.cpan.org'
1180
+ ];
1169
1181
}
1182
+
1183
+ my $warned ;
1170
1184
for (@{$self -> {mirrors }}) {
1171
1185
s ! ^/! file:///! ;
1172
1186
s ! /$!! ;
1187
+
1188
+ if (m / ^http:/ && !$self -> {use_http } && !$warned ) {
1189
+ warn " WARNING: you are using a non-HTTPS mirror, which is considered insecure. To remove this message, please pass the --insecure flag.\n " if !$warned ;
1190
+ $warned = 1;
1191
+ }
1173
1192
}
1193
+ return ;
1174
1194
}
1175
1195
1176
1196
sub self_upgrade {
@@ -1639,6 +1659,7 @@ sub cpan_module_common {
1639
1659
1640
1660
my $mirrors = $self -> {mirrors };
1641
1661
if ($match -> {download_uri }) {
1662
+ $match -> {download_uri } =~ s ! ^https:! http:! if $self -> {use_http };
1642
1663
(my $mirror = $match -> {download_uri }) =~ s ! /authors/id/.*$!! ;
1643
1664
$mirrors = [$mirror ];
1644
1665
}
@@ -2679,8 +2700,7 @@ sub mirror {
2679
2700
die <<"DIE" ;
2680
2701
TLS issue found while fetching $uri :\n
2681
2702
$reply ->{content}\n
2682
- Please verify your certificates or force an HTTP-only request/mirror
2683
- using --insecure option at your own risk.
2703
+ Please verify/update your certificates. You may also force an HTTP-only mirror or use the --insecure flag.
2684
2704
DIE
2685
2705
}
2686
2706
}
@@ -2727,23 +2747,41 @@ sub file_mirror {
2727
2747
sub configure_http {
2728
2748
my $self = shift ;
2729
2749
2730
- require HTTP::Tinyish;
2731
-
2732
- my $use_http = $self -> {use_http };
2733
-
2734
2750
my @try = qw( HTTPTiny) ;
2735
2751
unshift @try , ' Wget' if $self -> {try_wget };
2736
2752
unshift @try , ' Curl' if $self -> {try_curl };
2737
2753
unshift @try , ' LWP' if $self -> {try_lwp };
2738
2754
2739
- my @protocol = ( $use_http ? ' http' : ' https' );
2740
- push @protocol , ' http'
2741
- if !$use_http && grep /^http:/, @{$self -> {mirrors }};
2755
+ my @protocol = (' http' );
2756
+ if (!$self -> {use_http } || $self -> {cpanmetadb } =~ / ^https:/ || (grep /^https:/, @{$self -> {mirrors }})) {
2757
+ push @protocol , ' https' ;
2758
+ }
2742
2759
2760
+ my $backend = $self -> get_http_backend(\@try , \@protocol );
2761
+
2762
+ # fallback to http-only if we failed using https with default options:
2763
+ if (!$backend && !$self -> {use_http } && && !@{$self -> {mirrors }} && (!$self -> {has_custom_cpanmetadb } || $self -> {cpanmetadb } =~ / ^http:/ )) {
2764
+ $self -> diag(' WARNING: TLS support not found. Falling back to insecure HTTP-only requests' );
2765
+ $self -> {use_http } = 1;
2766
+ @protocol = (' http' );
2767
+ $backend = $self -> get_http_backend(\@try , \@protocol );
2768
+ }
2769
+
2770
+ if ( !$backend ) {
2771
+ $self -> diag_fail( join ( ' , ' , @protocol )." not supported by available HTTP Clients." );
2772
+ }
2773
+
2774
+ $backend -> new(agent => " Menlo/$Menlo::VERSION " , verify_SSL => 1);
2775
+ }
2776
+
2777
+ sub get_http_backend {
2778
+ my ($self , $tries , $protocols ) = @_ ;
2779
+
2780
+ require HTTP::Tinyish;
2743
2781
my $backend ;
2744
- for my $try (map " HTTP::Tinyish::$_ " , @try ) {
2782
+ for my $try (map " HTTP::Tinyish::$_ " , @$tries ) {
2745
2783
if (my $meta = HTTP::Tinyish-> configure_backend($try )) {
2746
- if ((grep $try -> supports($_ ), @protocol ) == @protocol ) {
2784
+ if ((grep $try -> supports($_ ), @$protocols ) == @$protocols ) {
2747
2785
for my $tool (sort keys %$meta ){
2748
2786
(my $desc = $meta -> {$tool }) =~ s / ^(.*?)\n .*/ $1 / s ;
2749
2787
$self -> chat(" You have $tool : $desc \n " );
@@ -2753,15 +2791,7 @@ sub configure_http {
2753
2791
}
2754
2792
}
2755
2793
}
2756
-
2757
- # In case we use https protocol by default
2758
- # and then later we try to perform non https requests
2759
- # we still want these requests to succeed
2760
- # Note: this is disabling the client cache optimization above
2761
- # and will fail later for SSL requests as no clients support TLS
2762
- $backend ||= ' HTTP::Tinyish' ;
2763
-
2764
- $backend -> new(agent => " Menlo/$Menlo::VERSION " , $use_http ? () : ( verify_SSL => 1 ) );
2794
+ return $backend ;
2765
2795
}
2766
2796
2767
2797
sub init_tools {
0 commit comments