@@ -69,7 +69,7 @@ sub new {
69
69
mirrors => [],
70
70
mirror_only => undef ,
71
71
mirror_index => undef ,
72
- cpanmetadb => " http ://cpanmetadb.plackperl.org/v1.0/" ,
72
+ cpanmetadb => " https ://cpanmetadb.plackperl.org/v1.0/" ,
73
73
perl => $^X,
74
74
argv => [],
75
75
local_lib => undef ,
@@ -83,6 +83,7 @@ sub new {
83
83
try_lwp => 1,
84
84
try_wget => 1,
85
85
try_curl => 1,
86
+ use_http => 0,
86
87
uninstall_shadows => ($] < 5.012),
87
88
skip_installed => 1,
88
89
skip_satisfied => 0,
@@ -200,6 +201,7 @@ sub parse_options {
200
201
' lwp!' => \$self -> {try_lwp },
201
202
' wget!' => \$self -> {try_wget },
202
203
' curl!' => \$self -> {try_curl },
204
+ ' insecure!' => \$self -> {use_http },
203
205
' auto-cleanup=s' => \$self -> {auto_cleanup },
204
206
' man-pages!' => \$self -> {pod2man },
205
207
' scandeps' => \$self -> {scandeps },
@@ -526,7 +528,7 @@ sub numify_ver {
526
528
sub search_metacpan {
527
529
my ($self , $module , $version , $dev_release ) = @_ ;
528
530
529
- my $metacpan_uri = ' http ://fastapi.metacpan.org/v1/download_url/' ;
531
+ my $metacpan_uri = ' https ://fastapi.metacpan.org/v1/download_url/' ;
530
532
531
533
my $url = $metacpan_uri . $module ;
532
534
@@ -543,7 +545,7 @@ sub search_metacpan {
543
545
if ($dist_meta && $dist_meta -> {download_url }) {
544
546
(my $distfile = $dist_meta -> {download_url }) =~ s ! .+/authors/id/!! ;
545
547
local $self -> {mirrors } = $self -> {mirrors };
546
- $self -> {mirrors } = [ ' http ://cpan.metacpan.org' ];
548
+ $self -> {mirrors } = [ ' https ://cpan.metacpan.org' ];
547
549
return $self -> cpan_module($module , $distfile , $dist_meta -> {version });
548
550
}
549
551
@@ -619,7 +621,7 @@ sub search_cpanmetadb_history {
619
621
for my $try (sort { $b -> {version_obj } cmp $a -> {version_obj } } @found ) {
620
622
if ($self -> satisfy_version($module , $try -> {version_obj }, $version )) {
621
623
local $self -> {mirrors } = $self -> {mirrors };
622
- unshift @{$self -> {mirrors }}, ' http ://backpan.perl.org'
624
+ unshift @{$self -> {mirrors }}, ' https ://backpan.perl.org'
623
625
unless $try -> {latest };
624
626
return $self -> cpan_module($module , $try -> {distfile }, $try -> {version });
625
627
}
@@ -747,7 +749,7 @@ Options:
747
749
--installdeps Only install dependencies
748
750
--showdeps Only display direct dependencies
749
751
--reinstall Reinstall the distribution even if you already have the latest version installed
750
- --mirror Specify the base URL for the mirror (e.g. http ://cpan.cpantesters.org/)
752
+ --mirror Specify the base URL for the mirror (e.g. https ://cpan.cpantesters.org/)
751
753
--mirror-only Use the mirror's index file instead of the CPAN Meta DB
752
754
-M,--from Use only this mirror base URL and its index file
753
755
--prompt Prompt when configure/build/test fails
@@ -767,18 +769,18 @@ Examples:
767
769
768
770
cpanm Test::More # install Test::More
769
771
cpanm MIYAGAWA/Plack-0.99_05.tar.gz # full distribution path
770
- cpanm http ://example.org/LDS/CGI.pm-3.20.tar.gz # install from URL
772
+ cpanm https ://example.org/LDS/CGI.pm-3.20.tar.gz # install from URL
771
773
cpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz # install from a local file
772
774
cpanm --interactive Task::Kensho # Configure interactively
773
775
cpanm . # install from local directory
774
776
cpanm --installdeps . # install all the deps for the current directory
775
777
cpanm -L extlib Plack # install Plack and all non-core deps into extlib
776
- cpanm --mirror http ://cpan.cpantesters.org/ DBI # use the fast-syncing mirror
778
+ cpanm --mirror https ://cpan.cpantesters.org/ DBI # use the fast-syncing mirror
777
779
cpanm -M https://cpan.metacpan.org App::perlbrew # use only this secure mirror and its index
778
780
779
781
You can also specify the default options in PERL_CPANM_OPT environment variable in the shell rc:
780
782
781
- export PERL_CPANM_OPT="--prompt --reinstall -l ~/perl --mirror http ://cpan.cpantesters.org"
783
+ export PERL_CPANM_OPT="--prompt --reinstall -l ~/perl --mirror https ://cpan.cpantesters.org"
782
784
783
785
Type `man cpanm` or `perldoc cpanm` for the more detailed explanation of the options.
784
786
@@ -1271,12 +1273,19 @@ sub chdir {
1271
1273
sub configure_mirrors {
1272
1274
my $self = shift ;
1273
1275
unless (@{$self -> {mirrors }}) {
1274
- $self -> {mirrors } = [ ' http ://www.cpan.org' ];
1276
+ $self -> {mirrors } = [ ' https ://www.cpan.org' ];
1275
1277
}
1276
1278
for (@{$self -> {mirrors }}) {
1277
1279
s ! ^/! file:///! ;
1278
1280
s ! /$!! ;
1279
1281
}
1282
+
1283
+ if ( grep { m / ^http:/ } @{$self -> {mirrors }} ) {
1284
+ warn " WARNING: Detected a non TLS mirror, enforcing http requests.\n " ;
1285
+ $self -> {use_http } = 1;
1286
+ }
1287
+
1288
+ return ;
1280
1289
}
1281
1290
1282
1291
sub self_upgrade {
@@ -1761,7 +1770,7 @@ sub cpan_dist {
1761
1770
sub git_uri {
1762
1771
my ($self , $uri ) = @_ ;
1763
1772
1764
- # similar to http ://www.pip-installer.org/en/latest/logic.html#vcs-support
1773
+ # similar to https ://www.pip-installer.org/en/latest/logic.html#vcs-support
1765
1774
# git URL has to end with .git when you need to use pin @ commit/tag/branch
1766
1775
1767
1776
($uri , my $commitish ) = split /(?<=\.git)@/i, $uri , 2;
@@ -2740,6 +2749,7 @@ sub mirror {
2740
2749
} else {
2741
2750
$self -> {_backends }{mirror }-> (@_ );
2742
2751
}
2752
+
2743
2753
}
2744
2754
2745
2755
sub untar { $_ [0]-> {_backends }{untar }-> (@_ ) };
@@ -2780,7 +2790,9 @@ sub file_mirror {
2780
2790
2781
2791
sub has_working_lwp {
2782
2792
my ($self , $mirrors ) = @_ ;
2793
+
2783
2794
my $https = grep /^https:/, @$mirrors ;
2795
+ $https = 0 if $self -> {use_http };
2784
2796
eval {
2785
2797
require LWP::UserAgent; # no fatpack
2786
2798
LWP::UserAgent-> VERSION(5.802);
@@ -2798,6 +2810,8 @@ sub init_tools {
2798
2810
$self -> chat(" You have make $self ->{make}\n " );
2799
2811
}
2800
2812
2813
+ my ( $http_get , $http_mirror );
2814
+
2801
2815
# use --no-lwp if they have a broken LWP, to upgrade LWP
2802
2816
if ($self -> {try_lwp } && $self -> has_working_lwp($self -> {mirrors })) {
2803
2817
$self -> chat(" You have LWP $LWP::VERSION \n " );
@@ -2810,13 +2824,13 @@ sub init_tools {
2810
2824
@_ ,
2811
2825
);
2812
2826
};
2813
- $self -> { _backends }{ get } = sub {
2827
+ $http_get = sub {
2814
2828
my $self = shift ;
2815
2829
my $res = $ua -> ()-> request(HTTP::Request-> new(GET => $_ [0]));
2816
2830
return unless $res -> is_success;
2817
2831
return $res -> decoded_content;
2818
2832
};
2819
- $self -> { _backends }{ mirror } = sub {
2833
+ $http_mirror = sub {
2820
2834
my $self = shift ;
2821
2835
my $res = $ua -> ()-> mirror(@_ );
2822
2836
die $res -> content if $res -> code == 501;
@@ -2829,13 +2843,13 @@ sub init_tools {
2829
2843
' --retry-connrefused' ,
2830
2844
($self -> {verbose } ? () : (' -q' )),
2831
2845
);
2832
- $self -> { _backends }{ get } = sub {
2846
+ $http_get = sub {
2833
2847
my ($self , $uri ) = @_ ;
2834
2848
$self -> safeexec( my $fh , $wget , $uri , @common , ' -O' , ' -' ) or die " wget $uri : $! " ;
2835
2849
local $/ ;
2836
2850
<$fh >;
2837
2851
};
2838
- $self -> { _backends }{ mirror } = sub {
2852
+ $http_mirror = sub {
2839
2853
my ($self , $uri , $path ) = @_ ;
2840
2854
$self -> safeexec( my $fh , $wget , $uri , @common , ' -O' , $path ) or die " wget $uri : $! " ;
2841
2855
local $/ ;
@@ -2848,13 +2862,13 @@ sub init_tools {
2848
2862
' --user-agent' , $self -> agent,
2849
2863
($self -> {verbose } ? () : ' -s' ),
2850
2864
);
2851
- $self -> { _backends }{ get } = sub {
2865
+ $http_get = sub {
2852
2866
my ($self , $uri ) = @_ ;
2853
2867
$self -> safeexec( my $fh , $curl , @common , $uri ) or die " curl $uri : $! " ;
2854
2868
local $/ ;
2855
2869
<$fh >;
2856
2870
};
2857
- $self -> { _backends }{ mirror } = sub {
2871
+ $http_mirror = sub {
2858
2872
my ($self , $uri , $path ) = @_ ;
2859
2873
$self -> safeexec( my $fh , $curl , @common , $uri , ' -#' , ' -o' , $path ) or die " curl $uri : $! " ;
2860
2874
local $/ ;
@@ -2866,19 +2880,23 @@ sub init_tools {
2866
2880
my %common = (
2867
2881
agent => $self -> agent,
2868
2882
);
2869
- $self -> { _backends }{ get } = sub {
2883
+ $http_get = sub {
2870
2884
my $self = shift ;
2871
2885
my $res = HTTP::Tiny-> new(%common )-> get($_ [0]);
2872
2886
return unless $res -> {success };
2873
2887
return $res -> {content };
2874
2888
};
2875
- $self -> { _backends }{ mirror } = sub {
2889
+ $http_mirror = sub {
2876
2890
my $self = shift ;
2877
2891
my $res = HTTP::Tiny-> new(%common )-> mirror(@_ );
2878
2892
return $res -> {status };
2879
2893
};
2880
2894
}
2881
2895
2896
+ # handle the insecure mode to honor and force http requests
2897
+ $self -> {_backends }{get } = $self -> wrap_http_request( $http_get );
2898
+ $self -> {_backends }{mirror } = $self -> wrap_http_request( $http_mirror );
2899
+
2882
2900
my $tar = $self -> which(' tar' );
2883
2901
my $tar_ver ;
2884
2902
my $maybe_bad_tar = sub { WIN32 || BAD_TAR || (($tar_ver = ` $tar --version 2>/dev/null` ) =~ / GNU.*1\. 13/i ) };
@@ -3017,6 +3035,40 @@ sub init_tools {
3017
3035
}
3018
3036
}
3019
3037
3038
+ sub wrap_http_request {
3039
+ my ( $self , $code ) = @_ ;
3040
+
3041
+ die unless ref $code eq ' CODE' ;
3042
+
3043
+ my $wrapper = sub {
3044
+ my ( $self , $uri , @extra ) = @_ ;
3045
+
3046
+ # certificates check, let's switch to http on demand.
3047
+ $uri =~ s / ^https:/ http:/ if $self -> {use_http };
3048
+
3049
+ # call the get or mirror
3050
+ my $reply = $code -> ( $self , $uri , @extra );
3051
+
3052
+ if ( ! $self -> {use_http } && $uri =~ m { ^https:} && !$self -> {has_displayed_insecure_advice } ) {
3053
+ if ( !defined $reply || $reply eq 500 || $reply =~ m { certificate} mi ) {
3054
+
3055
+ die <<"DIE" ;
3056
+ Failed to fetch $uri : $reply \n
3057
+
3058
+ This could be a TLS issue with the HTTP client used.
3059
+ Please verify your certificates or force an HTTP-only request/mirror
3060
+ using --insecure option at your own risk.
3061
+ DIE
3062
+ $self -> {has_displayed_insecure_advice } = 1;
3063
+ }
3064
+ }
3065
+
3066
+ return $reply ;
3067
+ };
3068
+
3069
+ return $wrapper ;
3070
+ }
3071
+
3020
3072
sub safeexec {
3021
3073
my $self = shift ;
3022
3074
my $rdr = $_ [0] ||= Symbol::gensym();
0 commit comments