From 5a4f49dffcf2a9c59769c6e0ca5d5a49b3a60f24 Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:17:02 -0500 Subject: [PATCH 1/2] Add MD5 checksum for Bytes parameters --- CHANGELOG.rst | 1 + brewtils/resolvers/bytes.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5bd1fbeb..1b185b53 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ TBD - Added support for display name to command decorator - Updated Wait Timeout Exception expected HTTP code from 408 to 504 - Dropping Official Python 2.7 Support +- Update Bytes file download to validate MD5 checksum 3.29.0 ------ diff --git a/brewtils/resolvers/bytes.py b/brewtils/resolvers/bytes.py index 0391a16c..834df683 100644 --- a/brewtils/resolvers/bytes.py +++ b/brewtils/resolvers/bytes.py @@ -19,4 +19,16 @@ def should_download(self, value, definition): return definition.type.lower() == "bytes" def download(self, value, definition): - return self.easy_client.download_bytes(value.id) + file_bytes = self.easy_client.download_bytes(value.id) + + if value.details: + if ( + "md5_sum" in value.details + and value.details["md5_sum"] + != md5(file_bytes.decode("utf-8").encode("utf-8")).hexdigest() + ): + raise ValidationError( + "Requested file %s MD5 SUM %s does match actual MD5 SUM %s" + % (value.id, value.details["md5_sum"], md5(value).hexdigest()) + ) + return file_bytes From a9f8b668775902376c17161286fa055e509e622f Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:19:55 -0500 Subject: [PATCH 2/2] formatting --- brewtils/resolvers/bytes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brewtils/resolvers/bytes.py b/brewtils/resolvers/bytes.py index 834df683..e70d7ab5 100644 --- a/brewtils/resolvers/bytes.py +++ b/brewtils/resolvers/bytes.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- +from hashlib import md5 + +from brewtils.errors import ValidationError from brewtils.resolvers import ResolverBase