How to use the josepy.JWK function in josepy

To help you get started, we’ve selected a few josepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wiedi / kumquat / kumquat / management / commands / letsencrypt.py View on Github external
def account():
	# Store account information in an JWKRSA formated json file
	reg_file = settings.LETSENCRYPT_STATE_FOLDER + '/regr.json'
	key_file = settings.LETSENCRYPT_STATE_FOLDER + '/private_key.json'
	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)
github certbot / certbot / certbot / certbot / _internal / account.py View on Github external
# we didn't error so we found something, so create a symlink to that
                accounts_dir = self.config.accounts_dir_for_server_path(server_path)
                # If accounts_dir isn't empty, make an account specific symlink
                if os.listdir(accounts_dir):
                    self._symlink_to_account_dir(prev_server_path, server_path, account_id)
                else:
                    self._symlink_to_accounts_dir(prev_server_path, server_path)
                return prev_loaded_account
            raise errors.AccountNotFound(
                "Account at %s does not exist" % account_dir_path)

        try:
            with open(self._regr_path(account_dir_path)) as regr_file:
                regr = messages.RegistrationResource.json_loads(regr_file.read())
            with open(self._key_path(account_dir_path)) as key_file:
                key = jose.JWK.json_loads(key_file.read())
            with open(self._metadata_path(account_dir_path)) as metadata_file:
                meta = Account.Meta.json_loads(metadata_file.read())
        except IOError as error:
            raise errors.AccountStorageError(error)

        return Account(regr, key, meta)
github certbot / certbot / certbot / account.py View on Github external
accounts_dir = self.config.accounts_dir_for_server_path(server_path)
                # If accounts_dir isn't empty, make an account specific symlink
                if os.listdir(accounts_dir):
                    self._symlink_to_account_dir(prev_server_path, server_path, account_id)
                else:
                    self._symlink_to_accounts_dir(prev_server_path, server_path)
                return prev_loaded_account
            else:
                raise errors.AccountNotFound(
                    "Account at %s does not exist" % account_dir_path)

        try:
            with open(self._regr_path(account_dir_path)) as regr_file:
                regr = messages.RegistrationResource.json_loads(regr_file.read())
            with open(self._key_path(account_dir_path)) as key_file:
                key = jose.JWK.json_loads(key_file.read())
            with open(self._metadata_path(account_dir_path)) as metadata_file:
                meta = Account.Meta.json_loads(metadata_file.read())
        except IOError as error:
            raise errors.AccountStorageError(error)

        return Account(regr, key, meta)
github Netflix / lemur / lemur / plugins / lemur_acme / plugin.py View on Github external
for option in json.loads(authority.options):
            options[option["name"]] = option.get("value")
        email = options.get("email", current_app.config.get("ACME_EMAIL"))
        tel = options.get("telephone", current_app.config.get("ACME_TEL"))
        directory_url = options.get(
            "acme_url", current_app.config.get("ACME_DIRECTORY_URL")
        )

        existing_key = options.get(
            "acme_private_key", current_app.config.get("ACME_PRIVATE_KEY")
        )
        existing_regr = options.get("acme_regr", current_app.config.get("ACME_REGR"))

        if existing_key and existing_regr:
            # Reuse the same account for each certificate issuance
            key = jose.JWK.json_loads(existing_key)
            regr = messages.RegistrationResource.json_loads(existing_regr)
            current_app.logger.debug(
                "Connecting with directory at {0}".format(directory_url)
            )
            net = ClientNetwork(key, account=regr)
            client = BackwardsCompatibleClientV2(net, key, directory_url)
            return client, {}
        else:
            # Create an account for each certificate issuance
            key = jose.JWKRSA(key=generate_private_key("RSA2048"))

            current_app.logger.debug(
                "Connecting with directory at {0}".format(directory_url)
            )

            net = ClientNetwork(key, account=None, timeout=3600)
github JackOfMostTrades / catlog / src / catlog / le_client.py View on Github external
def find_all(self) -> List[certbot.account.Account]:
        accounts = []
        for row in self._db.find_all_accounts(self._staging):
            accounts.append(certbot.account.Account(
                acme.messages.RegistrationResource.json_loads(row[1]),
                jose.JWK.json_loads(row[2])))
        return accounts
github JackOfMostTrades / catlog / src / catlog / le_client.py View on Github external
def load(self, account_id: str) -> certbot.account.Account:
        account_row = self._db.load_account(self._staging, account_id)
        if account_row is None:
            raise certbot.errors.AccountNotFound("Could not find account id " + account_id)
        return certbot.account.Account(
            acme.messages.RegistrationResource.json_loads(account_row[1]),
            jose.JWK.json_loads(account_row[2]))
github certbot / certbot / acme / acme / messages.py View on Github external
return eab.to_partial_json()


class Registration(ResourceBody):
    """Registration Resource Body.

    :ivar josepy.jwk.JWK key: Public key.
    :ivar tuple contact: Contact information following ACME spec,
        `tuple` of `unicode`.
    :ivar unicode agreement:

    """
    # on new-reg key server ignores 'key' and populates it based on
    # JWS.signature.combined.jwk
    key = jose.Field('key', omitempty=True, decoder=jose.JWK.from_json)
    contact = jose.Field('contact', omitempty=True, default=())
    agreement = jose.Field('agreement', omitempty=True)
    status = jose.Field('status', omitempty=True)
    terms_of_service_agreed = jose.Field('termsOfServiceAgreed', omitempty=True)
    only_return_existing = jose.Field('onlyReturnExisting', omitempty=True)
    external_account_binding = jose.Field('externalAccountBinding', omitempty=True)

    phone_prefix = 'tel:'
    email_prefix = 'mailto:'

    @classmethod
    def from_data(cls, phone=None, email=None, external_account_binding=None, **kwargs):
        """Create registration resource from contact details."""
        details = list(kwargs.pop('contact', ()))
        if phone is not None:
            details.append(cls.phone_prefix + phone)
github certbot / certbot / certbot / _internal / account.py View on Github external
accounts_dir = self.config.accounts_dir_for_server_path(server_path)
                # If accounts_dir isn't empty, make an account specific symlink
                if os.listdir(accounts_dir):
                    self._symlink_to_account_dir(prev_server_path, server_path, account_id)
                else:
                    self._symlink_to_accounts_dir(prev_server_path, server_path)
                return prev_loaded_account
            else:
                raise errors.AccountNotFound(
                    "Account at %s does not exist" % account_dir_path)

        try:
            with open(self._regr_path(account_dir_path)) as regr_file:
                regr = messages.RegistrationResource.json_loads(regr_file.read())
            with open(self._key_path(account_dir_path)) as key_file:
                key = jose.JWK.json_loads(key_file.read())
            with open(self._metadata_path(account_dir_path)) as metadata_file:
                meta = Account.Meta.json_loads(metadata_file.read())
        except IOError as error:
            raise errors.AccountStorageError(error)

        return Account(regr, key, meta)