From faad1a9852d00930e17bc8a476a5a5c9db547378 Mon Sep 17 00:00:00 2001 From: Olivier Bilodeau Date: Fri, 12 Mar 2021 15:50:08 -0500 Subject: [PATCH 1/3] FileMapping getHash is getSha1Hash now, updated internal callers --- pyrdp/mitm/FileMapping.py | 4 ++-- test/test_FileMapping.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrdp/mitm/FileMapping.py b/pyrdp/mitm/FileMapping.py index 8414cc2f2..d591db950 100644 --- a/pyrdp/mitm/FileMapping.py +++ b/pyrdp/mitm/FileMapping.py @@ -39,7 +39,7 @@ def write(self, data: bytes): self.file.write(data) self.written = True - def getHash(self): + def getSha1Hash(self): with open(self.dataPath, "rb") as f: sha1 = hashlib.sha1() @@ -57,7 +57,7 @@ def finalize(self): self.log.debug("Closing file %(path)s", {"path": self.dataPath}) self.file.close() - fileHash = self.getHash() + fileHash = self.getSha1Hash() # Go up one directory because files are saved to outDir / tmp while we're downloading them hashPath = (self.dataPath.parents[1] / fileHash) diff --git a/test/test_FileMapping.py b/test/test_FileMapping.py index 2c079ae0b..f32aed273 100644 --- a/test/test_FileMapping.py +++ b/test/test_FileMapping.py @@ -17,7 +17,7 @@ def setUp(self): def createMapping(self, mkdir: MagicMock, mkstemp: MagicMock, mock_open_object): mkstemp.return_value = (1, str(self.outDir / "tmp" / "tmp_test")) mapping = FileMapping.generate("/test", self.outDir, Path("filesystems"), self.log) - mapping.getHash = Mock(return_value = self.hash) + mapping.getSha1Hash = Mock(return_value = self.hash) return mapping, mkdir, mkstemp, mock_open_object def test_generate_createsTempFile(self): From 4c6026b7be3b992f1b6de8c8295d6f1f48e4f569 Mon Sep 17 00:00:00 2001 From: Olivier Bilodeau Date: Fri, 12 Mar 2021 15:52:20 -0500 Subject: [PATCH 2/3] logs: renamed hash field to shasum to align with industry practices --- pyrdp/mitm/FileMapping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrdp/mitm/FileMapping.py b/pyrdp/mitm/FileMapping.py index d591db950..5eab2f7fa 100644 --- a/pyrdp/mitm/FileMapping.py +++ b/pyrdp/mitm/FileMapping.py @@ -78,8 +78,8 @@ def finalize(self): # Make the symlink relative so you can move the output folder around and it will still work. self.filesystemPath.symlink_to(Path(os.path.relpath(hashPath, self.filesystemPath.parent))) - self.log.info("SHA1 '%(path)s' = '%(hash)s'", { - "path": self.filesystemPath.relative_to(self.filesystemDir), "hash": fileHash + self.log.info("SHA1 '%(path)s' = '%(shasum)s'", { + "path": self.filesystemPath.relative_to(self.filesystemDir), "shasum": fileHash }) @staticmethod From a49d0e8bb79be08c8c9936b2c528905bb9c24ce4 Mon Sep 17 00:00:00 2001 From: Olivier Bilodeau Date: Fri, 12 Mar 2021 16:05:36 -0500 Subject: [PATCH 3/3] Use string representation of Path object in logs Having the PosixPath() string wrapped around is a python-specific detail that doesn't add value to logs --- pyrdp/mitm/FileMapping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrdp/mitm/FileMapping.py b/pyrdp/mitm/FileMapping.py index 5eab2f7fa..ee77116d3 100644 --- a/pyrdp/mitm/FileMapping.py +++ b/pyrdp/mitm/FileMapping.py @@ -79,7 +79,7 @@ def finalize(self): self.filesystemPath.symlink_to(Path(os.path.relpath(hashPath, self.filesystemPath.parent))) self.log.info("SHA1 '%(path)s' = '%(shasum)s'", { - "path": self.filesystemPath.relative_to(self.filesystemDir), "shasum": fileHash + "path": str(self.filesystemPath.relative_to(self.filesystemDir)), "shasum": fileHash }) @staticmethod @@ -94,7 +94,7 @@ def generate(remotePath: str, outDir: Path, filesystemDir: Path, log: LoggerAdap file = open(handle, "wb") log.info("Saving file '%(remotePath)s' to '%(localPath)s'", { - "localPath": tmpPath, "remotePath": remotePath + "localPath": str(tmpPath), "remotePath": str(remotePath) }) return FileMapping(file, Path(tmpPath), filesystemPath, filesystemDir, log)