Skip to content

Commit

Permalink
restore unprotected etree on save
Browse files Browse the repository at this point in the history
  • Loading branch information
Evidlo committed Jan 19, 2020
1 parent d9fa0b6 commit cf4549b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
3.2.0 - 2019-
------------------
- fix for binary attachments missing Compressed attribute
- fix #181 - binary attachments missing Compressed attribute unparseable
- added PyKeePass.xml()
- fix #129 - protected multiline fields missing newline
- added tag searching - #182
- fix problem where entries are protected after save

3.1.0 - 2019-10-24
------------------
Expand Down
4 changes: 3 additions & 1 deletion pykeepass/kdbx_parsing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Adapter, BitStruct, BitsSwapped, Container, Flag, Padding, ListContainer, Mapping, GreedyBytes, Int32ul, Switch
)
from lxml import etree
from copy import deepcopy
import base64
import unicodedata
import zlib
Expand Down Expand Up @@ -198,8 +199,9 @@ def _decode(self, tree, con, path):
return tree

def _encode(self, tree, con, path):
tree_copy = deepcopy(tree)
cipher = self.get_cipher(self.protected_stream_key(con))
for elem in tree.xpath(self.unprotected_xpath):
for elem in tree_copy.xpath(self.unprotected_xpath):
if elem.text is not None:
elem.text = base64.b64encode(
cipher.encrypt(
Expand Down
17 changes: 8 additions & 9 deletions pykeepass/pykeepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
import uuid
import zlib
from copy import deepcopy

from construct import Container, ChecksumError
from lxml import etree
Expand Down Expand Up @@ -69,15 +70,13 @@ def save(self, filename=None, transformed_key=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,
transformed_key=transformed_key
)
)
KDBX.build_file(
self.kdbx,
filename,
password=self.password,
keyfile=self.keyfile,
transformed_key=transformed_key
)

@property
def version(self):
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lxml==4.3.4
pycryptodome==3.8.2
construct==2.9.45
argon2-cffi==19.1.0
lxml==4.4.0
pycryptodome==3.9.4
construct==2.9.51
argon2-cffi==19.2.0
python-dateutil==2.8.0
future==0.17.1
14 changes: 9 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,27 +732,31 @@ def test_129(self):
e = self.kp.find_entries(title='foobar_entry', first=True)
self.assertEqual(e.get_custom_property('multiline'), 'hello\nworld')

def test_pull102(self):
# PR 102 - entries are protected after save
# reset self.kp
self.setUp()
e = self.kp.find_entries(title='foobar_entry', first=True)
self.assertEqual(e.password, 'foobar')
self.kp.save()
self.assertEqual(e.password, 'foobar')


class EntryFindTests4(KDBX4Tests, EntryFindTests3):
pass


class GroupFindTests4(KDBX4Tests, GroupFindTests3):
pass


class EntryTests4(KDBX4Tests, EntryTests3):
pass


class GroupTests3(KDBX4Tests, GroupTests3):
pass


class AttachmentTests4(KDBX4Tests, AttachmentTests3):
pass


class PyKeePassTests4(KDBX4Tests, PyKeePassTests3):
pass

Expand Down

0 comments on commit cf4549b

Please sign in to comment.