Commit 1ec5048c1be5ecea9e67b0c5a09e978fb8c0fe90
- Diff rendering mode:
- inline
- side by side
lib/LWP/Authen/Basic.pm
(2 / 1)
|   | |||
| 27 | 27 | my($req, $ua, $h) = @_; | |
| 28 | 28 | my($user, $pass) = $ua->credentials($host_port, $h->{realm}); | |
| 29 | 29 | if (defined $user) { | |
| 30 | my $auth_value = $class->auth_header($user, $pass, $h); | ||
| 30 | my $auth_value = $class->auth_header($user, $pass, $req, $ua, $h); | ||
| 31 | 31 | $req->header($auth_header => $auth_value); | |
| 32 | 32 | } | |
| 33 | 33 | }; | |
| 34 | 34 | }); | |
| 35 | $h->{auth_param} = $auth_param; | ||
| 35 | 36 | ||
| 36 | 37 | if (!$proxy && !$request->header($auth_header) && $ua->credentials($host_port, $realm)) { | |
| 37 | 38 | # we can make sure this handler applies and retry |
lib/LWP/Authen/Digest.pm
(6 / 28)
|   | |||
| 1 | 1 | package LWP::Authen::Digest; | |
| 2 | |||
| 2 | 3 | use strict; | |
| 4 | use base 'LWP::Authen::Basic'; | ||
| 3 | 5 | ||
| 4 | 6 | require Digest::MD5; | |
| 5 | 7 | ||
| 6 | sub authenticate | ||
| 7 | { | ||
| 8 | my($class, $ua, $proxy, $auth_param, $response, | ||
| 9 | $request, $arg, $size) = @_; | ||
| 8 | sub auth_header { | ||
| 9 | my($class, $user, $pass, $request, $ua, $h) = @_; | ||
| 10 | 10 | ||
| 11 | my($user, $pass) = $ua->get_basic_credentials($auth_param->{realm}, | ||
| 12 | $request->url, $proxy); | ||
| 13 | return $response unless defined $user and defined $pass; | ||
| 11 | my $auth_param = $h->{auth_param}; | ||
| 14 | 12 | ||
| 15 | 13 | my $nc = sprintf "%08X", ++$ua->{authen_md5_nonce_count}{$auth_param->{nonce}}; | |
| 16 | 14 | my $cnonce = sprintf "%8x", time; | |
| … | … | ||
| 61 | 61 | push(@pairs, "$_=" . qq("$resp{$_}")); | |
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization"; | ||
| 65 | 64 | my $auth_value = "Digest " . join(", ", @pairs); | |
| 66 | |||
| 67 | # Need to check this isn't a repeated fail! | ||
| 68 | my $r = $response; | ||
| 69 | while ($r) { | ||
| 70 | my $u = $r->request->{digest_user_pass}; | ||
| 71 | if ($u && $u->[0] eq $user && $u->[1] eq $pass) { | ||
| 72 | # here we know this failed before | ||
| 73 | $response->header("Client-Warning" => | ||
| 74 | "Credentials for '$user' failed before"); | ||
| 75 | return $response; | ||
| 76 | } | ||
| 77 | $r = $r->previous; | ||
| 78 | } | ||
| 79 | |||
| 80 | my $referral = $request->clone; | ||
| 81 | $referral->header($auth_header => $auth_value); | ||
| 82 | # we shouldn't really do this, but... | ||
| 83 | $referral->{digest_user_pass} = [$user, $pass]; | ||
| 84 | |||
| 85 | return $ua->request($referral, $arg, $size, $response); | ||
| 65 | return $auth_value; | ||
| 86 | 66 | } | |
| 87 | 67 | ||
| 88 | 68 | 1; |

