Ejemplo n.º 1
0
    async def create_vault(self, identity: Identity) -> Revision:
        vault = self.vault
        if vault is None:
            raise ValueError("Invalid argument")

        revision = Revision(operation=RevisionOp.CreateVault)
        revision.vault_public_key = vault.identity.public_key.exportKey("DER")
        revision.user_public_key = identity.public_key.exportKey("DER")
        revision.user_id = '*****@*****.**' # TBD
        revision.sign(identity=identity)

        await self.write_term('create_vault',
                              revision.vault_public_key,
                              revision.user_public_key,
                              revision.user_fingerprint,
                              revision.signature)

        response = await self.read_term()

        vault_id = response[1].decode(vault.config.encoding)
        auth = response[2].decode(vault.config.encoding)
        server_info = rewrite_atoms_dict(response[3])

        if not vault_id:
            raise ServerError("Invalid vault ID: {0}".format(vault_id))

        if not auth:
            raise ServerError("Invalid auth token: {0}".format(auth))

        revision.vault_id = vault_id

        # assert :ok
        ret_revision = self.server_info_to_revision(server_info, vault)
        revision.revision_id = ret_revision.revision_id
        revision.created_at = ret_revision.created_at

        self.logger.info('Successfully created vault %s', vault_id)

        with vault.config.update_context():
            vault.config.update('remote', {
                'auth': auth
            })
            vault.config.update('vault', {
                'id': response[1].decode(vault.config.encoding)
            })

        return revision
Ejemplo n.º 2
0
    async def create_vault(self, identity: Identity) -> Revision:
        vault = self.vault
        if vault is None:
            raise ValueError("Invalid argument")

        revision = Revision(operation=RevisionOp.CreateVault)
        revision.vault_public_key = vault.identity.public_key.exportKey("DER")
        revision.user_public_key = identity.public_key.exportKey("DER")
        user_info = await self.user_info()
        revision.user_id = user_info['email']
        revision.sign(identity=identity)

        await self.write_term('create_vault', revision.vault_public_key,
                              revision.user_public_key,
                              revision.user_fingerprint, revision.signature)

        response = await self.read_term()

        vault_id = response[1].decode(vault.config.encoding)
        auth = response[2].decode(vault.config.encoding)
        server_info = rewrite_atoms_dict(response[3])

        if not vault_id:
            raise ServerError("Invalid vault ID: {0}".format(vault_id))

        if not auth:
            raise ServerError("Invalid auth token: {0}".format(auth))

        revision.vault_id = vault_id

        # assert :ok
        ret_revision = self.server_info_to_revision(server_info, vault)
        revision.revision_id = ret_revision.revision_id
        revision.created_at = ret_revision.created_at

        self.logger.info('Successfully created vault %s', vault_id)

        with vault.config.update_context():
            vault.config.update('remote', {'auth': auth})
            vault.config.update(
                'vault', {'id': response[1].decode(vault.config.encoding)})

        return revision
Ejemplo n.º 3
0
    async def init(self, identity: Identity) -> Revision:
        vault = cast(Vault, self.vault) # We can savely cast because of @require_vault

        new_vault_id = str(uuid4())
        if not vault.config.get("vault.id"):
            with vault.config.update_context():
                vault.config.update("vault", {"id": new_vault_id})

        await self.open()  # create directory

        # create txchain store
        with open(os.path.join(self.path, "txchain"), "wb"):
            pass

        revision = Revision(operation=RevisionOp.CreateVault)
        revision.vault_id = new_vault_id
        revision.user_id = "user@localhost"
        revision.vault_public_key = vault.identity.public_key.exportKey("DER")
        revision.user_public_key = identity.public_key.exportKey("DER")
        revision.sign(identity=identity)

        return self.add_revision(revision)
Ejemplo n.º 4
0
    async def init(self, identity: Identity) -> Revision:
        vault = cast(
            Vault, self.vault)  # We can savely cast because of @require_vault

        new_vault_id = str(uuid4())
        if not vault.config.get("vault.id"):
            with vault.config.update_context():
                vault.config.update("vault", {"id": new_vault_id})

        await self.open()  # create directory

        # create txchain store
        with open(os.path.join(self.path, "txchain"), "wb"):
            pass

        revision = Revision(operation=RevisionOp.CreateVault)
        revision.vault_id = new_vault_id
        revision.user_id = "user@localhost"
        revision.vault_public_key = vault.identity.public_key.exportKey("DER")
        revision.user_public_key = identity.public_key.exportKey("DER")
        revision.sign(identity=identity)

        return self.add_revision(revision)