2015-06-18 07:07:20 -04:00
|
|
|
"""Example script showing how to use acme client API."""
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import pkg_resources
|
|
|
|
|
|
2015-07-05 09:11:33 -04:00
|
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
|
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
2015-05-13 03:59:13 -04:00
|
|
|
import OpenSSL
|
2015-06-18 07:07:20 -04:00
|
|
|
|
|
|
|
|
from acme import client
|
|
|
|
|
from acme import messages
|
|
|
|
|
from acme import jose
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
|
|
|
2015-10-28 03:26:52 -04:00
|
|
|
DIRECTORY_URL = 'https://acme-staging.api.letsencrypt.org/directory'
|
2015-06-18 07:07:20 -04:00
|
|
|
BITS = 2048 # minimum for Boulder
|
|
|
|
|
DOMAIN = 'example1.com' # example.com is ignored by Boulder
|
|
|
|
|
|
2015-07-05 09:11:33 -04:00
|
|
|
# generate_private_key requires cryptography>=0.5
|
2015-07-08 08:07:05 -04:00
|
|
|
key = jose.JWKRSA(key=rsa.generate_private_key(
|
2015-07-05 09:11:33 -04:00
|
|
|
public_exponent=65537,
|
2015-10-27 15:04:20 -04:00
|
|
|
key_size=BITS,
|
2015-07-08 08:07:05 -04:00
|
|
|
backend=default_backend()))
|
2015-10-28 03:26:52 -04:00
|
|
|
acme = client.Client(DIRECTORY_URL, key)
|
2015-06-18 07:07:20 -04:00
|
|
|
|
2015-07-04 02:22:11 -04:00
|
|
|
regr = acme.register()
|
2015-06-18 07:07:20 -04:00
|
|
|
logging.info('Auto-accepting TOS: %s', regr.terms_of_service)
|
2015-12-12 14:50:26 -05:00
|
|
|
acme.agree_to_tos(regr)
|
2015-06-18 07:07:20 -04:00
|
|
|
logging.debug(regr)
|
|
|
|
|
|
|
|
|
|
authzr = acme.request_challenges(
|
2017-03-15 00:44:57 -04:00
|
|
|
identifier=messages.Identifier(typ=messages.IDENTIFIER_FQDN, value=DOMAIN))
|
2015-06-18 07:07:20 -04:00
|
|
|
logging.debug(authzr)
|
|
|
|
|
|
|
|
|
|
authzr, authzr_response = acme.poll(authzr)
|
|
|
|
|
|
2015-05-13 03:59:13 -04:00
|
|
|
csr = OpenSSL.crypto.load_certificate_request(
|
|
|
|
|
OpenSSL.crypto.FILETYPE_ASN1, pkg_resources.resource_string(
|
2015-07-12 07:39:37 -04:00
|
|
|
'acme', os.path.join('testdata', 'csr.der')))
|
2015-06-18 07:07:20 -04:00
|
|
|
try:
|
2016-02-16 12:00:11 -05:00
|
|
|
acme.request_issuance(jose.util.ComparableX509(csr), (authzr,))
|
2015-06-18 07:07:20 -04:00
|
|
|
except messages.Error as error:
|
|
|
|
|
print ("This script is doomed to fail as no authorization "
|
|
|
|
|
"challenges are ever solved. Error from server: {0}".format(error))
|