Comments (17)
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.
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.
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.
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.
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.
I don't see what i can upload the key and kbdx on gist.?
from pykeepass.
It's at the bottom left. Upload File
from pykeepass.
@disarticulate Any news on this?
from pykeepass.
from pykeepass.
You could just upload it elsewhere:
from pykeepass.
BTW the FIXME
notice regarding the gibberish passwords when saving twice the database is still pretty much accurate from my testing.
from pykeepass.
from pykeepass.
I can't open this database without the keyfile.
from pykeepass.
Sorry bought that
https://transfer.sh/X0ezF/NewDatabase.key
from pykeepass.
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.
This should be closed.
from pykeepass.
... and it now is
from pykeepass.
Related Issues (20)
- tests/test4.kdbx cannot be opened with KeepassXC nor with Windows Keepass HOT 1
- Feature: CustomData support for groups (since KDBX4) HOT 1
- Tests fail on big-endian platform (s390x) HOT 1
- Bug: keyfile with multiline text in Key/Data HOT 3
- Multiple tags are treated as one when working on kdbx from KeepassXC HOT 2
- construct.core.ChecksumError: Error in path (parsing) -> cred_check HOT 2
- entry.set_custom_property("field_name",value) corrupts database HOT 3
- 4.0.4: no documentation? 🤔 HOT 2
- Crashes when opening item without expiration date HOT 1
- Python 2 support (dependency on future) HOT 4
- How to edit a shared group? HOT 2
- RFE: please start making github releases HOT 1
- Can't modify attachments after saving! HOT 3
- Provide access to master seed HOT 3
- What is the right approach to duplicate a group with all of its subgroups and entries?
- Feature Request: Add option to provide keyfile as bytes HOT 4
- It does not decodes entry.password for KeePass 2.53.1 64-bit HOT 5
- Bug: xml keyfiles with unexpected structure leads to errors HOT 1
- Add option to set creation/modification date HOT 1
- TOTP support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pykeepass.