def save(self, filename=None, transformed_key=None): """Save current database object to disk. Args: filename (:obj:`str`, optional): path to database. If None, the path given when the database was opened is used. transformed_key (:obj:`bytes`, optional): precomputed transformed key. """ if not filename: filename = self.filename # FIXME: Construct's RawCopy preferentially rebuilds from raw data over # parsed values. ie if we modify the parsed header values, # the modified values are not saved. Delete the raw data so # RawCopy rebuilds from .value instead of .data # del self.kdbx.header.data KDBX.build_file( self.kdbx, filename, password=self.password, keyfile=self.keyfile, transformed_key=transformed_key )
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
def save(self, filename=None, transformed_key=None): """Save current database object to disk. Args: filename (:obj:`str`, optional): path to database or stream object. If None, the path given when the database was opened is used. PyKeePass.filename is unchanged. transformed_key (:obj:`bytes`, optional): precomputed transformed key. """ output = None if not filename: filename = self.filename if hasattr(filename, "write"): output = KDBX.build_stream(self.kdbx, filename, password=self.password, keyfile=self.keyfile, transformed_key=transformed_key) else: output = KDBX.build_file(self.kdbx, filename, password=self.password, keyfile=self.keyfile, transformed_key=transformed_key) return output
def save(self, filename=None, transformed_key=None): if not filename: filename = self.filename KDBX.build_file(self.kdbx, filename, password=self.password, keyfile=self.keyfile, transformed_key=transformed_key)
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
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
def save(self, filename=None): if not filename: filename = self.filename with open(filename, 'wb') as f: f.write( KDBX.build(self.kdbx, password=self.password, keyfile=self.keyfile))
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)
def save(self, filename=None, transformed_key=None): """Save current database object to disk. Args: filename (:obj:`str`, optional): path to database. If None, the path given when the database was opened is used. transformed_key (:obj:`bytes`, optional): precomputed transformed key. """ if not filename: filename = self.filename KDBX.build_file( self.kdbx, filename, password=self.password, keyfile=self.keyfile, transformed_key=transformed_key )
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