| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::ACME2::Error; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =encoding utf-8 | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Net::ACME2::Error - error parsing logic for ACME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | use Net::ACME2::Error; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | my $err = Net::ACME2::Error->new( { type => '..', .. } ); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | This simple module interfaces with ACME2 “error” objects, | 
| 18 |  |  |  |  |  |  | which are described in the ACME protocol specification. | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head1 NOTES | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | ACME’s errors are basically just HTTP API problem detail documents, | 
| 23 |  |  |  |  |  |  | which are described in more detail at L. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 6 |  |  | 6 |  | 118736 | use strict; | 
|  | 6 |  |  |  |  | 24 |  | 
|  | 6 |  |  |  |  | 176 |  | 
| 28 | 6 |  |  | 6 |  | 31 | use warnings; | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 163 |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 6 |  |  | 6 |  | 495 | use parent qw( Net::ACME2::AccessorBase ); | 
|  | 6 |  |  |  |  | 302 |  | 
|  | 6 |  |  |  |  | 45 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 6 |  |  | 6 |  | 2204 | use Call::Context (); | 
|  | 6 |  |  |  |  | 1552 |  | 
|  | 6 |  |  |  |  | 217 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | my $URN_PREFIX = 'urn:ietf:params:acme:error:'; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 6 |  |  |  |  | 798 | use constant _ACCESSORS => qw( | 
| 37 |  |  |  |  |  |  | detail | 
| 38 |  |  |  |  |  |  | instance | 
| 39 |  |  |  |  |  |  | status | 
| 40 |  |  |  |  |  |  | title | 
| 41 |  |  |  |  |  |  | type | 
| 42 | 6 |  |  | 6 |  | 38 | ); | 
|  | 6 |  |  |  |  | 11 |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | #cf. https://ietf-wg-acme.github.io/acme/#errors | 
| 45 | 6 |  |  |  |  | 2588 | use constant _TYPE_DESCRIPTION => { | 
| 46 |  |  |  |  |  |  | badCSR                => 'The CSR is unacceptable (e.g., due to a short key)', | 
| 47 |  |  |  |  |  |  | badNonce              => 'The client sent an unacceptable anti-replay nonce', | 
| 48 |  |  |  |  |  |  | badSignatureAlgorithm => 'The JWS was signed with an algorithm the server does not support', | 
| 49 |  |  |  |  |  |  | invalidContact        => 'A contact URL for an account was invalid', | 
| 50 |  |  |  |  |  |  | unsupportedContact        => 'A contact URL for an account used an unsupported protocol scheme', | 
| 51 |  |  |  |  |  |  | accountDoesNotExist   => 'The request specified an account that does not exist', | 
| 52 |  |  |  |  |  |  | malformed             => 'The request message was malformed', | 
| 53 |  |  |  |  |  |  | rateLimited           => 'The request exceeds a rate limit', | 
| 54 |  |  |  |  |  |  | rejectedIdentifier    => 'The server will not issue for the identifier', | 
| 55 |  |  |  |  |  |  | serverInternal        => 'The server experienced an internal error', | 
| 56 |  |  |  |  |  |  | unauthorized          => 'The client lacks sufficient authorization', | 
| 57 |  |  |  |  |  |  | unsupportedIdentifier => 'Identifier is not supported, but may be in the future', | 
| 58 |  |  |  |  |  |  | userActionRequired => 'Visit the “instance” URL and take actions specified there', | 
| 59 |  |  |  |  |  |  | badRevocationReason => 'The revocation reason provided is not allowed by the server', | 
| 60 |  |  |  |  |  |  | dns => 'There was a problem with a DNS query', | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | connection            => 'The server could not connect to a validation target', | 
| 63 |  |  |  |  |  |  | dnssec                => 'The server could not validate a DNSSEC signed domain', | 
| 64 |  |  |  |  |  |  | caa                   => 'CAA records forbid the CA from issuing', | 
| 65 |  |  |  |  |  |  | tls                   => 'The server received a TLS error during validation', | 
| 66 |  |  |  |  |  |  | incorrectResponse     => 'Response received didn’t match the challenge’s requirements', | 
| 67 | 6 |  |  | 6 |  | 42 | }; | 
|  | 6 |  |  |  |  | 14 |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 ACCESSORS | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =over | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =item * C | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =item * C | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =item * C | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =item * C | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =item * C - defaults to C | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =item * C - text description of the C | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =item * C - list of subproblem objects | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =item * C - human-readable description of the error | 
| 88 |  |  |  |  |  |  | (including subproblems) | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =back | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =cut | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub type { | 
| 95 | 21 |  |  | 21 | 1 | 64 | my ($self) = @_; | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 21 |  | 100 |  |  | 85 | return $self->SUPER::type() || 'about:blank'; | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | sub description { | 
| 101 | 10 |  |  | 10 | 1 | 17 | my ($self) = @_; | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 10 |  |  |  |  | 18 | my $type = $self->type(); | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 10 |  |  |  |  | 69 | $type =~ s<\A$URN_PREFIX><>; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 10 |  |  |  |  | 26 | return _TYPE_DESCRIPTION()->{$type}; | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | sub subproblems { | 
| 111 | 11 |  |  | 11 | 1 | 21 | my ($self) = @_; | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 11 |  |  |  |  | 32 | Call::Context::must_be_list(); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 11 | 100 |  |  |  | 122 | my $subs_ar = $self->{'_subproblems'} or return; | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 3 |  |  |  |  | 6 | return map { Net::ACME2::Error::Subproblem->new(%$_) } @$subs_ar; | 
|  | 6 |  |  |  |  | 26 |  | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | sub to_string { | 
| 121 | 10 |  |  | 10 | 1 | 39 | my ($self) = @_; | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 10 |  |  |  |  | 50 | my $str = join( q< >, grep { defined } $self->status(), $self->type() ); | 
|  | 20 |  |  |  |  | 47 |  | 
| 124 |  |  |  |  |  |  |  | 
| 125 | 10 |  |  |  |  | 25 | for my $attribute ( qw( title description detail instance ) ) { | 
| 126 | 40 |  |  |  |  | 144 | my $value = $self->$attribute(); | 
| 127 | 40 | 100 | 66 |  |  | 115 | if ( defined $value && length $value ) { | 
| 128 | 6 |  |  |  |  | 21 | $str .= " ($value)"; | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 10 |  |  |  |  | 33 | my @subs = $self->subproblems(); | 
| 133 | 10 | 100 |  |  |  | 23 | if (@subs) { | 
| 134 | 2 |  |  |  |  | 18 | $str .= ' (' . join(', ', map { $_->to_string() } @subs) . ')'; | 
|  | 4 |  |  |  |  | 9 |  | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 10 |  |  |  |  | 74 | return $str; | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | package Net::ACME2::Error::Subproblem; | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 6 |  |  | 6 |  | 47 | use parent qw( Net::ACME2::Error ); | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 74 |  | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 6 |  |  |  |  | 990 | use constant _ACCESSORS => ( | 
| 147 |  |  |  |  |  |  | __PACKAGE__->SUPER::_ACCESSORS(), | 
| 148 |  |  |  |  |  |  | 'identifier', | 
| 149 | 6 |  |  | 6 |  | 512 | ); | 
|  | 6 |  |  |  |  | 12 |  | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | sub to_string { | 
| 152 | 6 |  |  | 6 |  | 7361 | my ($self) = @_; | 
| 153 |  |  |  |  |  |  |  | 
| 154 | 6 |  |  |  |  | 12 | my $identifier_str = join('/', @{ $self->identifier() }{'type', 'value'}); | 
|  | 6 |  |  |  |  | 28 |  | 
| 155 |  |  |  |  |  |  |  | 
| 156 | 6 |  |  |  |  | 21 | return "$identifier_str: " . $self->SUPER::to_string(); | 
| 157 |  |  |  |  |  |  | } | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | 1; |