ACME2.pm

filter: Statementstmt 72.8% 94 / 129 Branchbran 50.0% 16 / 32 Conditioncond 52.3% 11 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 75.8% 22 / 29 Podpod 100% 9 / 9 totaltotal 65.2% 152 / 233 SCAR 40.0
CC
27
Cov
66%
create_new_account
13.7
create_new_order
6.0
finalize_order
6.0
CRAP 54.4
↑ Summary ACME2/HTTP.pm »
1 package Net::ACME2;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::ACME2 - L<IETF|https://www.ietf.org>-standard ACME (Let’s Encrypt) client
11  
12 X<Lets Encrypt> X<Let's Encrypt> X<letsencrypt>
13  
14 =head1 SYNOPSIS
15  
16 package SomeCA::ACME;
17  
18 use parent qw( Net::ACME2 );
19  
20 use constant {
21 DIRECTORY_PATH => '/acme-directory',
22 };
23  
24 # %opts are the parameters given to new().
25 sub HOST {
26 my ($class, %opts) = @_;
27  
28 # You can make this depend on the %opts if you want.
29 return 'acme.someca.net';
30 }
31  
32 package main;
33  
34 my $acme = SomeCA::ACME->new(
35 key => $account_key_pem_or_der,
36 key_id => undef,
37 );
38  
39 #for a new account
40 {
41 my $terms_url = $acme->get_terms_of_service();
42  
43 $acme->create_new_account(
44 termsOfServiceAgreed => 1,
45 );
46 }
47  
48 #Save $acme->key_id() somewhere so you can use it again.
49  
50 my $order = $acme->create_new_order(
51 identifiers => [
52 { type => 'dns', value => '*.example.com' },
53 ],
54 );
55  
56 my $authz = $acme->get_authorization( ($order->authorizations())[0] );
57  
58 my @challenges = $authz->challenges();
59  
60 # ... Pick a challenge, and satisfy it.
61  
62 $acme->accept_challenge($challenge);
63  
64 sleep 1 while 'valid' ne $acme->poll_authorization($authz);
65  
66 # ... Make a key and CSR for *.example.com
67  
68 $acme->finalize_order($order, $csr_pem_or_der);
69  
70 while ($order->status() ne 'valid') {
71 sleep 1;
72 $acme->poll_order($order);
73 }
74  
75 my $certificate_url = $order->certificate();
76  
77 # ... Download your certificate! :)
78  
79 See F</examples> in the distribution for more fleshed-out examples.
80  
81 To use L<Let’s Encrypt|http://letsencrypt.org>, see
82 L<Net::ACME2::LetsEncrypt>.
83  
84 =head1 DESCRIPTION
85  
86 This library implements client logic for the L<IETF|https://www.ietf.org>-standard ACME
87 (Automated Certificate Management Environment) protocol. As of this
88 writing, that protocol remains in development; the latest draft will
89 be available from L<https://datatracker.ietf.org/doc/draft-ietf-acme-acme/>.
90  
91 Net::ACME2 derives from L<Net::ACME>, which implements the
92 (significantly different) earlier draft of that protocol as initially
93 deployed by L<Let’s Encrypt|http://letsencrypt.org>.
94  
95 =head1 STATUS
96  
97 This is a beta-grade implementation. While the underlying protocol
98 is L<in use for production|https://community.letsencrypt.org/t/acme-v2-production-environment-wildcards/55578>,
99 it’s still not finalized; consequently, this distribution remains
100 subject to change. It is expected that any further breaking changes
101 will be small, but you still B<MUST> check the changelog before upgrading!
102  
103 =head1 FEATURES
104  
105 =over
106  
107 =item * Support for both ECDSA and RSA encrytion.
108  
109 =item * Support for http-01, dns-01, and tls-alpn-01 challenges.
110  
111 =item * Comprehensive error handling with typed, L<X::Tiny>-based exceptions.
112  
113 =item * This is a pure-Perl solution. Most of its dependencies are
114 either core modules or pure Perl themselves. XS is necessary to
115 communicate with the ACME server via TLS; however, most Perl installations
116 already include the necessary logic (i.e., L<Net::SSLeay>) for TLS.
117  
118 In short, Net::ACME2 will run anywhere that Perl can speak TLS, which is
119 I<almost> everywhere that Perl runs.
120  
121 =back
122  
123 =head1 ERROR HANDLING
124  
125 All thrown exceptions are instances of L<Net::ACME2::X::Base>.
126 Specific error classes aren’t yet defined.
127  
128 =head1 SPEED
129  
130 If you notice speed problems, check to see if your L<Math::BigInt>
131 installation can be made faster.
132  
133 =cut
134  
135 2 ▶use Crypt::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 2 ▶use Crypt::Perl::PK;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 2 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 2 ▶use Net::ACME2::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
140 2 ▶use Net::ACME2::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
141 2 ▶use Net::ACME2::Authorization;
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 2 our $VERSION = '0.21-TRIAL3';
144  
145 use constant {
146 2 _JWK_THUMBPRINT_DIGEST => 'sha256',
147 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
148  
149 # accessed from test
150 2 use constant newAccount_booleans => qw(
151 termsOfServiceAgreed
152 onlyReturnExisting
153 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 # the list of methods that need a “jwk” in their JWS Protected Header
156 # (cf. section 6.2 of the spec)
157 2 use constant FULL_JWT_METHODS => qw(
158 newAccount
159 revokeCert
160 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 =head1 METHODS
163  
164 =head2 I<CLASS>->new( %OPTS )
165  
166 Instantiates an ACME2 object, which you’ll use for all
167 interactions with the ACME server. %OPTS is:
168  
169 =over
170  
171 =item * C<key> - Required. The private key to associate with the ACME2
172 user. Anything that C<Crypt::Perl::PK::parse_key()> can parse is acceptable.
173  
174 =item * C<key_id> - Optional. As returned by C<key_id()>.
175 Saves a round-trip to the ACME2 server, so you should give this
176 if you have it.
177  
178 =item * C<directory> - Optional. A hash reference to use as the
179 directory contents. Saves a round-trip to the ACME2 server, but there’s
180 no built-in logic to determine when the cache goes invalid. Caveat
181 emptor.
182  
183 =back
184  
185 =cut
186  
187 sub new {
188 7 ▶ my ( $class, %opts ) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
189  
190 7 ▶ _die_generic('Need “key”!') if !$opts{'key'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"key"} 0 7 7
191  
192 my $self = {
193 _host => $class->HOST(%opts),
194 _key => $opts{'key'},
195 _key_id => $opts{'key_id'},
196 7 _directory => $opts{'directory'},
197 };
198  
199 7 bless $self, $class;
200  
201 7 $self->_set_ua();
202  
203 7 return $self;
204 }
205  
206 =head2 $id = I<OBJ>->key_id()
207  
208 Returns the object’s cached key ID, either as given at instantiation
209 or as fetched in C<create_new_account()>.
210  
211 =cut
212  
213 sub key_id {
214 12 ▶ my ($self) = @_;
Subroutine key_id: called CC=1 SCAR=0.0
Pod documented
215  
216 12 return $self->{'_key_id'};
217 }
218  
219 =head2 $url = I<OBJ>->get_terms_of_service()
220  
221 Returns the URL for the terms of service.
222  
223 B<NOTE:> For L<Let’s Encrypt|http://letsencrypt.org> you can
224 unofficially resolve against
225 L<https://acme-v01.api.letsencrypt.org/terms> to see the terms
226 of service.
227  
228 =cut
229  
230 sub get_terms_of_service {
231 6 ▶ my ($self) = @_;
Subroutine get_terms_of_service: called CC=4 SCAR=15.0
Pod documented
232  
233 #We want to be able to call this as a class method.
234 6 ▶ if (!ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 6 6
235 0 $self = $self->new();
236 }
237  
238 6 my $dir = $self->_get_directory();
239  
240 # Exceptions here indicate an ACME violation and should be
241 # practically nonexistent.
242 6 ▶ my $url = $dir->{'meta'} or _die_generic('No “meta” in directory!');
Branch: 1 branch
BranchTrueFalseTotal
my $url = $dir->{"meta"} or _die_generic("No \342\200\234meta\342\200\235 in directory!") 0 6 6
243 6 ▶ $url = $url->{'termsOfService'} or _die_generic('No “termsOfService” in directory metadata!');
Branch: 1 branch
BranchTrueFalseTotal
$url = $url->{"termsOfService"} or _die_generic("No \342\200\234termsOfService\342\200\235 in directory metadata!") 0 6 6
244  
245 6 return $url;
246 }
247  
248 =head2 $created_yn = I<OBJ>->create_new_account( %OPTS )
249  
250 Creates a new account using the ACME2 object’s key and the passed
251 %OPTS, which are as described in the ACME2 spec (cf. C<newAccount>).
252 Boolean values may be given as simple Perl booleans.
253  
254 Returns 1 if the account is newly created
255 or 0 if the account already existed.
256  
257 =cut
258  
259 sub create_new_account {
260 12 ▶ my ($self, %opts) = @_;
Subroutine create_new_account: called CC=12 SCAR=26.2
Pod documented
261  
262 12 for my $name (newAccount_booleans()) {
263 24 ▶ next if !exists $opts{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{$name} 18 6 24
264 6 ▶ ($opts{$name} &&= JSON::true()) ||= JSON::false();
Condition33%2/6
($opts{$name} &&= JSON::true()) ||= JSON::false()
l!l&&r!l&&!r
600
$opts{$name} &&= JSON::true()
!ll&&!rl&&r
006
MC/DC0%0/2
($opts{$name} &&= JSON::true()) ||= JSON::false()
($opts{$name} &&= JSON::true()) JSON::false()
MC/DC0%0/2
$opts{$name} &&= JSON::true()
$opts{$name} JSON::true()
Truth table33%1/3
A ||= B
A= ($opts{$name} &&= JSON::true())B= JSON::false()
ABresult
1X1
011
000
Truth table33%1/3
A &&= B
A= $opts{$name}B= JSON::true()
ABresult
0X0
100
111
265 }
266  
267 12 my $resp = $self->_post(
268 'newAccount',
269 \%opts,
270 );
271  
272 12 $self->{'_key_id'} = $resp->header('location');
273  
274 12 $self->{'_ua'}->set_key_id( $self->{'_key_id'} );
275  
276 12 ▶ return 0 if $resp->status() == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $resp->status == 200 6 6 12
277  
278 6 ▶ $resp->die_because_unexpected() if $resp->status() != 201;
Branch: 1 branch
BranchTrueFalseTotal
if $resp->status != 201 0 6 6
279  
280 6 my $struct = $resp->content_struct();
281  
282 6 ▶ if ($struct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($struct) 6 0 6
283 6 for my $name (newAccount_booleans()) {
284 12 ▶ next if !exists $struct->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $struct->{$name} 6 6 12
285 6 ▶ ($struct->{$name} &&= 1) ||= 0;
Condition50%2/4
($struct->{$name} &&= 1) ||= 0
l!l
60
$struct->{$name} &&= 1
!ll
06
MC/DC0%0/1
($struct->{$name} &&= 1) ||= 0
($struct->{$name} &&= 1)
MC/DC0%0/1
$struct->{$name} &&= 1
$struct->{$name}
Truth table50%1/2
A
A= ($struct->{$name} &&= 1)
Aresult
11
00
Truth table50%1/2
A
A= $struct->{$name}
Aresult
00
11
286 }
287 }
288  
289 6 return 1;
290 }
291  
292 #sub update_account {
293 # my ($self, %opts) = @_;
294 #
295 # $self->_require_key_id(\%opts);
296 #
297 # my $set = $self->_post_url(
298 # $opts{'kid'},
299 # \%opts,
300 # );
301 #
302 # return $set;
303 #}
304  
305 =head2 $order = I<OBJ>->create_new_order( %OPTS )
306  
307 Returns a L<Net::ACME2::Order> object. %OPTS is as described in the
308 ACME spec (cf. C<newOrder>). Boolean values may be given as simple
309 Perl booleans.
310  
311 =cut
312  
313 sub create_new_order {
314 0 ▶ my ($self, %opts) = @_;
Subroutine create_new_order: not called CC=2 SCAR=17.9
Pod documented
315  
316 0 $self->_require_key_id(\%opts);
317  
318 0 my $resp = $self->_post( 'newOrder', \%opts );
319  
320 0 ▶ $resp->die_because_unexpected() if $resp->status() != 201;
Branch: 1 branch
BranchTrueFalseTotal
if $resp->status != 201 0 0 0
321  
322 return Net::ACME2::Order->new(
323 id => $resp->header('location'),
324 0 %{ $resp->content_struct() },
325 );
326 }
327  
328 =head2 $authz = I<OBJ>->get_authorization( $URL )
329  
330 Fetches the authorization’s information based on the given $URL
331 and returns a L<Net::ACME2::Authorization> object.
332  
333 The URL is as given by L<Net::ACME2::Order>’s C<authorizations()> method.
334  
335 =cut
336  
337 sub get_authorization {
338 0 ▶ my ($self, $id) = @_;
Subroutine get_authorization: not called CC=1 SCAR=6.9
Pod documented
339  
340 0 my $resp = $self->{'_ua'}->get($id);
341  
342 return Net::ACME2::Authorization->new(
343 id => $id,
344 0 %{ $resp->content_struct() },
345 );
346 }
347  
348 #Server may not support! (Pebble doesn’t, and LE won’t?)
349 #sub create_new_authorization {
350 # my ($self, $type, $value) = @_;
351 #
352 # my %opts = (
353 # identifier => { type => $type, value => $value },
354 # );
355 #
356 # $self->_require_key_id(\%opts);
357 #
358 # return $self->_post( 'newAuthz', \%opts );
359 #}
360  
361 #TODO: separate distribution?
362 #sub __unix2iso {
363 # my ($unix) = @_;
364 #
365 # my (@smhdmy) = gmtime $unix;
366 # $smhdmy[5] += 1900;
367 # $smhdmy[4]++;
368 #
369 # return join( q<>,
370 # join( '-', @smhdmy[ 5, 4, 3 ] ),
371 # 'T',
372 # join( ':', @smhdmy[ 2, 1, 0 ] ),
373 # 'Z',
374 # );
375 #}
376  
377 =head2 $str = I<OBJ>->make_key_authorization( $CHALLENGE )
378  
379 Accepts an instance of L<Net::ACME2::Challenge> (probably a subclass
380 thereof) and returns
381 a key authorization string suitable for handling the given $CHALLENGE.
382 See F</examples> in the distribution for example usage.
383  
384 If you’re using HTTP authorization and are on the same server as the
385 domains’ document roots, then look at the handler logic in
386 L<Net::ACME2::Challenge::http_01> for a potentially simpler way to
387 handle HTTP challenges.
388  
389 =cut
390  
391 sub make_key_authorization {
392 2 ▶ my ($self, $challenge_obj) = @_;
Subroutine make_key_authorization: called CC=2 SCAR=7.1
Pod documented
393  
394 2 ▶ _die_generic('Need a challenge object!') if !$challenge_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $challenge_obj 0 2 2
395  
396 2 return $challenge_obj->token() . '.' . $self->_key_thumbprint();
397 }
398  
399 =head2 I<OBJ>->accept_challenge( CHALLENGE )
400  
401 Signal to the ACME server that the CHALLENGE is ready.
402  
403 =cut
404  
405 sub accept_challenge {
406 0 ▶ my ($self, $challenge_obj) = @_;
Subroutine accept_challenge: not called CC=1 SCAR=6.9
Pod documented
407  
408 0 $self->_post_url(
409 $challenge_obj->url(),
410 {
411 keyAuthorization => $self->make_key_authorization($challenge_obj),
412 },
413 );
414  
415 0 return;
416 }
417  
418 =head2 $status = I<OBJ>->poll_authorization( $AUTHORIZATION )
419  
420 Accepts a L<Net::ACME2::Authorization> instance and polls the
421 ACME server for that authorization’s status. The AUTHORIZATION
422 object is then updated with the results of the poll.
423  
424 As a courtesy, this returns the object’s new C<status()>.
425  
426 =cut
427  
428 #This has to handle updates to the authz and challenge objects
429 2 *poll_authorization = *_poll_order_or_authz;
430  
431 =head2 $status = I<OBJ>->finalize_order( $ORDER, $CSR )
432  
433 Finalizes an order and updates the $ORDER object with the returned
434 status. $CSR may be in either DER or PEM format.
435  
436 As a courtesy, this returns the $ORDER’s C<status()>. If this does
437 not equal C<valid>, then you should probably C<poll_order()>
438 until it does.
439  
440 =cut
441  
442 sub finalize_order {
443 0 ▶ my ($self, $order_obj, $csr) = @_;
Subroutine finalize_order: not called CC=2 SCAR=17.9
Pod documented
444  
445 0 my $csr_der;
446 0 ▶ if (index($csr, '-----') == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($csr, '-----') == 0) { } 0 0 0
447 0 $csr_der = Crypt::Format::pem2der($csr);
448 }
449 else {
450 0 $csr_der = $csr;
451 }
452  
453 0 $csr = MIME::Base64::encode_base64url($csr_der);
454  
455 0 my $post = $self->_post_url(
456 $order_obj->finalize(),
457 {
458 csr => $csr,
459 },
460 );
461  
462 0 my $content = $post->content_struct();
463  
464 0 $order_obj->update($content);
465  
466 0 return $order_obj->status();
467 }
468  
469 =head2 $status = I<OBJ>->poll_order( $ORDER )
470  
471 Like C<poll_authorization()> but handles a
472 L<Net::ACME2::Order> object instead.
473  
474 =cut
475  
476 2 *poll_order = *_poll_order_or_authz;
477  
478 #----------------------------------------------------------------------
479  
480 sub _key_thumbprint {
481 2 ▶ my ($self) = @_;
Subroutine _key_thumbprint: called CC=2 SCAR=7.1
482  
483 2 ▶ return $self->{'_key_thumbprint'} ||= $self->_key_obj()->get_jwk_thumbprint( _JWK_THUMBPRINT_DIGEST() );
Condition66%2/3
$self->{"_key_thumbprint"} ||= $self->_key_obj->get_jwk_thumbprint("sha256")
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->{"_key_thumbprint"} ||= $self->_key_obj->get_jwk_thumbprint("sha256")
$self->{"_key_thumbprint"} $self->_key_obj->get_jwk_thumbprint("sha256")
Truth table66%2/3
A ||= B
A= $self->{"_key_thumbprint"}B= $self->_key_obj->get_jwk_thumbprint("sha256")
ABresult
1X1
011
000
484 }
485  
486 sub _get_directory {
487 30 ▶ my ($self) = @_;
Subroutine _get_directory: called CC=3 SCAR=11.3
488  
489 30 ▶ $self->{'_directory'} ||= do {
Condition66%2/3
$self->{"_directory"} ||= do { my $dir_path = $self->DIRECTORY_PATH; $self->{"_ua"}->get(qq[https://$self->{"_host"}$dir_path])->content_struct }
l!l&&r!l&&!r
2460
MC/DC0%0/2
$self->{"_directory"} ||= do { my $dir_path = $self->DIRECTORY_PATH; $self->{"_ua"}->get(qq[https://$self->{"_host"}$dir_path])->content_struct }
$self->{"_directory"} do { my $dir_path = $self->DIRECTORY_PATH; $self->{"_ua"}->get(qq[https://$self->{"_host"}$dir_path])->content_struct }
Truth table66%2/3
A ||= B
A= $self->{"_directory"}B= do { my $dir_path = $self->DIRECTORY_PATH; $self->{"_ua"}->get(qq[https://$self->{"_host"}$dir_path])->content_struct }
ABresult
1X1
011
000
490 6 my $dir_path = $self->DIRECTORY_PATH();
491 6 $self->{'_ua'}->get("https://$self->{'_host'}$dir_path")->content_struct();
492 };
493  
494 30 ▶ my $new_nonce_url = $self->{'_directory'}{'newNonce'} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $new_nonce_url = $self->{"_directory"}{"newNonce"} or do { _die_generic("Directory is missing \342\200\234newNonce\342\200\235.") } 0 30 30
495 0 _die_generic('Directory is missing “newNonce”.');
496 };
497  
498 30 $self->{'_ua'}->set_new_nonce_url( $new_nonce_url );
499  
500 30 return $self->{'_directory'};
501 }
502  
503 sub _require_key_id {
504 0 ▶ my ($self, $opts_hr) = @_;
Subroutine _require_key_id: not called CC=2 SCAR=17.9
505  
506 0 ▶ $opts_hr->{'_key_id'} = $self->{'_key_id'} or do {
Branch: 1 branch
BranchTrueFalseTotal
$opts_hr->{"_key_id"} = $self->{"_key_id"} or do { _die_generic("No key ID has been set. Either pass \342\200\234key_id\342\200\235 to new(), or create_new_account().") } 0 0 0
507 0 _die_generic('No key ID has been set. Either pass “key_id” to new(), or create_new_account().');
508 };
509  
510 return
511 0 }
512  
513 sub _poll_order_or_authz {
514 0 ▶ my ($self, $order_or_authz_obj) = @_;
Subroutine _poll_order_or_authz: not called CC=1 SCAR=6.9
515  
516 0 my $get = $self->{'_ua'}->get( $order_or_authz_obj->id() );
517  
518 0 my $content = $get->content_struct();
519  
520 0 $order_or_authz_obj->update($content);
521  
522 0 return $order_or_authz_obj->status();
523 }
524  
525 sub _key_obj {
526 8 ▶ my ($self) = @_;
Subroutine _key_obj: called CC=2 SCAR=7.1
527  
528 8 ▶ return $self->{'_key_obj'} ||= Crypt::Perl::PK::parse_key($self->{'_key'});
Condition66%2/3
$self->{"_key_obj"} ||= Crypt::Perl::PK::parse_key($self->{"_key"})
l!l&&r!l&&!r
170
MC/DC0%0/2
$self->{"_key_obj"} ||= Crypt::Perl::PK::parse_key($self->{"_key"})
$self->{"_key_obj"} Crypt::Perl::PK::parse_key($self->{"_key"})
Truth table66%2/3
A ||= B
A= $self->{"_key_obj"}B= Crypt::Perl::PK::parse_key($self->{"_key"})
ABresult
1X1
011
000
529 }
530  
531 sub _set_ua {
532 7 ▶ my ($self) = @_;
Subroutine _set_ua: called CC=1 SCAR=0.0
533  
534 $self->{'_ua'} = Net::ACME2::HTTP->new(
535 key => $self->_key_obj(),
536 7 key_id => $self->{'_key_id'},
537 );
538  
539 7 return;
540 }
541  
542 2 our $_POST_METHOD;
543  
544 sub _post {
545 12 ▶ my ( $self, $link_name, $data ) = @_;
Subroutine _post: called CC=3 SCAR=11.2
546  
547 12 my $post_method;
548 12 ▶ $post_method = 'post_full_jwt' if grep { $link_name eq $_ } FULL_JWT_METHODS();
Branch: 1 branch
BranchTrueFalseTotal
if grep {$link_name eq $_;} ("newAccount", "revokeCert") 12 0 12
549  
550 # Since the $link_name will come from elsewhere in this module
551 # there really shouldn’t be an error here, but just in case.
552 12 ▶ my $url = $self->_get_directory()->{$link_name} or _die_generic("Unknown link name: “$link_name”");
Branch: 1 branch
BranchTrueFalseTotal
my $url = $self->_get_directory->{$link_name} or _die_generic("Unknown link name: \342\200\234$link_name\342\200\235") 0 12 12
553  
554 12 return $self->_post_url( $url, $data, $post_method );
555 }
556  
557 sub _post_url {
558 12 ▶ my ( $self, $url, $data, $opt_post_method ) = @_;
Subroutine _post_url: called CC=2 SCAR=7.0
559  
560 #Do this in case we haven’t initialized the directory yet.
561 #Initializing the directory is necessary to get a nonce.
562 12 $self->_get_directory();
563  
564 12 ▶ my $post_method = $opt_post_method || 'post_key_id';
Condition50%1/2
$opt_post_method || 'post_key_id'
l!l
120
MC/DC0%0/1
$opt_post_method || 'post_key_id'
$opt_post_method
Truth table50%1/2
A
A= $opt_post_method
Aresult
11
00
565  
566 12 return $self->{'_ua'}->$post_method( $url, $data );
567 }
568  
569 sub _die_generic {
570 0 ▶ die Net::ACME2::X->create('Generic', @_);
Subroutine _die_generic: not called CC=1 SCAR=6.9
571 }
572  
573 2 1;
574  
575 =head1 TODO
576  
577 =over
578  
579 =item * Add pre-authorization support if there is ever a production
580 use for it.
581  
582 =item * Expose the Retry-After header via the module API.
583  
584 =item * Add (more) tests.
585  
586 =back
587  
588 =head1 SEE ALSO
589  
590 L<Crypt::Perl> provides pure-Perl cryptography for this library. See the
591 present library distribution’s F</examples> directory for sample usage
592 to generate keys and CSRs.
593  
594 =cut
↑ Summary ACME2/HTTP.pm »