File: README.pod

package info (click to toggle)
libprotocol-acme-perl 1.01-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 296 kB
  • ctags: 98
  • sloc: perl: 1,463; makefile: 9; sh: 8
file content (376 lines) | stat: -rw-r--r-- 11,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
=head1 NAME

Protocol::ACME - Interface to the Let's Encrypt ACME API

=head1 VERSION

Version 1.01

=head1 SYNOPSIS

 use Protocol::ACME;

 my @names = qw( www.example.com cloud.example.com );

 my $challenges = {
                    'www.example.com'   => Protocol::ACME::Challenge::SimpleSSH->new(
                      { ssh_host => "host1", www_root => "~/www" }
                    ),
                   'cloud.example.com' => Protocol::ACME::Challenge::SimpleSSH->new(
                     { ssh_host => "home2", www_root => "/opt/local/www/htdocs" }
                   )
                 };

 eval
 {
   my $acme = Protocol::ACME->new( host               => $host,
                                   account_key        => $account_key_pem_or_der,
                                 );

   $acme->directory();
   $acme->register();
   $acme->accept_tos();

   for my $domain ( @names )
   {
     $acme->authz( $domain );
     $acme->handle_challenge( $challenges->{$domain} );
     $acme->check_challenge();
     $acme->cleanup_challenge( $challenges->{$domain} );
   }

   my $cert = $acme->sign( $csr_file );
 };
 if ( $@ )
 {
   die if !UNIVERSAL::isa($@, 'Protocol::ACME::Exception');
   die "Error occurred: Status: $@->{status},
                        Detail: $@->{detail},
                        Type:   $@->{type}\n";
 }
 else
 {
   # do something appropriate with the DER encoded cert
   print "Success\n";
 }

=head1 DESCRIPTION

The C<Protocol::ACME> is a class implementing an interface for the
Let's Encrypt ACME API.

The class handles the protocol details behind provisioning a Let's
Encrypt certificate.

=head1 CONSTRUCTOR METHODS

The following constructor methods are available:

=over 4

=item $acme = Protcol::ACME->new( %options )

This method constructs a new C<Protocl::ACME> object and returns it.
Key/value pair arguments may be provided to set up the initial state.
The may be passed in as a hash or a hashref. The following options
correspond to attribute methods described below. Items marked with
a * are required.

   KEY                     DEFAULT
   -----------             --------------------
   *host                   undef
   account_key             undef
   openssl                 undef
   ua                      HTTP::Tiny->new()
   loglevel                error
   debug                   0
   mailto                  undef

B<host>: The API end point to connect to.  This will generally be acme-staging.api.letsencrypt.org
or acme-v01.api.letsencrypt.org

B<account_key>: The account private key in a scalar ref or filename.  See C<$self->account_key>
for details on this arguemtn.

B<openssl>: The path to openssl.  If this option is used a local version of the openssl binary will
be used for crypto operations rather than C<Crypt::OpenSSL::RSA>.

B<ua>: An HTTP::Tiny object customized as you see fit

B<loglevel>: Set the loglevel to one of the C<Log::Any> values.

B<debug>: If set to non-zero this is a shortcut for C<loglevel => debug>

B<mailto>: This should be the email address that you want associated with your account.  This is used
my Let's Encrypt for expiration notification.

=back

=head2 METHODS

=over

=item account_key( $key_filename )

=item account_key( \$buffer )

=item account_key( \%explicit_args )


C<account_key> will load a the private account key if it was not already loaded
when the C<pProtocol::ACME> object was constructed.  There are three ways to call this:

If the arg is a B<SCALAR> it is assumed to be the filename of the
key.  C<account_key> will throw an error if there are problems reading the file.

If the arg is a B<SCALAR> reference it is assumed to be a buffer that
contains the KEY.

If the arg is a B<HASH> reference it contains named arguments.  The arguments
are:

   KEY          DEFAUL        DESC
   -----------  -----------   -------------------
   filename     undef         The key Filename
   buffer       undef         Buffer containing the key
   format       undef         Explicitly state the format ( DER | PEM )

If both C<filename> and C<buffer> are set the C<buffer> argument will be ignored.

If the format is not explcitly set C<Protocol::ACME> will look at the key and
try and determine what the format it.


=item load_key_from_disk( $key_path )

B<DEPRECATED>

Load a key from disk.  Currently the key needs to be unencrypted.
Callbacks for handling password protected keys are still to come.

=item directory()

Loads the directory from the ACME host.  This call must be made first
before any other calls to the API in order the bootstrap the API
resource list.

=item register( %args )

Call the new-reg resource and create an account associated with the
loaded account key.  If that key has already been registered this method
will gracefully and silently handle that.

Arguments that can be passed in:

   KEY                     DEFAULT
   -----------             --------------------
   mailto                  undef

B<mailto>: See C<new> for a desciption.  This will override the value passed to new
if any.


=item accept_tos()

In order to use the Let's Encrypt service, the account needs to accept
the Terms of Service.  This is provided in a link header in response
to the new-reg ( or reg ) resource call.  If the TOS have already been
accepted as indicated by the reg structure returned by the API this
call will be a noop.

=item authz( $domain )

C<authz> needs to be called for each domain ( called identifiers in
ACME speak ) in the certificate.  This included the domain in the subject
as well as the Subject Alternate Name (SAN) fields.  Each call to
C<authz> will result in a challenge being issued from Let's Encrypt.
These challenges need to be handled individually.

=item handle_challenge( $challenge_object )

C<handle_challenge> is called for each challenge issued by C<authz>.
The challenge object must be a subclass of C<Protocol::ACME::Challenge>
which implements a 'handle' method.  This objects handle method
will be passed three arguments and is expected to fulfill the
preconditions for the chosen challenge.  The three areguments
are:

  fingerprint: the sha256 hex digest of the account key
  token: the challenge token
  url: the url returned by the challenge

Fully describing how to handle every challenge type of out of the
scope of this documentation ( at least for now ).  Two challenge
classes have been included for reference:

C<Protocol::ACME::Challenge::SimpleSSH> is initialized with the
ssh host name and the www root for the web server for the http-01
challenge.  It will ssh to the host and create the file in
the correct location for challenge fulfillment.

C<Protocol::ACME::Challenge::LocalFile> is initialized with just the
www root for the web server for the http-01 challenge.  It will
simply create the challenge file in the correct place on the local
filesystem.

C<Protocol::ACME::Challenge::Manual> is intended to be run in an
interactive manner and will stop and prompt the user with the relevant
information so they can fulfill the challenge manually.

but below is an example for handling the simpleHTTP ( http-01 )
challenge.


=item check_challenge()

Called after C<handle_challenge>.  This will poll the challenge status
resource and will return when the state changes from 'pending'.

=item cleanup_challenge()

Called after C<check_challenge> to remove the challenge files.

=item $cert = sign( $csr_filename )

=item $cert = sign( \$buffer )

=item $cert = sign( \%explicit_args )


Call C<sign> after the challenge for each domain ( itentifier ) has
been fulfilled.  There are three ways to call this:

If the arg is a B<SCALAR> it is assumed to be the filename of the
CSR.  C<sign> will throw an error if there are problems reading the file.

If the arg is a B<SCALAR> reference it is assumed to be a buffer that
contains the CSR.

If the arg is a B<HASH> reference it contains named arguments.  The arguments
are:

   KEY          DEFAUL        DESC
   -----------  -----------   -------------------
   filename     undef         The CSR Filename
   buffer       undef         Buffer containing the CSR
   format       undef         Explicitly state the format ( DER | PEM )

If both C<filename> and C<buffer> are set the C<buffer> argument will be ignored.

If the format is not explcitly set Protocol::ACME will look at the CSR and
try and determine what the format it.

On success C<Protocol::ACME> will return the DER encoded signed certificate.

=item $cert_chain = chain()

After C<sign> has been called and a cert successfully created, C<chain> will
fetch and return the DER encoded certificate issuer.

=item revoke( $certfile )

Call C<revoke> to revoke an already issued certificate. C<$certfile>
must point the a DER encoded form of the certificate.

=item recovery_key()

LE does not yet support recovery keys.  This method will die when
called.


=back

=head1 AUTHOR

Stephen Ludin, C<< <sludin at ludin.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-protocol-acme at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Protocol-ACME>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 REPOSITORY

https://github.com/sludin/Protocol-ACME


=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Protocol::ACME


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Protocol-ACME>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Protocol-ACME>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Protocol-ACME>

=item * Search CPAN

L<http://search.cpan.org/dist/Protocol-ACME/>

=back


=head1 CONTRIBUTORS

Felipe Gasper, C<< <felipe at felipegasper.com> >>

=head1 ACKNOWLEDGEMENTS



=head1 LICENSE AND COPYRIGHT

Copyright 2015 Stephen Ludin.

This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:

L<http://www.perlfoundation.org/artistic_license_2_0>

Any use, modification, and distribution of the Standard or Modified
Version 1.01
distributing the Package, you accept this license. Do not use, modify,
or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge
patent license to make, have made, use, offer to sell, sell, import and
otherwise transfer the Package with respect to any patent claims
licensable by the Copyright Holder that are necessarily infringed by the
Package. If you institute patent litigation (including a cross-claim or
counterclaim) against any party alleging that the Package constitutes
direct or contributory patent infringement, then this Artistic License
to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.