!6 fix CVE-2020-13757

Merge pull request !6 from Markeryang/master
This commit is contained in:
openeuler-ci-bot 2020-08-04 19:08:28 +08:00 committed by Gitee
commit 88ab024267
2 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,48 @@
From 93af6f2f89a9bf28361e67716c4240e691520f30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu>
Date: Wed, 3 Jun 2020 14:39:23 +0200
Subject: [PATCH] Fix CVE-2020-13757: detect cyphertext modifications by
prepending zero bytes
Reject cyphertexts that have been modified by prepending zero bytes, by
checking the cyphertext length against the expected size (given the
decryption key). This resolves CVE-2020-13757.
The same approach is used when verifying a signature.
Thanks Carnil for pointing this out on https://github.com/sybrenstuvel/python-rsa/issues/146
---
rsa/pkcs1.py | 9 +++++++++
1 files changed, 9 insertions(+)
diff --git a/rsa/pkcs1.py b/rsa/pkcs1.py
index 28f0dc5..cdf830b 100644
--- a/rsa/pkcs1.py
+++ b/rsa/pkcs1.py
@@ -232,6 +232,12 @@ def decrypt(crypto, priv_key):
decrypted = priv_key.blinded_decrypt(encrypted)
cleartext = transform.int2bytes(decrypted, blocksize)
+ # Detect leading zeroes in the crypto. These are not reflected in the
+ # encrypted value (as leading zeroes do not influence the value of an
+ # integer). This fixes CVE-2020-13757.
+ if len(crypto) > blocksize:
+ raise DecryptionError('Decryption failed')
+
# If we can't find the cleartext marker, decryption failed.
if cleartext[0:2] != b('\x00\x02'):
raise DecryptionError('Decryption failed')
@@ -310,6 +316,9 @@ def verify(message, signature, pub_key):
cleartext = HASH_ASN1[method_name] + message_hash
expected = _pad_for_signing(cleartext, keylength)
+ if len(signature) != keylength:
+ raise VerificationError('Verification failed')
+
# Compare with the signed one
if expected != clearsig:
raise VerificationError('Verification failed')
--
1.8.3.1

View File

@ -1,12 +1,14 @@
Name: python-rsa Name: python-rsa
Version: 3.4.2 Version: 3.4.2
Release: 11 Release: 12
Summary: Pure-Python RSA implementation Summary: Pure-Python RSA implementation
License: ASL 2.0 License: ASL 2.0
URL: http://stuvel.eu/rsa URL: http://stuvel.eu/rsa
Source0: https://pypi.python.org/packages/source/r/rsa/rsa-%{version}.tar.gz Source0: https://pypi.python.org/packages/source/r/rsa/rsa-%{version}.tar.gz
BuildArch: noarch BuildArch: noarch
Patch1: 0001-Fix-CVE-2020-13757.patch
%description %description
Python-RSA is a pure-Python RSA implementation. It supports Python-RSA is a pure-Python RSA implementation. It supports
encryption and decryption, signing and verifying signatures, encryption and decryption, signing and verifying signatures,
@ -79,5 +81,8 @@ mv $RPM_BUILD_ROOT%{_bindir}/pyrsa-decrypt-bigfile $RPM_BUILD_ROOT%{_bindir}/pyr
%{__python3} setup.py test %{__python3} setup.py test
%changelog %changelog
* Tue Aug 4 2020 yanglongkang <yanglongkang@huawei.com> - 3.4.2-12
- fix CVE-2020-13757
* Mon Feb 10 2020 Ruijun Ge <geruijun@huawei.com> - 3.4.2-11 * Mon Feb 10 2020 Ruijun Ge <geruijun@huawei.com> - 3.4.2-11
- package init - package init