Skip to content

Commit cf4549b

Browse files
committed
restore unprotected etree on save
1 parent d9fa0b6 commit cf4549b

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

CHANGELOG.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
3.2.0 - 2019-
22
------------------
3-
- fix for binary attachments missing Compressed attribute
3+
- fix #181 - binary attachments missing Compressed attribute unparseable
44
- added PyKeePass.xml()
5+
- fix #129 - protected multiline fields missing newline
6+
- added tag searching - #182
7+
- fix problem where entries are protected after save
58

69
3.1.0 - 2019-10-24
710
------------------

pykeepass/kdbx_parsing/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Adapter, BitStruct, BitsSwapped, Container, Flag, Padding, ListContainer, Mapping, GreedyBytes, Int32ul, Switch
77
)
88
from lxml import etree
9+
from copy import deepcopy
910
import base64
1011
import unicodedata
1112
import zlib
@@ -198,8 +199,9 @@ def _decode(self, tree, con, path):
198199
return tree
199200

200201
def _encode(self, tree, con, path):
202+
tree_copy = deepcopy(tree)
201203
cipher = self.get_cipher(self.protected_stream_key(con))
202-
for elem in tree.xpath(self.unprotected_xpath):
204+
for elem in tree_copy.xpath(self.unprotected_xpath):
203205
if elem.text is not None:
204206
elem.text = base64.b64encode(
205207
cipher.encrypt(

pykeepass/pykeepass.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import re
1212
import uuid
1313
import zlib
14+
from copy import deepcopy
1415

1516
from construct import Container, ChecksumError
1617
from lxml import etree
@@ -69,15 +70,13 @@ def save(self, filename=None, transformed_key=None):
6970
if not filename:
7071
filename = self.filename
7172

72-
with open(filename, 'wb') as f:
73-
f.write(
74-
KDBX.build(
75-
self.kdbx,
76-
password=self.password,
77-
keyfile=self.keyfile,
78-
transformed_key=transformed_key
79-
)
80-
)
73+
KDBX.build_file(
74+
self.kdbx,
75+
filename,
76+
password=self.password,
77+
keyfile=self.keyfile,
78+
transformed_key=transformed_key
79+
)
8180

8281
@property
8382
def version(self):

requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
lxml==4.3.4
2-
pycryptodome==3.8.2
3-
construct==2.9.45
4-
argon2-cffi==19.1.0
1+
lxml==4.4.0
2+
pycryptodome==3.9.4
3+
construct==2.9.51
4+
argon2-cffi==19.2.0
55
python-dateutil==2.8.0
66
future==0.17.1

tests/tests.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -732,27 +732,31 @@ def test_129(self):
732732
e = self.kp.find_entries(title='foobar_entry', first=True)
733733
self.assertEqual(e.get_custom_property('multiline'), 'hello\nworld')
734734

735+
def test_pull102(self):
736+
# PR 102 - entries are protected after save
737+
# reset self.kp
738+
self.setUp()
739+
e = self.kp.find_entries(title='foobar_entry', first=True)
740+
self.assertEqual(e.password, 'foobar')
741+
self.kp.save()
742+
self.assertEqual(e.password, 'foobar')
743+
735744

736745
class EntryFindTests4(KDBX4Tests, EntryFindTests3):
737746
pass
738747

739-
740748
class GroupFindTests4(KDBX4Tests, GroupFindTests3):
741749
pass
742750

743-
744751
class EntryTests4(KDBX4Tests, EntryTests3):
745752
pass
746753

747-
748754
class GroupTests3(KDBX4Tests, GroupTests3):
749755
pass
750756

751-
752757
class AttachmentTests4(KDBX4Tests, AttachmentTests3):
753758
pass
754759

755-
756760
class PyKeePassTests4(KDBX4Tests, PyKeePassTests3):
757761
pass
758762

0 commit comments

Comments
 (0)