Protocol::ACME
Interface to the Let's Encrypt ACME API
- Provided by: libprotocol-acme-perl (Version: 1.01-3)
- Report a bug
Interface to the Let's Encrypt ACME API
Version 1.01
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";
}
The "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.
The following constructor methods are available:
KEY DEFAULT
----------- --------------------
*host undef
account_key undef
openssl undef
ua HTTP::Tiny->new()
loglevel error
debug 0
mailto undef
host: The API end point to connect to. This will generally be acme-staging.api.letsencrypt.org or acme-v01.api.letsencrypt.org
account_key: The account private key in a scalar ref or filename. See "$self-"account_key> for details on this argument.
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 "Crypt::OpenSSL::RSA".
ua: An HTTP::Tiny object customized as you see fit
loglevel: Set the loglevel to one of the "Log::Any" values.
debug: If set to non-zero this is a shortcut for "loglevel =" debug>
mailto: This should be the email address that you want associated with your account. This is used my Let's Encrypt for expiration notification.
If the arg is a SCALAR it is assumed to be the filename of the key. "account_key" will throw an error if there are problems reading the file.
If the arg is a SCALAR reference it is assumed to be a buffer that contains the KEY.
If the arg is a 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 "filename" and "buffer" are set the "buffer" argument will be ignored.
If the format is not explcitly set "Protocol::ACME" will look at the key and try and determine what the format it.
Load a key from disk. Currently the key needs to be unencrypted. Callbacks for handling password protected keys are still to come.
Arguments that can be passed in:
KEY DEFAULT
----------- --------------------
mailto undef
mailto: See "new" for a desciption. This will override the value passed to new if any.
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:
"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.
"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.
"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.
If the arg is a SCALAR it is assumed to be the filename of the CSR. "sign" will throw an error if there are problems reading the file.
If the arg is a SCALAR reference it is assumed to be a buffer that contains the CSR.
If the arg is a 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 "filename" and "buffer" are set the "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 "Protocol::ACME" will return the DER encoded signed certificate.
Stephen Ludin, "<sludin at ludin.org>"
Please report any bugs or feature requests to "bug-protocol-acme at rt.cpan.org", or through the web interface at <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.
https://github.com/sludin/Protocol-ACME
You can find documentation for this module with the perldoc command.
perldoc Protocol::ACME
You can also look for information at:
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Protocol-ACME>
<http://annocpan.org/dist/Protocol-ACME>
<http://cpanratings.perl.org/d/Protocol-ACME>
<http://search.cpan.org/dist/Protocol-ACME/>
Felipe Gasper, "<felipe at felipegasper.com>"
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:
<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.