| 1 | package WWW::LetsEncrypt::Message::Directory; | ||
| 2 | $WWW::LetsEncrypt::Message::Directory::VERSION = '0.001'; | ||
| 3 | use JSON; | ||
| 4 | use Moose; | ||
| 5 | |||
| 6 | extends 'WWW::LetsEncrypt::Message'; | ||
| 7 | |||
| 8 | =pod | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | WWW::LetsEncrypt::Message::Directory | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | use WWW::LetsEncrypt::Message::Directory; | ||
| 17 | |||
| 18 | my $Directory = WWW::LetsEncrypt::Message::Directory->new(); | ||
| 19 | |||
| 20 | my $result_ref = $Directory->do_request(); | ||
| 21 | my $urls_ref = $result_ref->{directory}; | ||
| 22 | |||
| 23 | # Save the nonce for later, maybe? | ||
| 24 | my $nonce = $Directory->nonce(); | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | This module implements the ACME message for requesting the directory from the | ||
| 29 | server. Note: This does not perform any kind of configuration for later | ||
| 30 | messages. Mostly used to get the first nonce for later ACME messages. | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | # JWK is not required for this operation. | ||
| 35 | has '+JWK' => (required => 0); | ||
| 36 | |||
| 37 | =head2 Private Functions | ||
| 38 | |||
| 39 | =over 4 | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub _prep_step { | ||
| 44 | my ($self) = @_; | ||
| 45 | my $uri = $self->acme_base_url() . "/directory"; | ||
| 46 | $self->_Request(HTTP::Request->new(GET => $uri)); | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | =item _process_response | ||
| 51 | |||
| 52 | Internal function that processes revocation messages. | ||
| 53 | |||
| 54 | Input | ||
| 55 | |||
| 56 | $self - Object reference | ||
| 57 | $Response - HTTP::Response object reference | ||
| 58 | |||
| 59 | Output | ||
| 60 | |||
| 61 | # if getting the directory was successful | ||
| 62 | \%hash_ref = { | ||
| 63 | successful => 1, | ||
| 64 | finished => 1, | ||
| 65 | directory => \%hash_ref that is the directory information (see the RFC) | ||
| 66 | } | ||
| 67 | |||
| 68 | # Otherwise | ||
| 69 | \%hash_ref = { | ||
| 70 | successful => 0, | ||
| 71 | finished => 1, | ||
| 72 | } | ||
| 73 | |||
| 74 | # Else, an error \%hashref | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | sub _process_response { | ||
| 79 | my ($self, $Response) = @_; | ||
| 80 | if ($Response->code() == 200) { | ||
| 81 | my $json_data = decode_json($Response->content()); | ||
| 82 | return { | ||
| 83 | successful => 1, | ||
| 84 | finished => 1, | ||
| 85 | directory => $json_data, | ||
| 86 | }; | ||
| 87 | } | ||
| 88 | return { | ||
| 89 | successful => 0, | ||
| 90 | finished => 1, | ||
| 91 | }; | ||
| 92 | } | ||
| 93 | |||
| 94 | # Nonces are not needed for Directory Messages | ||
| 95 | sub _need_nonce { | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | # JWKs are not needed for a Directory GET. | ||
| 100 | sub _need_jwk { | ||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | __PACKAGE__->meta->make_immutable; |