Rebase to version 1.5.6

Resolves: RHEL-34809

Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
This commit is contained in:
Rafael Guterres Jeffman 2024-06-12 11:25:09 -03:00
parent 45e498f128
commit 4b3d275c39
5 changed files with 50 additions and 80 deletions

5
.gitignore vendored
View File

@ -8,3 +8,8 @@
/jwcrypto-0.5.0.tar.gz /jwcrypto-0.5.0.tar.gz
/jwcrypto-0.6.0.tar.gz /jwcrypto-0.6.0.tar.gz
/jwcrypto-0.8.tar.gz /jwcrypto-0.8.tar.gz
/jwcrypto-0.9.1.tar.gz
/jwcrypto-1.4.tar.gz
/jwcrypto-1.4.1.tar.gz
/jwcrypto-1.4.2.tar.gz
/jwcrypto-1.5.6.tar.gz

View File

@ -1,74 +0,0 @@
From 90477a3b6e73da69740e00b8161f53fea19b831f Mon Sep 17 00:00:00 2001
From: Simo Sorce <simo@redhat.com>
Date: Tue, 5 Mar 2024 16:57:17 -0500
Subject: [PATCH] Address potential DoS with high compression ratio
Fixes CVE-2024-28102
Signed-off-by: Simo Sorce <simo@redhat.com>
---
jwcrypto/jwe.py | 7 +++++++
jwcrypto/tests.py | 26 ++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/jwcrypto/jwe.py b/jwcrypto/jwe.py
index 9412881..5df500b 100644
--- a/jwcrypto/jwe.py
+++ b/jwcrypto/jwe.py
@@ -10,5 +10,8 @@
from jwcrypto.jwa import JWA
+# Limit the amount of data we are willing to decompress by default.
+default_max_compressed_size = 256 * 1024
+
# RFC 7516 - 4.1
# name: (description, supported?)
@@ -387,6 +387,10 @@ def _decrypt(self, key, ppe):
compress = jh.get('zip', None)
if compress == 'DEF':
+ if len(data) > default_max_compressed_size:
+ raise InvalidJWEData(
+ 'Compressed data exceeds maximum allowed'
+ 'size' + f' ({default_max_compressed_size})')
self.plaintext = zlib.decompress(data, -zlib.MAX_WBITS)
elif compress is None:
self.plaintext = data
diff --git a/jwcrypto/tests.py b/jwcrypto/tests.py
index bb2ff10..59049f8 100644
--- a/jwcrypto/tests.py
+++ b/jwcrypto/tests.py
@@ -1526,6 +1526,32 @@ def test_pbes2_hs256_aeskw_custom_params(self):
token.deserialize(jwt=e)
json_decode(token.claims)
+ def test_jwe_decompression_max(self):
+ key = jwk.JWK(kty='oct', k=base64url_encode(b'A' * (128 // 8)))
+ payload = '{"u": "' + "u" * 400000000 + '", "uu":"' \
+ + "u" * 400000000 + '"}'
+ protected_header = {
+ "alg": "A128KW",
+ "enc": "A128GCM",
+ "typ": "JWE",
+ "zip": "DEF",
+ }
+ enc = jwe.JWE(payload.encode('utf-8'),
+ recipient=key,
+ protected=protected_header).serialize(compact=True)
+ with self.assertRaises(jwe.InvalidJWEData):
+ check = jwe.JWE()
+ check.deserialize(enc)
+ check.decrypt(key)
+
+ defmax = jwe.default_max_compressed_size
+ jwe.default_max_compressed_size = 1000000000
+ # ensure we can eraise the limit and decrypt
+ check = jwe.JWE()
+ check.deserialize(enc)
+ check.decrypt(key)
+ jwe.default_max_compressed_size = defmax
+
class JWATests(unittest.TestCase):
def test_jwa_create(self):

View File

@ -0,0 +1,40 @@
diff -Naur jwcrypto-1.5.6/jwcrypto/jwk.py jwcrypto-1.5.6-new/jwcrypto/jwk.py
--- jwcrypto-1.5.6/jwcrypto/jwk.py 2024-02-07 13:52:39.000000000 -0300
+++ jwcrypto-1.5.6-new/jwcrypto/jwk.py 2024-06-12 13:06:28.553972422 -0300
@@ -11,7 +11,15 @@
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric import rsa
-from typing_extensions import deprecated
+try:
+ from typing_extensions import deprecated
+except ImportError:
+ def deprecated(_fn, *args):
+ def inner(func):
+ return func
+
+ return inner
+
from jwcrypto.common import JWException
from jwcrypto.common import base64url_decode, base64url_encode
diff -Naur jwcrypto-1.5.6/jwcrypto/jwt.py jwcrypto-1.5.6-new/jwcrypto/jwt.py
--- jwcrypto-1.5.6/jwcrypto/jwt.py 2024-02-07 13:52:39.000000000 -0300
+++ jwcrypto-1.5.6-new/jwcrypto/jwt.py 2024-06-12 13:26:48.534696766 -0300
@@ -4,7 +4,15 @@
import time
import uuid
-from typing_extensions import deprecated
+try:
+ from typing_extensions import deprecated
+except ImportError:
+ def deprecated(*args):
+ def inner(func):
+ return func
+
+ return inner
+
from jwcrypto.common import JWException, JWKeyNotFound
from jwcrypto.common import json_decode, json_encode

View File

@ -15,15 +15,15 @@
%global srcname jwcrypto %global srcname jwcrypto
Name: python-%{srcname} Name: python-%{srcname}
Version: 0.8 Version: 1.5.6
Release: 5%{?dist} Release: %autorelease
Summary: Implements JWK, JWS, JWE specifications using python-cryptography Summary: Implements JWK, JWS, JWE specifications using python-cryptography
License: LGPLv3+ License: LGPLv3+
URL: https://github.com/latchset/%{srcname} URL: https://github.com/latchset/%{srcname}
Source0: https://github.com/latchset/%{srcname}/releases/download/v%{version}/%{srcname}-%{version}.tar.gz Source0: https://github.com/latchset/%{srcname}/releases/download/v%{version}/%{srcname}-%{version}.tar.gz
Patch1: 0001-Address-potential-DoS-with-high-compression-ratio_rhel#28698.patch Patch1: 0001-ignore-deprecated-annotation.patch
BuildArch: noarch BuildArch: noarch
%if 0%{?with_python2} %if 0%{?with_python2}
@ -36,7 +36,7 @@ BuildRequires: python2-pytest
%if 0%{?with_python3} %if 0%{?with_python3}
BuildRequires: python%{python3_pkgversion}-devel BuildRequires: python%{python3_pkgversion}-devel
BuildRequires: python%{python3_pkgversion}-setuptools BuildRequires: python%{python3_pkgversion}-setuptools
BuildRequires: python%{python3_pkgversion}-cryptography >= 1.5 BuildRequires: python%{python3_pkgversion}-cryptography >= 2.3
BuildRequires: python%{python3_pkgversion}-pytest BuildRequires: python%{python3_pkgversion}-pytest
%endif %endif

View File

@ -1,2 +1 @@
SHA512 (jwcrypto-0.6.0.tar.gz) = ed72f4be0f19afe448048e4124d5cbdd227b66b2b0af375cb1ab6c631c6e0d638f40cc1d756eb052176934eb919fa16b40bf51b5380b9227b162cfb6d3f5256e SHA512 (jwcrypto-1.5.6.tar.gz) = 1db62cf247bc006f1737c4603b80e5ca87e1a3db3b3dc37183a9725a8b3cae4baba706b2ec596119877130ab4d56525a01fb9d7efca07e59811d78021aa7ebf5
SHA512 (jwcrypto-0.8.tar.gz) = e8dc62d6159e5722a572e049c41edc8e31fe0d022aa47987ab6720c7057cbac2f98cec5d35af1ea02f6bc6efde769810fde4b868e019956b138cfac529cc027d