Beispiel #1
0
    def read(self,
             filename=None,
             password=None,
             keyfile=None,
             transformed_key=None):
        self.password = password
        self.keyfile = keyfile
        if filename:
            self.filename = filename
        else:
            filename = self.filename

        try:
            self.kdbx = KDBX.parse_file(filename,
                                        password=password,
                                        keyfile=keyfile,
                                        transformed_key=transformed_key)
        except ChecksumError as e:
            if e.path in (
                    '(parsing) -> body -> cred_check',  # KDBX4
                    '(parsing) -> cred_check'  # KDBX3
            ):
                raise CredentialsError
            elif e.path == '(parsing) -> body -> sha256':
                raise HeaderChecksumError
            elif e.path in (
                    '(parsing) -> body -> payload -> hmac_hash',  # KDBX4
                    '(parsing) -> xml -> block_hash'  # KDBX3
            ):
                raise PayloadChecksumError
            else:
                raise
Beispiel #2
0
    def save_database(self):
        if self.save_running is False and self.changes is True:
            self.save_running = True

            kdbx = KDBX.build(self.db.kdbx,
                              password=self.db.password,
                              keyfile=self.db.keyfile)

            try:
                output_stream = self.database_file_descriptor.replace(
                    None, False, Gio.FileCreateFlags.REPLACE_DESTINATION
                    | Gio.FileCreateFlags.PRIVATE, None)
                output_stream.write_all(kdbx)
                output_stream.close()
                self.logging_manager.debug("Saved database")
                self.changes = False
            except Exception:
                self.logging_manager.error(
                    "Error occured while saving database")

            # Workaround
            # Fix created and proposed: https://github.com/pschmitt/pykeepass/pull/102
            self.db.kdbx = KDBX.parse_file(self.db.filename,
                                           password=self.db.password,
                                           keyfile=self.db.keyfile)

            self.save_running = False
Beispiel #3
0
    def read(self, filename=None, password=None, keyfile=None):
        self.password = password
        self.keyfile = keyfile
        if not filename:
            filename = self.filename

        self.kdbx = KDBX.parse_file(filename,
                                    password=password,
                                    keyfile=keyfile)
Beispiel #4
0
    def read(self, filename=None, password=None, keyfile=None,
             transformed_key=None):
        self.password = password
        self.keyfile = keyfile
        if not filename:
            filename = self.filename

        try:
            self.kdbx = KDBX.parse_file(
                filename,
                password=password,
                keyfile=keyfile,
                transformed_key=transformed_key
            )
        except ChecksumError:
            raise CredentialsIntegrityError
Beispiel #5
0
    def read(self, filename=None, password=None, keyfile=None,
             transformed_key=None):
        """
        See class docstring.

        Todo:
            - raise, no filename provided, database not open
        """
        self.password = password
        self.keyfile = keyfile
        if filename:
            self.filename = filename
        else:
            filename = self.filename

        try:
            if hasattr(filename, "read"):
                self.kdbx = KDBX.parse_stream(
                    filename,
                    password=password,
                    keyfile=keyfile,
                    transformed_key=transformed_key
                )
            else:
                self.kdbx = KDBX.parse_file(
                    filename,
                    password=password,
                    keyfile=keyfile,
                    transformed_key=transformed_key
                )

        except ChecksumError as e:
            if e.path in (
                    '(parsing) -> body -> cred_check', # KDBX4
                    '(parsing) -> cred_check' # KDBX3
                    ):
                raise CredentialsError
            elif e.path == '(parsing) -> body -> sha256':
                raise HeaderChecksumError
            elif e.path in (
                    '(parsing) -> body -> payload -> hmac_hash', # KDBX4
                    '(parsing) -> xml -> block_hash' # KDBX3
                    ):
                raise PayloadChecksumError
            else:
                raise