line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ACME::RetryAfter; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
4
|
|
|
|
|
|
|
# A base class for modules that handle the 202 status with Retry-After |
5
|
|
|
|
|
|
|
# header, as described in the ACME protocol spec. |
6
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
681
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
9
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
33
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
657
|
use Net::ACME::HTTP (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my ( $class, %opts ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $uri = $opts{'uri'} or do { |
17
|
|
|
|
|
|
|
die( sprintf "“%s” requires a “uri”!", __PACKAGE__ ); |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $self = bless { _uri => $uri }, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if ( $opts{'retry_after'} ) { |
23
|
|
|
|
|
|
|
$self->_consume_retry_after_value( $opts{'retry_after'} ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub uri { return (shift)->{'_uri'}; } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_time_to_poll { |
32
|
|
|
|
|
|
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $earliest_time = $self->{'_next_retry_time'}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return 1 if !$earliest_time || ( time >= $earliest_time ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub poll { |
42
|
|
|
|
|
|
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $resp = $self->_http_get( $self->{'_uri'} ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if ( $resp->status() == 202 ) { |
47
|
|
|
|
|
|
|
$self->_consume_retry_after_value( $resp->header('retry-after') ); |
48
|
|
|
|
|
|
|
return undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return scalar $self->_handle_non_202_poll($resp); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#https://ietf-wg-acme.github.io/acme/#certificate-issuance |
55
|
|
|
|
|
|
|
sub _consume_retry_after_value { |
56
|
|
|
|
|
|
|
my ( $self, $val ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->{'_next_retry_time'} = $val && ( time + $val ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _http_get { |
64
|
|
|
|
|
|
|
my ( $self, $uri ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->{'_http'} ||= Net::ACME::HTTP->new(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $self->{'_http'}->get($uri); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |