Update messages2, network2 stub, example updated

This commit is contained in:
Jakub Warmuz
2015-03-24 12:34:21 +00:00
parent 7e820b093d
commit c9589d33d3
3 changed files with 221 additions and 92 deletions
+17 -46
View File
@@ -1,66 +1,37 @@
import httplib
import logging
import os
import pkg_resources
import requests
from letsencrypt.acme import messages2
from letsencrypt.acme import jose
from letsencrypt.client import network2
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
URL_ROOT = 'https://www.letsencrypt-demo.org'
NEW_REG_URL = URL_ROOT + '/acme/new-reg'
NEW_AUTHZ_URL = URL_ROOT + '/acme/new-authz'
NEW_CERT_URL = URL_ROOT + '/acme/new-certz'
#NEW_CERT_URL = URL_ROOT + '/acme/new-certz'
class Resource(jose.ImmutableMap):
__slots__ = ('body', 'location')
def send(resource, key, alg=jose.RS256):
dumps = resource.body.json_dumps()
logging.debug('Serialized JSON: %s', dumps)
sig = jose.JWS.sign(payload=dumps, key=key, alg=alg).json_dumps()
logging.debug('Serialized JWS: %s', sig)
response = requests.post(resource.location, sig)
logging.debug('Received response %s: %s', response, response.text)
if (response.status_code == httplib.OK or
response.status_code == httplib.CREATED):
pass
# TODO: server might override NEW_AUTHZ_URI (after new-reg) or
# NEW_CERTZ_URI (after new-authz) and we should use it
# instead. Below code only prints the link.
if 'next' in response.links:
logging.debug('Link (next): %s', response.links['next']['url'])
if 'up' in response.links:
logging.debug('Link (up): %s', response.links['up']['url'])
# TODO: new-cert response is not JSON
return Resource(
body=type(resource.body).from_json(response.json()),
location=response.headers['location'])
registration = messages2.Registration(contact=(
'mailto:cert-admin@example.com', 'tel:+12025551212'))
key = jose.JWKRSA.load(pkg_resources.resource_string(
'letsencrypt.acme.jose', os.path.join('testdata', 'rsa512_key.pem')))
net = network2.Network(NEW_REG_URL, key)
authz = Resource(body=messages2.Authorization(identifier=messages2.Identifier(
typ=messages2.Identifier.FQDN, value="example1.com")),
location=NEW_AUTHZ_URL)
contact = contact=('mailto:cert-admin@example.com', 'tel:+12025551212')
# Boulder does not support registrations
#regr = net.register(contact=contact)
regr = messages2.RegistrationResource(
body=messages2.Registration(contact=contact, key=key.public()),
uri=NEW_REG_URL + '/fooooo',
new_authz_uri=NEW_AUTHZ_URL)
authz2 = send(authz, key)
assert authz2.body.key == key.public()
assert authz2.body.identifier == authz.body.identifier
assert authz2.body.challenges is not None
authzr = net.request_challenges(
identifier=messages2.Identifier(
typ=messages2.IdentifierFQDN, value="example1.com"),
regr=regr)
print authz2
print
print requests.get(authz2.location).json()
print authzr