Esempio n. 1
0
    def load(self, account_id):
        account_dir_path = self._account_dir_path(account_id)
        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
Esempio n. 2
0
 def save(self, account):
     account_dir_path = self._account_dir_path(account.id)
     le_util.make_or_verify_dir(account_dir_path, 0o700, os.geteuid())
     try:
         with open(self._regr_path(account_dir_path), "w") as regr_file:
             regr_file.write(account.regr.json_dumps())
         with le_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)