Exemplo n.º 1
0
    def _load_for_server_path(self, account_id, server_path):
        account_dir_path = self._account_dir_path_for_server_path(
            account_id, server_path)
        if not os.path.isdir(
                account_dir_path):  # isdir is also true for symlinks
            if server_path in constants.LE_REUSE_SERVERS:
                prev_server_path = constants.LE_REUSE_SERVERS[server_path]
                prev_loaded_account = self._load_for_server_path(
                    account_id, prev_server_path)
                # we didn't error so we found something, so create a symlink to that
                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)

        acc = Account(regr, key, meta)
        if acc.id != account_id:
            raise errors.AccountStorageError(
                "Account ids mismatch (expected: {0}, found: {1}".format(
                    account_id, acc.id))
        return acc
Exemplo n.º 2
0
 def _save(self, account, acme, regr_only):
     account_dir_path = self._account_dir_path(account.id)
     util.make_or_verify_dir(account_dir_path, 0o700, os.geteuid(),
                             self.config.strict_permissions)
     try:
         with open(self._regr_path(account_dir_path), "w") as regr_file:
             regr = account.regr
             # If we have a value for new-authz, save it for forwards
             # compatibility with older versions of Certbot. If we don't
             # have a value for new-authz, this is an ACMEv2 directory where
             # an older version of Certbot won't work anyway.
             if hasattr(acme.directory, "new-authz"):
                 regr = RegistrationResourceWithNewAuthzrURI(
                     new_authzr_uri=acme.directory.new_authz,
                     body={},
                     uri=regr.uri)
             else:
                 regr = messages.RegistrationResource(body={}, uri=regr.uri)
             regr_file.write(regr.json_dumps())
         if not regr_only:
             with util.safe_open(self._key_path(account_dir_path),
                                 "w",
                                 chmod=0o400) as key_file:
                 key_file.write(account.key.json_dumps())
             with open(self._metadata_path(account_dir_path),
                       "w") as metadata_file:
                 metadata_file.write(account.meta.json_dumps())
     except IOError as error:
         raise errors.AccountStorageError(error)
Exemplo n.º 3
0
    def _load_for_server_path(self, account_id, server_path):
        account_dir_path = self._account_dir_path_for_server_path(account_id, server_path)
        if not os.path.isdir(account_dir_path): # isdir is also true for symlinks
            if server_path in constants.LE_REUSE_SERVERS:
                prev_server_path = constants.LE_REUSE_SERVERS[server_path]
                prev_loaded_account = self._load_for_server_path(account_id, prev_server_path)
                # 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
            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)
Exemplo n.º 4
0
    def update_meta(self, account: Account) -> None:
        """Update the meta resource.

        :param Account account: account to update

        """
        try:
            dir_path = self._prepare(account)
            self._update_meta(account, dir_path)
        except IOError as error:
            raise errors.AccountStorageError(error)
Exemplo n.º 5
0
    def update_regr(self, account: Account, client: ClientBase) -> None:
        """Update the registration resource.

        :param Account account: account to update
        :param ClientBase client: ACME client associated to the account

        """
        try:
            dir_path = self._prepare(account)
            self._update_regr(account, client, dir_path)
        except IOError as error:
            raise errors.AccountStorageError(error)
Exemplo n.º 6
0
    def _load_for_server_path(self, account_id, server_path):
        account_dir_path = self._account_dir_path_for_server_path(account_id, server_path)
        if not os.path.isdir(account_dir_path):
            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)

        acc = Account(regr, key, meta)
        if acc.id != account_id:
            raise errors.AccountStorageError(
                "Account ids mismatch (expected: {0}, found: {1}".format(
                    account_id, acc.id))
        return acc
Exemplo n.º 7
0
    def save(self, account: Account, client: ClientBase) -> None:
        """Create a new account.

        :param Account account: account to create
        :param ClientBase client: ACME client associated to the account

        """
        try:
            dir_path = self._prepare(account)
            self._create(account, dir_path)
            self._update_meta(account, dir_path)
            self._update_regr(account, client, dir_path)
        except IOError as error:
            raise errors.AccountStorageError(error)
Exemplo n.º 8
0
 def _save(self, account, regr_only):
     account_dir_path = self._account_dir_path(account.id)
     util.make_or_verify_dir(account_dir_path, 0o700, os.geteuid(),
                             self.config.strict_permissions)
     try:
         with open(self._regr_path(account_dir_path), "w") as regr_file:
             regr_file.write(account.regr.json_dumps())
         if not regr_only:
             with util.safe_open(self._key_path(account_dir_path),
                                 "w", chmod=0o400) as key_file:
                 key_file.write(account.key.json_dumps())
             with open(self._metadata_path(
                     account_dir_path), "w") as metadata_file:
                 metadata_file.write(account.meta.json_dumps())
     except IOError as error:
         raise errors.AccountStorageError(error)
Exemplo n.º 9
0
 def _save(self, account, acme, regr_only):
     account_dir_path = self._account_dir_path(account.id)
     util.make_or_verify_dir(account_dir_path, 0o700, os.geteuid(),
                             self.config.strict_permissions)
     try:
         with open(self._regr_path(account_dir_path), "w") as regr_file:
             regr = account.regr
             with_uri = RegistrationResourceWithNewAuthzrURI(
                 new_authzr_uri=acme.directory.new_authz,
                 body=regr.body,
                 uri=regr.uri,
                 terms_of_service=regr.terms_of_service)
             regr_file.write(with_uri.json_dumps())
         if not regr_only:
             with util.safe_open(self._key_path(account_dir_path),
                                 "w",
                                 chmod=0o400) as key_file:
                 key_file.write(account.key.json_dumps())
             with open(self._metadata_path(account_dir_path),
                       "w") as metadata_file:
                 metadata_file.write(account.meta.json_dumps())
     except IOError as error:
         raise errors.AccountStorageError(error)