| 1 | package Net::ACME::Authorization::Pending; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | Net::ACME::Authorization::Pending - pending ACME authorization | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | use Net::ACME::Authorization::Pending (); | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | my $authz_p = Net::ACME::Authorization::Pending->new( | ||||||||||||||||||||
| 14 | uri => 'http://url/to/poll/for/authz', | ||||||||||||||||||||
| 15 | challenges => \@challenge_objects, | ||||||||||||||||||||
| 16 | combinations => [ | ||||||||||||||||||||
| 17 | [ 2 ], | ||||||||||||||||||||
| 18 | [ 1 ], | ||||||||||||||||||||
| 19 | [ 0 ], | ||||||||||||||||||||
| 20 | ], | ||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | for my $cmb ( $authz_p->combinations() ) { | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | #An example of only doing “http-01”: | ||||||||||||||||||||
| 26 | next if @$cmb > 1; | ||||||||||||||||||||
| 27 | next if $cmb->[0]->type() ne 'http-01'; | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #Prepare for the challenge … | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | #Assume we instantiated Net::ACME above … | ||||||||||||||||||||
| 32 | $acme->do_challenge($cmb->[0]); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | while (1) { | ||||||||||||||||||||
| 35 | if ($authz_p->is_time_to_poll()) { | ||||||||||||||||||||
| 36 | my $poll = $authz_p->poll(); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | last if $poll->status() eq 'valid'; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | if ($poll->status() eq 'invalid') { | ||||||||||||||||||||
| 41 | my $completed_challenge = ($poll->challenges())[0]; | ||||||||||||||||||||
| 42 | print $completed_challenge->error()->detail() . $/; | ||||||||||||||||||||
| 43 | die "Failed authorization!$/"; | ||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sleep 1; | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | last; | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | #NOTE: For now, this assumes a domain name. | ||||||||||||||||||||
| 57 | #Might be useful moving forward to separate out other types | ||||||||||||||||||||
| 58 | #of authz as per ACME spec expansion. (As of April 2016 only | ||||||||||||||||||||
| 59 | #domain names are handled.) | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | 7 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 7 | ▶ | use parent qw( Net::ACME::RetryAfter ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 7 | ▶ | use Call::Context (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 7 | ▶ | use Net::ACME::Authorization (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 69 | 7 | ▶ | use Net::ACME::Challenge (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 70 | 7 | ▶ | use Net::ACME::Error (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 71 | 7 | ▶ | use Net::ACME::X (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | my $PENDING_CLASS = 'Net::ACME::Challenge::Pending'; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||
| 76 | 3 | my ( $class, %opts ) = @_; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | my $self = { | ||||||||||||||||||||
| 79 | _uri => $opts{'uri'} || die('Need “uri”!'), | ||||||||||||||||||||
| 80 | _challenges => $opts{'challenges'}, | ||||||||||||||||||||
| 81 | 3 | ▶ | _combinations => $opts{'combinations'}, | ||||||||||||||||||
|
Condition50%1/2
$opts{'uri'} || die("Need \342\200\234uri\342\200\235!")
MC/DC0%0/1
$opts{'uri'} || die("Need \342\200\234uri\342\200\235!")
$opts{'uri'}
Truth table50%1/2
A
A= $opts{'uri'}
| |||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 3 | ▶ | if ( !@{ $opts{'challenges'} } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 0 | die Net::ACME::X::create( 'Empty', { name => 'challenges' } ); | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 3 | for my $c ( 0 .. $#{ $opts{'challenges'} } ) { | |||||||||||||||||||
| 89 | 4 | my $challenge = $opts{'challenges'}[$c]; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 4 | ▶ | if ( !$challenge->isa($PENDING_CLASS) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 0 | die "Challenge $c ($challenge) is not an instance of “$PENDING_CLASS”!"; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 3 | bless $self, $class; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 3 | return $self; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | ▶ | sub combinations { | ||||||||||||||||||
|
Subroutine
combinations: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 102 | 1 | my ($self) = @_; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1 | Call::Context::must_be_list(); | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | return map { | ||||||||||||||||||||
| 107 | 2 | [ map { $self->{'_challenges'}[$_] } @$_ ] | |||||||||||||||||||
| 108 | 1 | } @{ $self->{'_combinations'} }; | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 3 | ▶ | sub _handle_non_202_poll { | ||||||||||||||||||
|
Subroutine
_handle_non_202_poll: called CC=5 SCAR=16.2
| |||||||||||||||||||||
| 112 | 3 | my ( $self, $resp ) = @_; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 3 | ▶ | $resp->die_because_unexpected() if $resp->status() != 200; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 2 | my $payload = $resp->content_struct(); | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 2 | my @challenge_objs; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 2 | for my $c ( @{ $payload->{'challenges'} } ) { | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | #We only care here about challenges that have been resolved. | ||||||||||||||||||||
| 123 | 2 | ▶ | next if $c->{'status'} eq 'pending'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 2 | my $err = $c->{'error'}; | |||||||||||||||||||
| 126 | 2 | ▶ | $err &&= Net::ACME::Error->new(%$err); | ||||||||||||||||||
|
Condition66%2/3
$err &&= "Net::ACME::Error"->new(%$err)
MC/DC50%1/2
$err &&= "Net::ACME::Error"->new(%$err)
$err
"Net::ACME::Error"->new(%$err)
Truth table66%2/3
A &&= B
A= $errB= "Net::ACME::Error"->new(%$err)
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | push @challenge_objs, Net::ACME::Challenge->new( | ||||||||||||||||||||
| 129 | 2 | status => $c->{'status'}, | |||||||||||||||||||
| 130 | error => $err, | ||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | return Net::ACME::Authorization->new( | ||||||||||||||||||||
| 135 | 2 | status => $payload->{'status'}, | |||||||||||||||||||
| 136 | challenges => \@challenge_objs, | ||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 7 | 1; | |||||||||||||||||||