'Generate and write out challenge certificate.'

def _setup_challenge_cert(self, achall, cert_key=None):

    cert_path = self.get_cert_path(achall)
    key_path = self.get_key_path(achall)
    self.configurator.reverter.register_file_creation(True, key_path)
    self.configurator.reverter.register_file_creation(True, cert_path)
    (response, (cert, key)) = achall.response_and_validation(cert_key=cert_key)
    cert_pem = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    key_pem = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)
    with open(cert_path, 'wb') as cert_chall_fd:
        cert_chall_fd.write(cert_pem)
    with util.safe_open(key_path, 'wb', chmod=256) as key_file:
        key_file.write(key_pem)
    return response
