Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def uninitialized_client(key=None):
if key is None:
key = josepy.JWKRSA(key=rsa.generate_private_key(65537, 2048, default_backend()))
net = acme_client.ClientNetwork(key, user_agent="Boulder integration tester")
directory = messages.Directory.from_json(net.get(DIRECTORY_V2).json())
return acme_client.ClientV2(directory, net)
def make_client(email=None):
"""Build an acme.Client and register a new account with a random key."""
key = josepy.JWKRSA(key=rsa.generate_private_key(65537, 2048, default_backend()))
net = acme_client.ClientNetwork(key, user_agent="Boulder integration tester")
client = acme_client.Client(DIRECTORY, key=key, net=net)
account = client.register(messages.NewRegistration.from_data(email=email))
client.agree_to_tos(account)
client.account = account
return client
def registered_client(args, existing_account_key, existing_account_reg):
"""Return an ACME v2 client from account key and registration.
Register a new account or recover missing registration if necessary."""
key = check_or_generate_account_key(args, existing_account_key)
net = acme_client.ClientNetwork(
key=key,
account=existing_account_reg,
user_agent=args.user_agent
)
directory = messages.Directory.from_json(net.get(args.server).json())
client = acme_client.ClientV2(directory, net=net)
if existing_account_reg is None:
if args.email is None:
logger.warning('--email was not provided; ACME CA will have no '
'way of contacting you.')
new_reg = messages.NewRegistration.from_data(email=args.email)
if "terms_of_service" in client.directory.meta:
logger.info("By using simp_le, you implicitly agree "
"to the CA's terms of service: %s",
def issue_cert():
# Use or generate new account for ACME API
key, regr = account()
vhosts = [vhost for vhost in VHost.objects.filter(use_letsencrypt=True) if vhost.letsencrypt_state() in ['REQUEST', 'RENEW']]
if not vhosts:
return
net = client.ClientNetwork(key = key, account = regr)
directory = messages.Directory.from_json(net.get(settings.LETSENCRYPT_ACME_SERVER).json())
client_acme = client.ClientV2(directory, net=net)
letsencrypt_issued = False
for vhost in vhosts:
pkey_pem = None
if vhost.letsencrypt_state() is 'RENEW':
pkey_pem = vhost.cert.key
# Generate a certificate request based on the vhost and aliases.
pkey_pem, csr_pem = gen_csr([str(vhost.punycode()),] + [vhostalias.punycode() for vhostalias in vhost.vhostalias_set.all()], pkey_pem)
# Create new certificate order
challbs = []
try:
new_order = client_acme.new_order(csr_pem)
- Revoke certificate
(Account update actions)
- Change contact information
- Deactivate Account
"""
# Create account key
acc_key = jose.JWKRSA(
key=rsa.generate_private_key(public_exponent=65537,
key_size=ACC_KEY_BITS,
backend=default_backend()))
# Register account and accept TOS
net = client.ClientNetwork(acc_key, user_agent=USER_AGENT)
directory = messages.Directory.from_json(net.get(DIRECTORY_URL).json())
client_acme = client.ClientV2(directory, net=net)
# Terms of Service URL is in client_acme.directory.meta.terms_of_service
# Registration Resource: regr
# Creates account with contact information.
email = ('fake@example.com')
regr = client_acme.new_account(
messages.NewRegistration.from_data(
email=email, terms_of_service_agreed=True))
# Create domain private key and CSR
pkey_pem, csr_pem = new_csr_comp(DOMAIN)
# Issue certificate
try:
# Read existing account data and private key
with open(reg_file, 'r') as f:
regr = messages.RegistrationResource.json_loads(f.read())
with open(key_file, 'r') as f:
key = jose.JWK.json_loads(f.read())
except IOError as error:
# Generate new private key, as we expect that the account doesn't exist
private_key = rsa.generate_private_key(
public_exponent = 65537,
key_size = settings.LETSENCRYPT_ACCT_KEY_BITS,
backend = default_backend()
)
key = jose.JWKRSA(key=private_key)
# Prepare ACME client connection with account private key
net = client.ClientNetwork(key)
directory = messages.Directory.from_json(
net.get(settings.LETSENCRYPT_ACME_SERVER).json()
)
client_acme = client.ClientV2(directory, net=net)
# Generate a new account and store account information locally
email = getattr(settings, 'KUMQUAT_EMAIL', None)
regr = client_acme.new_account(
messages.NewRegistration.from_data(
email = email,
terms_of_service_agreed = True
)
)
# Store private key as json format
with open(key_file, 'w') as f:
f.write(key.json_dumps())
# Store regr information as json format
def acme_from_config_key(config, key):
"Wrangle ACME client construction"
# TODO: Allow for other alg types besides RS256
net = acme_client.ClientNetwork(key, verify_ssl=(not config.no_verify_ssl),
user_agent=_determine_user_agent(config))
return acme_client.Client(config.server, key=key, net=net)
def acme_from_config_key(config, key, regr=None):
"Wrangle ACME client construction"
# TODO: Allow for other alg types besides RS256
net = acme_client.ClientNetwork(key, account=regr, verify_ssl=(not config.no_verify_ssl),
user_agent=determine_user_agent(config))
return acme_client.BackwardsCompatibleClientV2(net, key, config.server)
def make_client(email=None):
"""Build an acme.Client and register a new account with a random key."""
key = jose.JWKRSA(key=rsa.generate_private_key(65537, 2048, default_backend()))
net = acme_client.ClientNetwork(key, verify_ssl=False,
user_agent="Boulder integration tester")
client = acme_client.Client(DIRECTORY, key=key, net=net)
tos = client.directory.meta.terms_of_service
if tos is not None and "Do%20what%20thou%20wilt" in tos:
net.account = client.register(messages.NewRegistration.from_data(email=email,
terms_of_service_agreed=True))
else:
raise Exception("Unrecognized terms of service URL %s" % tos)
return client