Пример #1
0
def register(storage, client, log, agree_to_tos_url=None):
    existing_regr = None
    if not os.path.exists(storage):
        # Create a new registration.
        log("Registering a new account with Let's Encrypt.")
        regr = client.register()
    else:
        log("Validating existing account saved to %s." % storage)

        # Validate existing registration by querying for it from the server.
        with open(storage, 'r') as f:
            regr = acme.messages.RegistrationResource.json_loads(f.read())
        existing_regr = regr.json_dumps()
        regr = client.query_registration(regr)

    # If this call is to agree to a terms of service agreement, update the
    # registration.
    if agree_to_tos_url:
        regr = client.update_registration(regr.update(body=regr.body.update(agreement=agree_to_tos_url)))

    # Write new or updated registration (if it changed, and hopefully json_dumps is stable).
    if existing_regr != regr.json_dumps():
        if existing_regr is not None:
            log("Saving updated account information.")
        with open(storage, 'w') as f:
            f.write(regr.json_dumps_pretty())

    return regr
Пример #2
0
def register(storage, client, log, agree_to_tos_url=None):
    existing_regr = None
    if not os.path.exists(storage):
        # Create a new registration.
        log("Registering a new account with Let's Encrypt.")
        regr = client.register()
    else:
        log("Validating existing account saved to %s." % storage)

        # Validate existing registration by querying for it from the server.
        with open(storage, 'r') as f:
            regr = acme.messages.RegistrationResource.json_loads(f.read())
        existing_regr = regr.json_dumps()
        try:
            regr = client.query_registration(regr)
        except acme.messages.Error as e:
            if e.typ == "urn:acme:error:unauthorized":
                # There is a problem accessing our own account. This probably
                # means the stored registration information is not valid.
                raise AccountDataIsCorrupt(storage)
            raise

    # If this call is to agree to a terms of service agreement, update the
    # registration.
    if agree_to_tos_url:
        regr = client.update_registration(regr.update(body=regr.body.update(agreement=agree_to_tos_url)))

    # Write new or updated registration (if it changed, and hopefully json_dumps is stable).
    if existing_regr != regr.json_dumps():
        if existing_regr is not None:
            log("Saving updated account information.")
        with open(storage, 'w') as f:
            f.write(regr.json_dumps_pretty())

    return regr
Пример #3
0
def register(storage, client, log, agree_to_tos_url=None):
    existing_regr = None
    if not os.path.exists(storage):
        # Create a new registration.
        log("Registering a new account with Let's Encrypt.")
        regr = client.register()
    else:
        log("Validating existing account saved to %s." % storage)

        # Validate existing registration by querying for it from the server.
        with open(storage, 'r') as f:
            regr = acme.messages.RegistrationResource.json_loads(f.read())
        existing_regr = regr.json_dumps()
        try:
            regr = client.query_registration(regr)
        except acme.messages.Error as e:
            if e.typ == "urn:acme:error:unauthorized":
                # There is a problem accessing our own account. This probably
                # means the stored registration information is not valid.
                raise AccountDataIsCorrupt(storage)
            raise

    # If this call is to agree to a terms of service agreement, update the
    # registration.
    if agree_to_tos_url:
        regr = client.update_registration(regr.update(body=regr.body.update(agreement=agree_to_tos_url)))

    # Write new or updated registration (if it changed, and hopefully json_dumps is stable).
    if existing_regr != regr.json_dumps():
        if existing_regr is not None:
            log("Saving updated account information.")
        with open(storage, 'w') as f:
            f.write(regr.json_dumps_pretty())

    return regr
Пример #4
0
def _register(hostname):
	existing_regr = None
	#see if hostname exists in our DB
	info = _recallHost(hostname)
	if info == None:
		_storeKeypair(hostname, _generateKeypair(), _generateKeypair())
		info = _recallHost(hostname)
	key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, base64.b64decode(info['acct_privkey']))
	client = acme.client.Client(CA,jose.JWKRSA(key=jose.ComparableRSAKey(key)))
	print client
	if info['reg_json'] == None:
		# Create a new registration.
		print ("Registering a new account with Let's Encrypt.")
		regr = client.register()
	else:
		print ("Validating existing account for hostname %s." % hostname)

		# Validate existing registration by querying for it from the server.
		regr = acme.messages.RegistrationResource.json_loads(info['reg_json'])
		existing_regr = regr.json_dumps()
		try:
			regr = client.query_registration(regr)
		except acme.messages.Error as e:
			if e.typ == "urn:acme:error:unauthorized":
				# There is a problem accessing our own account. This probably
				# means the stored registration information is not valid.
				raise AccountDataIsCorrupt(storage)
			raise

	# If this call is to agree to a terms of service agreement, update the
	# registration.
	regr = client.update_registration(regr.update(body=regr.body.update(agreement=TERMS)))

	# Write new or updated registration (if it changed, and hopefully json_dumps is stable).
	if existing_regr != regr.json_dumps():
		if existing_regr is not None:
			print ("Saving updated account information.")
		_updateHost(hostname, 'reg_json', regr.json_dumps_pretty())
	return regr
Пример #5
0
def register_client(client, email=None):
    """Register the given client
    """
    new_reg = acme.messages.NewRegistration.from_data(email=email)
    try:
        # register account
        regr = client.register(new_reg)
    except acme.messages.Error as error:
        if error.detail != 'Registration key is already in use':
            raise
    else:
        # agree to terms of service if needed
        if regr.terms_of_service is not None:
            tos_hash = sha256_of_uri_contents(regr.terms_of_service)
            logger.debug('TOS hash: %s', tos_hash)
            # TODO is tos_hash always the same?
            # if no, we should maybe store it somewhere?
            if tos_hash != DEFAULT_TOS_SHA256:
                raise RuntimeError('TOS hash mismatch. Found: %s.' % tos_hash)
            client.agree_to_tos(regr)

    return client