Giter VIP home page Giter VIP logo

Comments (17)

disarticulate avatar disarticulate commented on May 14, 2024

the class method is:

	def save_item(self,user,group_name,password,host,notes):
		group_entry = self.find_group(name=group_name)
		if not group_entry:
			group_entry = self.keepass_connection.add_group(
				self.keepass_connection.root_group,
				group_name
			)

		self.keepass_connection.add_entry(
			group_entry, 
			host,
			user,
			password
			#url=host, 
			#notes=notes
			)
		self.keepass_connection.save()

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024

looked into the code, there's the TODO note, which means whenever I save, I have to reinstantiate my password manager:

    def save(self, filename=None):
        # FIXME The *second* save operations creates gibberish passwords
        # FIXME the save operation should be moved to libkeepass at some point
        #       we shouldn't need to open another fd here just to write
        if not filename:
            filename = self.kdb_filename
        with open(filename, 'wb+') as outfile:
            self.kdb.write_to(outfile)

This is probably what the #TODO is.

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

Can you find specifically what you're adding that's causing the error by trial and error? Having this would be very valuable for debugging purposes.

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024
class KeepassManager:

	def __init__(self, keepassfile,keepasskey,password):
		self.keepass_connection = PyKeePass(keepassfile,keyfile=keepasskey,password=password)
		self.needs_save = False

	def encode_title(self,user,group_name,host):
		return host+'/'+user

	def decode_title(self,encoded_title):
		return bendcode.decode(encoded_title)

	def save(self):
		print('SAVING KEYPASS FILE!')
		self.keepass_connection.save()

	def execute(self, command,*args,**kwargs):
		func = getattr(self,command)
		if func:
			func(*args,**kwargs)
			return None
		else:
			return (command,args,kwargs)

	def find_group(self,**kwargs):
		name = kwargs.get('name')
		if name:
			return self.keepass_connection.find_groups_by_name(name,first=True)
		path = kwargs.get('path')
		if path:
			return self.keepass_connection.find_groups_by_path(path)

	def insert_item(self,user,group_name,password,host,notes):
		group_entry = self.find_group(name=group_name)
		if not group_entry:
			group_entry = self.keepass_connection.add_group(
				self.keepass_connection.root_group,
				group_name
			)

		self.keepass_connection.add_entry(
			group_entry, 
			self.encode_title(user,group_name,host),
			user,
			password,
			url=host, 
			notes=notes
		)

		self.needs_save = True

	def find_password(self,user,host,group=None):
		"""Finds password or returns None"""
		entry = self.find_user(user,host,group)
		if entry:
			return entry.password
		else:
			return None

	def find_user(self,user,host,group):
		"""Finds User Entry"""
		entries = self.keepass_connection.find_entries_by_username(user)
		for entry in entries:
			title = self.decode_title(entry.title)
			if title and title.get('host') == host and title.get('group') == group:
				return entry
			elif host in entry.title:
				return entry
			else:
				pass
		return None
	
	def copy_entry(entry,group):
		groups = self.keepass_connection.find_groups_by_name(group,first=False)
		[g.append(entry) for g in groups]
		return None


	def find_group_entries(self,group):
		group = self.keepass_connection.find_groups_by_name(group,first=True)
		if group:
			return group.entries
		return None
kp = PyKeePass('NewDatabase.kdbx', password='123',keyfile='/home/cy/.ssh/NewDatabase.key')
kpm = KeepassManager('NewDatabase.kdbx','/home/cy/.ssh/NewDatabase.key','123')
kpm.insert_item('testface','host.users','123','example.com','ssh://example.com')
kpm.save()
kpm.save()

It actually looks like it's the host '.' users.

If you got a drop box somewhere I can send the kbdx, but it sure looks like there's something being parsed wrong with 'hosts.users' as i can open the file up easily in unix keepass.

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

I ran insert_item on a blank database without any problem so I think libkeepass is running into issues reading your database. Unicode support is a little buggy right now it seems.

Can you delete everything in your database except the minimum set of items that cause the error and upload it as a gist.

Also, in regards to the FIXME you mentioned, I've always saved just once in my code and never had any issues, so perhaps it's no longer relevant. Maybe @pschmitt can comment on this?

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024

I don't see what i can upload the key and kbdx on gist.?

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

It's at the bottom left. Upload File

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

@disarticulate Any news on this?

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024

from pykeepass.

pschmitt avatar pschmitt commented on May 14, 2024

You could just upload it elsewhere:

from pykeepass.

pschmitt avatar pschmitt commented on May 14, 2024

BTW the FIXME notice regarding the gibberish passwords when saving twice the database is still pretty much accurate from my testing.

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

I can't open this database without the keyfile.

from pykeepass.

disarticulate avatar disarticulate commented on May 14, 2024

Sorry bought that
https://transfer.sh/X0ezF/NewDatabase.key

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

I worked on this a couple days ago, but I have since forgotten most of it. What I do know is that this is definitely a libkeepass problem, not pykeepass.

from pykeepass.

Evidlo avatar Evidlo commented on May 14, 2024

This should be closed.

from pykeepass.

pschmitt avatar pschmitt commented on May 14, 2024

... and it now is

from pykeepass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.