Skip to content

Commit

Permalink
pykeepass: Update to 4.0.7.post1
Browse files Browse the repository at this point in the history
We also update the patch with commit actually merged as part of
libkeepass/pykeepass#388.
  • Loading branch information
A6GibKm committed Apr 11, 2024
1 parent a2d0db9 commit f95e0fc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
83 changes: 59 additions & 24 deletions 0001-Fix-composite-key-computation-for-BytesIO.patch
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
From fca73313b77d2c8ea32db8b21858745500c334ec Mon Sep 17 00:00:00 2001
From: Jan-Michael Brummer <jan[email protected]>
Date: Tue, 26 Mar 2024 10:27:48 +0100
Subject: [PATCH] Fix composite key computation for BytesIO
From 6e591b43d60cc6e1552cf2ef8cce6ac6c59a0265 Mon Sep 17 00:00:00 2001
From: Jan-Michael Brummer <jan[email protected]>
Date: Tue, 9 Apr 2024 21:58:09 +0200
Subject: [PATCH] Fix composite key computation for BytesIO (#388)

In case a keyfile as BytesIO has been read before, the
next read will be empty. We need to ensure that we
are reading the data from the beginning.

Add seek to start to fix it.

Co-authored-by: Jan-Michael Brummer <[email protected]>
---
pykeepass/kdbx_parsing/common.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
pykeepass/kdbx_parsing/common.py | 6 ++++--
tests/tests.py | 14 ++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/pykeepass/kdbx_parsing/common.py b/pykeepass/kdbx_parsing/common.py
index 3973f61..1865bb4 100644
index 5542a0b..ac42d8c 100644
--- a/pykeepass/kdbx_parsing/common.py
+++ b/pykeepass/kdbx_parsing/common.py
@@ -13,6 +13,7 @@ import unicodedata
import zlib
import re
@@ -1,13 +1,13 @@
import base64
import codecs
import hashlib
+import io
from io import BytesIO
from collections import OrderedDict
import logging
@@ -116,7 +117,13 @@ def compute_key_composite(password=None, keyfile=None):
password_composite = b''
import re
import zlib
from binascii import Error as BinasciiError
from collections import OrderedDict
from copy import deepcopy
-from io import BytesIO

from construct import (
Adapter,
@@ -128,6 +128,8 @@ def compute_key_composite(password=None, keyfile=None):
# hash the keyfile
if keyfile:
- if hasattr(keyfile, "read"):
+ if (
+ isinstance(keyfile, io.BufferedIOBase)
+ or isinstance(keyfile, io.TextIOBase)
+ or isinstance(keyfile, io.RawIOBase)
+ ):
+ if keyfile.seekable():
if hasattr(keyfile, "read"):
+ if hasattr(keyfile, "seekable") and keyfile.seekable():
+ keyfile.seek(0)
keyfile_bytes = keyfile.read()
else:
with open(keyfile, 'rb') as f:
--
2.44.0

@@ -194,7 +196,7 @@ class XML(Adapter):

def _decode(self, data, con, path):
parser = etree.XMLParser(remove_blank_text=True)
- return etree.parse(BytesIO(data), parser)
+ return etree.parse(io.BytesIO(data), parser)

def _encode(self, tree, con, path):
return etree.tostring(tree)
diff --git a/tests/tests.py b/tests/tests.py
index 7584219..5bc02b6 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -875,6 +875,20 @@ def test_fields(self):


class PyKeePassTests3(KDBX3Tests):
+ def test_consecutives_saves_with_stream(self):
+ # https://github.com/libkeepass/pykeepass/pull/388
+ self.setUp()
+
+ with open(base_dir / self.keyfile_tmp, 'rb') as f:
+ keyfile = BytesIO(f.read())
+
+ for _i in range(5):
+ with PyKeePass(
+ base_dir / self.database_tmp,
+ password=self.password,
+ keyfile=keyfile,
+ ) as kp:
+ kp.save()

def test_set_credentials(self):
self.kp_tmp.password = 'f00bar'
4 changes: 2 additions & 2 deletions python3-pykeepass.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"sources": [
{
"type": "archive",
"url": "https://files.pythonhosted.org/packages/e1/ca/2da205bb1baa9f86b9cc36145ab5435fbc50ee3cc136e4a90356dbbdc3d2/pykeepass-4.0.7.tar.gz",
"sha256": "56ce2a1d22c204c838e6501796e0acce8ba9f50ade821111aaa1458f9d1a775e"
"url": "https://files.pythonhosted.org/packages/c5/3a/dc4c067aa600e7fdb38a4981ce40768fc75c6b6b708f305ec7c94c767f72/pykeepass-4.0.7.post1.tar.gz",
"sha256": "04090d79cf121686b51c4c84d5bc6a62cd47b8337f8c0158caa9e845df803131"
},
{
"type": "patch",
Expand Down

0 comments on commit f95e0fc

Please sign in to comment.