| 1 | package Net::ACME2; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | 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_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_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 | 3 | ▶ | use Crypt::Format; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | use Crypt::Perl::PK; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | use Net::ACME2::HTTP; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | use Net::ACME2::Order; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 141 | 3 | ▶ | use Net::ACME2::Authorization; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||
| 143 | 3 | our $VERSION = '0.23'; | |||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | use constant { | ||||||||||||||||||||||||||||||||||||||
| 146 | 3 | _JWK_THUMBPRINT_DIGEST => 'sha256', | |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | _HTTP_OK => 200, | ||||||||||||||||||||||||||||||||||||||
| 149 | _HTTP_CREATED => 201, | ||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||
| 152 | # accessed from test | ||||||||||||||||||||||||||||||||||||||
| 153 | 3 | use constant newAccount_booleans => qw( | |||||||||||||||||||||||||||||||||||||
| 154 | termsOfServiceAgreed | ||||||||||||||||||||||||||||||||||||||
| 155 | onlyReturnExisting | ||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | # the list of methods that need a “jwk” in their JWS Protected Header | ||||||||||||||||||||||||||||||||||||||
| 159 | # (cf. section 6.2 of the spec) | ||||||||||||||||||||||||||||||||||||||
| 160 | 3 | use constant FULL_JWT_METHODS => qw( | |||||||||||||||||||||||||||||||||||||
| 161 | newAccount | ||||||||||||||||||||||||||||||||||||||
| 162 | revokeCert | ||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | =head2 I<CLASS>->new( %OPTS ) | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | Instantiates an ACME2 object, which you’ll use for all | ||||||||||||||||||||||||||||||||||||||
| 170 | interactions with the ACME server. %OPTS is: | ||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | =over | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | =item * C<key> - Required. The private key to associate with the ACME2 | ||||||||||||||||||||||||||||||||||||||
| 175 | user. Anything that C<Crypt::Perl::PK::parse_key()> can parse is acceptable. | ||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | =item * C<key_id> - Optional. As returned by C<key_id()>. | ||||||||||||||||||||||||||||||||||||||
| 178 | Saves a round-trip to the ACME2 server, so you should give this | ||||||||||||||||||||||||||||||||||||||
| 179 | if you have it. | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | =item * C<directory> - Optional. A hash reference to use as the | ||||||||||||||||||||||||||||||||||||||
| 182 | directory contents. Saves a round-trip to the ACME2 server, but there’s | ||||||||||||||||||||||||||||||||||||||
| 183 | no built-in logic to determine when the cache goes invalid. Caveat | ||||||||||||||||||||||||||||||||||||||
| 184 | emptor. | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | =back | ||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 191 | 13 | ▶ | my ( $class, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 13 | ▶ | _die_generic('Need “key”!') if !$opts{'key'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | my $self = { | ||||||||||||||||||||||||||||||||||||||
| 196 | _host => $class->HOST(%opts), | ||||||||||||||||||||||||||||||||||||||
| 197 | _key => $opts{'key'}, | ||||||||||||||||||||||||||||||||||||||
| 198 | _key_id => $opts{'key_id'}, | ||||||||||||||||||||||||||||||||||||||
| 199 | 13 | _directory => $opts{'directory'}, | |||||||||||||||||||||||||||||||||||||
| 200 | }; | ||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||
| 202 | 13 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | 13 | $self->_set_ua(); | |||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | =head2 $id = I<OBJ>->key_id() | ||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||
| 211 | Returns the object’s cached key ID, either as given at instantiation | ||||||||||||||||||||||||||||||||||||||
| 212 | or as fetched in C<create_account()>. | ||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | sub key_id { | ||||||||||||||||||||||||||||||||||||||
| 217 | 24 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
key_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | 24 | return $self->{'_key_id'}; | |||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||
| 222 | =head2 $url = I<OBJ>->get_terms_of_service() | ||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||
| 224 | Returns the URL for the terms of service. | ||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | B<NOTE:> For L<Let’s Encrypt|http://letsencrypt.org> you can | ||||||||||||||||||||||||||||||||||||||
| 227 | unofficially resolve against | ||||||||||||||||||||||||||||||||||||||
| 228 | L<https://acme-v01.api.letsencrypt.org/terms> to see the terms | ||||||||||||||||||||||||||||||||||||||
| 229 | of service. | ||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | sub get_terms_of_service { | ||||||||||||||||||||||||||||||||||||||
| 234 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_terms_of_service: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | #We want to be able to call this as a class method. | ||||||||||||||||||||||||||||||||||||||
| 237 | 12 | ▶ | if (!ref $self) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $self = $self->new(); | |||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||
| 241 | 12 | my $dir = $self->_get_directory(); | |||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | # Exceptions here indicate an ACME violation and should be | ||||||||||||||||||||||||||||||||||||||
| 244 | # practically nonexistent. | ||||||||||||||||||||||||||||||||||||||
| 245 | 12 | ▶ | my $url = $dir->{'meta'} or _die_generic('No “meta” in directory!'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 246 | 12 | ▶ | $url = $url->{'termsOfService'} or _die_generic('No “termsOfService” in directory metadata!'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||
| 248 | 12 | return $url; | |||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||
| 251 | =head2 $created_yn = I<OBJ>->create_account( %OPTS ) | ||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | Creates an account using the ACME2 object’s key and the passed | ||||||||||||||||||||||||||||||||||||||
| 254 | %OPTS, which are as described in the ACME2 spec (cf. C<newAccount>). | ||||||||||||||||||||||||||||||||||||||
| 255 | Boolean values may be given as simple Perl booleans. | ||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | Returns 1 if the account is newly created | ||||||||||||||||||||||||||||||||||||||
| 258 | or 0 if the account already existed. | ||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||
| 260 | NB: C<create_new_account()> is an alias for this method. | ||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | =cut | ||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||
| 264 | sub create_account { | ||||||||||||||||||||||||||||||||||||||
| 265 | 24 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_account: called CC=12 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||
| 267 | 24 | for my $name (newAccount_booleans()) { | |||||||||||||||||||||||||||||||||||||
| 268 | 48 | ▶ | next if !exists $opts{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 269 | 12 | ▶ | ($opts{$name} &&= JSON::true()) ||= JSON::false(); | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
($opts{$name} &&= JSON::true()) ||= JSON::false()
$opts{$name} &&= JSON::true()
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()
Truth table33%1/3
A &&= B
A= $opts{$name}B= JSON::true()
| |||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | 24 | my $resp = $self->_post( | |||||||||||||||||||||||||||||||||||||
| 273 | 'newAccount', | ||||||||||||||||||||||||||||||||||||||
| 274 | \%opts, | ||||||||||||||||||||||||||||||||||||||
| 275 | ); | ||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | 24 | $self->{'_key_id'} = $resp->header('location'); | |||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||
| 279 | 24 | $self->{'_ua'}->set_key_id( $self->{'_key_id'} ); | |||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | 24 | ▶ | return 0 if $resp->status() == _HTTP_OK; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | 12 | ▶ | $resp->die_because_unexpected() if $resp->status() != _HTTP_CREATED; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||
| 285 | 12 | my $struct = $resp->content_struct(); | |||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | 12 | ▶ | if ($struct) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 288 | 12 | for my $name (newAccount_booleans()) { | |||||||||||||||||||||||||||||||||||||
| 289 | 24 | ▶ | next if !exists $struct->{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 290 | 12 | ▶ | ($struct->{$name} &&= 1) ||= 0; | ||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
($struct->{$name} &&= 1) ||= 0
$struct->{$name} &&= 1
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)
Truth table50%1/2
A
A= $struct->{$name}
| |||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||
| 294 | 12 | return 1; | |||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | #sub update_account { | ||||||||||||||||||||||||||||||||||||||
| 298 | # my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||
| 299 | # | ||||||||||||||||||||||||||||||||||||||
| 300 | # $self->_require_key_id(\%opts); | ||||||||||||||||||||||||||||||||||||||
| 301 | # | ||||||||||||||||||||||||||||||||||||||
| 302 | # my $set = $self->_post_url( | ||||||||||||||||||||||||||||||||||||||
| 303 | # $opts{'kid'}, | ||||||||||||||||||||||||||||||||||||||
| 304 | # \%opts, | ||||||||||||||||||||||||||||||||||||||
| 305 | # ); | ||||||||||||||||||||||||||||||||||||||
| 306 | # | ||||||||||||||||||||||||||||||||||||||
| 307 | # return $set; | ||||||||||||||||||||||||||||||||||||||
| 308 | #} | ||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||
| 310 | =head2 $order = I<OBJ>->create_order( %OPTS ) | ||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||
| 312 | Returns a L<Net::ACME2::Order> object. %OPTS is as described in the | ||||||||||||||||||||||||||||||||||||||
| 313 | ACME spec (cf. C<newOrder>). Boolean values may be given as simple | ||||||||||||||||||||||||||||||||||||||
| 314 | Perl booleans. | ||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | NB: C<create_new_order()> is an alias for this method. | ||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | sub create_order { | ||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_order: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $self->_require_key_id(\%opts); | |||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $resp = $self->_post( 'newOrder', \%opts ); | |||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $resp->die_because_unexpected() if $resp->status() != _HTTP_CREATED; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||
| 329 | return Net::ACME2::Order->new( | ||||||||||||||||||||||||||||||||||||||
| 330 | id => $resp->header('location'), | ||||||||||||||||||||||||||||||||||||||
| 331 | 0 | %{ $resp->content_struct() }, | |||||||||||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | =head2 $authz = I<OBJ>->get_authorization( $URL ) | ||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | Fetches the authorization’s information based on the given $URL | ||||||||||||||||||||||||||||||||||||||
| 338 | and returns a L<Net::ACME2::Authorization> object. | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | The URL is as given by L<Net::ACME2::Order>’s C<authorizations()> method. | ||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||
| 342 | =cut | ||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||
| 344 | sub get_authorization { | ||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_authorization: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $resp = $self->{'_ua'}->get($id); | |||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | return Net::ACME2::Authorization->new( | ||||||||||||||||||||||||||||||||||||||
| 350 | id => $id, | ||||||||||||||||||||||||||||||||||||||
| 351 | 0 | %{ $resp->content_struct() }, | |||||||||||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||
| 355 | #Server may not support! (Pebble doesn’t, and LE won’t?) | ||||||||||||||||||||||||||||||||||||||
| 356 | #sub create_authorization { | ||||||||||||||||||||||||||||||||||||||
| 357 | # my ($self, $type, $value) = @_; | ||||||||||||||||||||||||||||||||||||||
| 358 | # | ||||||||||||||||||||||||||||||||||||||
| 359 | # my %opts = ( | ||||||||||||||||||||||||||||||||||||||
| 360 | # identifier => { type => $type, value => $value }, | ||||||||||||||||||||||||||||||||||||||
| 361 | # ); | ||||||||||||||||||||||||||||||||||||||
| 362 | # | ||||||||||||||||||||||||||||||||||||||
| 363 | # $self->_require_key_id(\%opts); | ||||||||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||||||||
| 365 | # return $self->_post( 'newAuthz', \%opts ); | ||||||||||||||||||||||||||||||||||||||
| 366 | #} | ||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | #TODO: separate distribution? | ||||||||||||||||||||||||||||||||||||||
| 369 | #sub __unix2iso { | ||||||||||||||||||||||||||||||||||||||
| 370 | # my ($unix) = @_; | ||||||||||||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||||||||||||
| 372 | # my (@smhdmy) = gmtime $unix; | ||||||||||||||||||||||||||||||||||||||
| 373 | # $smhdmy[5] += 1900; | ||||||||||||||||||||||||||||||||||||||
| 374 | # $smhdmy[4]++; | ||||||||||||||||||||||||||||||||||||||
| 375 | # | ||||||||||||||||||||||||||||||||||||||
| 376 | # return join( q<>, | ||||||||||||||||||||||||||||||||||||||
| 377 | # join( '-', @smhdmy[ 5, 4, 3 ] ), | ||||||||||||||||||||||||||||||||||||||
| 378 | # 'T', | ||||||||||||||||||||||||||||||||||||||
| 379 | # join( ':', @smhdmy[ 2, 1, 0 ] ), | ||||||||||||||||||||||||||||||||||||||
| 380 | # 'Z', | ||||||||||||||||||||||||||||||||||||||
| 381 | # ); | ||||||||||||||||||||||||||||||||||||||
| 382 | #} | ||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | =head2 $str = I<OBJ>->make_key_authorization( $CHALLENGE ) | ||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | Accepts an instance of L<Net::ACME2::Challenge> (probably a subclass | ||||||||||||||||||||||||||||||||||||||
| 387 | thereof) and returns | ||||||||||||||||||||||||||||||||||||||
| 388 | a key authorization string suitable for handling the given $CHALLENGE. | ||||||||||||||||||||||||||||||||||||||
| 389 | See F</examples> in the distribution for example usage. | ||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||
| 391 | If you’re using HTTP authorization and are on the same server as the | ||||||||||||||||||||||||||||||||||||||
| 392 | domains’ document roots, then look at the handler logic in | ||||||||||||||||||||||||||||||||||||||
| 393 | L<Net::ACME2::Challenge::http_01> for a potentially simpler way to | ||||||||||||||||||||||||||||||||||||||
| 394 | handle HTTP challenges. | ||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||
| 396 | =cut | ||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||
| 398 | sub make_key_authorization { | ||||||||||||||||||||||||||||||||||||||
| 399 | 2 | ▶ | my ($self, $challenge_obj) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
make_key_authorization: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | 2 | ▶ | _die_generic('Need a challenge object!') if !$challenge_obj; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||
| 403 | 2 | return $challenge_obj->token() . '.' . $self->_key_thumbprint(); | |||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||
| 406 | =head2 I<OBJ>->accept_challenge( CHALLENGE ) | ||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||
| 408 | Signal to the ACME server that the CHALLENGE is ready. | ||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||
| 410 | =cut | ||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||
| 412 | sub accept_challenge { | ||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | my ($self, $challenge_obj) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_challenge: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $self->_post_url( | |||||||||||||||||||||||||||||||||||||
| 416 | $challenge_obj->url(), | ||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||
| 418 | keyAuthorization => $self->make_key_authorization($challenge_obj), | ||||||||||||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||||||||||||
| 420 | ); | ||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | =head2 $status = I<OBJ>->poll_authorization( $AUTHORIZATION ) | ||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | Accepts a L<Net::ACME2::Authorization> instance and polls the | ||||||||||||||||||||||||||||||||||||||
| 428 | ACME server for that authorization’s status. The AUTHORIZATION | ||||||||||||||||||||||||||||||||||||||
| 429 | object is then updated with the results of the poll. | ||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | As a courtesy, this returns the object’s new C<status()>. | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | #This has to handle updates to the authz and challenge objects | ||||||||||||||||||||||||||||||||||||||
| 436 | 3 | *poll_authorization = *_poll_order_or_authz; | |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | =head2 $status = I<OBJ>->finalize_order( $ORDER, $CSR ) | ||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | Finalizes an order and updates the $ORDER object with the returned | ||||||||||||||||||||||||||||||||||||||
| 441 | status. $CSR may be in either DER or PEM format. | ||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||
| 443 | As a courtesy, this returns the $ORDER’s C<status()>. If this does | ||||||||||||||||||||||||||||||||||||||
| 444 | not equal C<valid>, then you should probably C<poll_order()> | ||||||||||||||||||||||||||||||||||||||
| 445 | until it does. | ||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||
| 447 | =cut | ||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||
| 449 | sub finalize_order { | ||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | my ($self, $order_obj, $csr) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize_order: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $csr_der; | |||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if (index($csr, '-----') == 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $csr_der = Crypt::Format::pem2der($csr); | |||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||
| 456 | else { | ||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $csr_der = $csr; | |||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $csr = MIME::Base64::encode_base64url($csr_der); | |||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $post = $self->_post_url( | |||||||||||||||||||||||||||||||||||||
| 463 | $order_obj->finalize(), | ||||||||||||||||||||||||||||||||||||||
| 464 | { | ||||||||||||||||||||||||||||||||||||||
| 465 | csr => $csr, | ||||||||||||||||||||||||||||||||||||||
| 466 | }, | ||||||||||||||||||||||||||||||||||||||
| 467 | ); | ||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my $content = $post->content_struct(); | |||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $order_obj->update($content); | |||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return $order_obj->status(); | |||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||
| 476 | =head2 $status = I<OBJ>->poll_order( $ORDER ) | ||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||
| 478 | Like C<poll_authorization()> but handles a | ||||||||||||||||||||||||||||||||||||||
| 479 | L<Net::ACME2::Order> object instead. | ||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||
| 481 | =cut | ||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||
| 483 | 3 | *poll_order = *_poll_order_or_authz; | |||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||
| 485 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | sub _key_thumbprint { | ||||||||||||||||||||||||||||||||||||||
| 488 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_key_thumbprint: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||
| 490 | 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")
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")
| |||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||
| 493 | sub _get_directory { | ||||||||||||||||||||||||||||||||||||||
| 494 | 60 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_directory: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||
| 496 | 60 | ▶ | $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
}
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
}
| |||||||||||||||||||||||||||||||||||||||
| 497 | 12 | my $dir_path = $self->DIRECTORY_PATH(); | |||||||||||||||||||||||||||||||||||||
| 498 | 12 | $self->{'_ua'}->get("https://$self->{'_host'}$dir_path")->content_struct(); | |||||||||||||||||||||||||||||||||||||
| 499 | }; | ||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||
| 501 | 60 | ▶ | my $new_nonce_url = $self->{'_directory'}{'newNonce'} or do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 502 | 0 | _die_generic('Directory is missing “newNonce”.'); | |||||||||||||||||||||||||||||||||||||
| 503 | }; | ||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | 60 | $self->{'_ua'}->set_new_nonce_url( $new_nonce_url ); | |||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||
| 507 | 60 | return $self->{'_directory'}; | |||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||
| 510 | sub _require_key_id { | ||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | my ($self, $opts_hr) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_key_id: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | $opts_hr->{'_key_id'} = $self->{'_key_id'} or do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 514 | 0 | _die_generic('No key ID has been set. Either pass “key_id” to new(), or create_account().'); | |||||||||||||||||||||||||||||||||||||
| 515 | }; | ||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||
| 517 | return | ||||||||||||||||||||||||||||||||||||||
| 518 | 0 | } | |||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||
| 520 | sub _poll_order_or_authz { | ||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | my ($self, $order_or_authz_obj) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_poll_order_or_authz: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my $get = $self->{'_ua'}->get( $order_or_authz_obj->id() ); | |||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $content = $get->content_struct(); | |||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $order_or_authz_obj->update($content); | |||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return $order_or_authz_obj->status(); | |||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||
| 532 | sub _key_obj { | ||||||||||||||||||||||||||||||||||||||
| 533 | 14 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_key_obj: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||
| 535 | 14 | ▶ | return $self->{'_key_obj'} ||= Crypt::Perl::PK::parse_key($self->{'_key'}); | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_key_obj"} ||= Crypt::Perl::PK::parse_key($self->{"_key"})
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"})
| |||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||
| 538 | sub _set_ua { | ||||||||||||||||||||||||||||||||||||||
| 539 | 13 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_ua: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||
| 541 | $self->{'_ua'} = Net::ACME2::HTTP->new( | ||||||||||||||||||||||||||||||||||||||
| 542 | key => $self->_key_obj(), | ||||||||||||||||||||||||||||||||||||||
| 543 | 13 | key_id => $self->{'_key_id'}, | |||||||||||||||||||||||||||||||||||||
| 544 | ); | ||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||
| 546 | 13 | return; | |||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||
| 549 | 3 | our $_POST_METHOD; | |||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||
| 551 | sub _post { | ||||||||||||||||||||||||||||||||||||||
| 552 | 24 | ▶ | my ( $self, $link_name, $data ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_post: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||
| 554 | 24 | my $post_method; | |||||||||||||||||||||||||||||||||||||
| 555 | 24 | ▶ | $post_method = 'post_full_jwt' if grep { $link_name eq $_ } FULL_JWT_METHODS(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||
| 557 | # Since the $link_name will come from elsewhere in this module | ||||||||||||||||||||||||||||||||||||||
| 558 | # there really shouldn’t be an error here, but just in case. | ||||||||||||||||||||||||||||||||||||||
| 559 | 24 | ▶ | my $url = $self->_get_directory()->{$link_name} or _die_generic("Unknown link name: “$link_name”"); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||
| 561 | 24 | return $self->_post_url( $url, $data, $post_method ); | |||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||
| 564 | sub _post_url { | ||||||||||||||||||||||||||||||||||||||
| 565 | 24 | ▶ | my ( $self, $url, $data, $opt_post_method ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_post_url: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||
| 567 | #Do this in case we haven’t initialized the directory yet. | ||||||||||||||||||||||||||||||||||||||
| 568 | #Initializing the directory is necessary to get a nonce. | ||||||||||||||||||||||||||||||||||||||
| 569 | 24 | $self->_get_directory(); | |||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||
| 571 | 24 | ▶ | my $post_method = $opt_post_method || 'post_key_id'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt_post_method || 'post_key_id'
MC/DC0%0/1
$opt_post_method || 'post_key_id'
$opt_post_method
Truth table50%1/2
A
A= $opt_post_method
| |||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||
| 573 | 24 | return $self->{'_ua'}->$post_method( $url, $data ); | |||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||
| 576 | sub _die_generic { | ||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | die Net::ACME2::X->create('Generic', @_); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_die_generic: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||
| 580 | #legacy aliases | ||||||||||||||||||||||||||||||||||||||
| 581 | 3 | *create_new_account = \*create_account; | |||||||||||||||||||||||||||||||||||||
| 582 | 3 | *create_new_order = \*create_order; | |||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||
| 584 | 3 | 1; | |||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||
| 586 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||
| 588 | =over | ||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||
| 590 | =item * Add pre-authorization support if there is ever a production | ||||||||||||||||||||||||||||||||||||||
| 591 | use for it. | ||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||
| 593 | =item * Expose the Retry-After header via the module API. | ||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||
| 595 | =item * Add (more) tests. | ||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||
| 597 | =back | ||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||
| 601 | L<Crypt::Perl> provides pure-Perl cryptography for this library. See the | ||||||||||||||||||||||||||||||||||||||
| 602 | present library distribution’s F</examples> directory for sample usage | ||||||||||||||||||||||||||||||||||||||
| 603 | to generate keys and CSRs. | ||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||
| 605 | =cut | ||||||||||||||||||||||||||||||||||||||