def make_authzs(client, domains): """Make authzs for each of the given domains. Return a list of authzs and challenges.""" authzs, challenges = [], [] for d in domains: authz, chall_body = get_chall(client, d) authzs.append(authz) challenges.append(chall_body) return authzs, challenges
def get_challenges(client, regr, domain, challenges_file, log): # Load the cache of challenges. challenges = load_challenges_file(challenges_file) # If challenges exist for this domain, reuse it. # We've already dropped expired and revoked challenges, so we don't have # to check that here. for i, challg in enumerate(challenges): if challg.body.identifier.typ.name == "dns" and challg.body.identifier.value == domain: log("Reusing existing challenges for %s." % domain) # Refresh the record because it may have been updated with validated challenges. try: challg, resp = client.poll(challg) except acme.messages.Error as e: if e.typ in ("urn:acme:error:unauthorized", "urn:acme:error:malformed"): # There is a problem accessing our own account. This probably # means the stored registration information is not valid. raise AccountDataIsCorrupt(challenges_file) raise # Check that the refreshed record is not expired/revoked. Those # aren't helpful. It might be "invalid", meaning a challenge # failed. We'll percolate up an invalid challenge so the user # gets a ChallengeFailed exception, but we'll also drop it from # the cache so that it doesn't prevent further attempts to get # a certificate from proceeding. if is_still_valid_challenge(challg): if challg.body.status.name != "invalid": # Update cache. challenges[i] = challg else: # Drop from cache. challenges.pop(i) # Stop loop here: Use this challenge. break else: # None found. challg = None resp = None if challg is None: # Get new challenges for a domain. log("Requesting new challenges for %s." % domain) try: challg = client.request_domain_challenges(domain, regr.new_authzr_uri) except acme.messages.Error as e: if e.typ == "urn:acme:error:malformed": raise InvalidDomainName(domain, e.detail) raise # Add into our existing challenges. challenges.append(challg) # Write a cache of challenges. save_challenges_file(challenges, challenges_file) # Return the new challenges for this domain, and if we updated it, # then the response object so we can know how long to wait before # polling again. return (challg, resp)