2090b3
%bcond_with python3
55fde0
55fde0
%global srcname urllib3
55fde0
55fde0
Name:           python-%{srcname}
f594b0
Version:        1.24.2
2090b3
Release:        3%{?dist}
55fde0
Summary:        Python HTTP library with thread-safe connection pooling and file post
55fde0
55fde0
License:        MIT
55fde0
URL:            https://github.com/shazow/urllib3
55fde0
Source0:        %{url}/archive/%{version}/%{srcname}-%{version}.tar.gz
55fde0
# Used with Python 3.5+
55fde0
Source1:        ssl_match_hostname_py3.py
55fde0
BuildArch:      noarch
55fde0
f594b0
# CVE-2019-11236 python-urllib3:
f594b0
#   - CRLF injection due to not encoding the '\r\n' sequence leading to
f594b0
#     possible attack on internal service.
f594b0
#   - Also known as CVE-2019-9740 (duplicate entry)
f594b0
# Backported from:
f594b0
#  * https://github.com/urllib3/urllib3/pull/1591
f594b0
#    - Superfluous commits were omitted (flake8 checks, travis settings, macos patch)
f594b0
#  * https://github.com/urllib3/urllib3/pull/1593
f594b0
Patch1:         CVE-2019-11236.patch
f594b0
2090b3
# CVE-2020-26137
2090b3
# CRLF injection via HTTP request method
2090b3
# Resolved upstream: https://github.com/urllib3/urllib3/pull/1800
2090b3
Patch2: CVE-2020-26137.patch
2090b3
f594b0
55fde0
%description
55fde0
Python HTTP module with connection pooling and file POST abilities.
55fde0
55fde0
%package -n python2-%{srcname}
55fde0
Summary:        Python2 HTTP library with thread-safe connection pooling and file post
55fde0
%{?python_provide:%python_provide python2-%{srcname}}
55fde0
55fde0
Requires:       ca-certificates
55fde0
55fde0
# Previously bundled things:
55fde0
Requires:       python2-six
55fde0
Requires:       python2-backports-ssl_match_hostname
55fde0
55fde0
# Secure extra requirements
55fde0
Requires:       python2-ipaddress
55fde0
Requires:       python2-pysocks
55fde0
55fde0
BuildRequires:  python2-devel
55fde0
55fde0
# For tests
55fde0
BuildRequires:  python2-pytest
55fde0
BuildRequires:  python2-mock
55fde0
BuildRequires:  python2-pysocks
f594b0
BuildRequires:  python2-backports-ssl_match_hostname
55fde0
55fde0
%description -n python2-%{srcname}
55fde0
Python2 HTTP module with connection pooling and file POST abilities.
55fde0
55fde0
55fde0
%if %{with python3}
55fde0
%package -n python3-%{srcname}
55fde0
Summary:        Python3 HTTP library with thread-safe connection pooling and file post
55fde0
55fde0
BuildRequires:  python3-devel
55fde0
# For unittests
55fde0
BuildRequires:  python3-mock
55fde0
BuildRequires:  python3-six
55fde0
BuildRequires:  python3-pysocks
55fde0
BuildRequires:  python3-pytest
55fde0
55fde0
Requires:       ca-certificates
55fde0
Requires:       python3-six
55fde0
Requires:       python3-pysocks
55fde0
55fde0
%description -n python3-%{srcname}
55fde0
Python3 HTTP module with connection pooling and file POST abilities.
55fde0
55fde0
%endif
55fde0
55fde0
%prep
55fde0
%setup -q -n %{srcname}-%{version}
f594b0
f594b0
%patch1 -p1
2090b3
%patch2 -p1
f594b0
55fde0
# Drop the dummyserver tests in koji.
55fde0
# These require tornado, a Web framework otherwise unused in the distro.
55fde0
rm -rf test/with_dummyserver/
55fde0
rm -rf test/test_connectionpool.py
55fde0
rm -rf dummyserver/
55fde0
# Don't run the Google App Engine tests
55fde0
rm -rf test/appengine/
55fde0
# Lots of these tests started failing, even for old versions, so it has something
55fde0
# to do with Fedora in particular. They don't fail in upstream build infrastructure
55fde0
rm -rf test/contrib/
55fde0
f594b0
# Tests for Python built without SSL, but RHEL builds with SSL. These tests
f594b0
# fail when combined with the unbundling of backports-ssl_match_hostname
f594b0
rm -f test/test_no_ssl.py
721b52
2090b3
# Make sure that the RECENT_DATE value doesn't get too far behind what the current date is.
2090b3
# RECENT_DATE must not be older that 2 years from the build time, or else test_recent_date
2090b3
# (from test/test_connection.py) would fail. However, it shouldn't be to close to the build time either,
2090b3
# since a user's system time could be set to a little in the past from what build time is (because of timezones,
2090b3
# corner cases, etc). As stated in the comment in src/urllib3/connection.py:
2090b3
#   When updating RECENT_DATE, move it to within two years of the current date,
2090b3
#   and not less than 6 months ago.
2090b3
#   Example: if Today is 2018-01-01, then RECENT_DATE should be any date on or
2090b3
#   after 2016-01-01 (today - 2 years) AND before 2017-07-01 (today - 6 months)
2090b3
# There is also a test_ssl_wrong_system_time test (from test/with_dummyserver/test_https.py) that tests if
2090b3
# user's system time isn't set as too far in the past, because it could lead to SSL verification errors.
2090b3
# That is why we need RECENT_DATE to be set at most 2 years ago (or else test_ssl_wrong_system_time would
2090b3
# result in false positive), but before at least 6 month ago (so this test could tolerate user's system time being
2090b3
# set to some time in the past, but not to far away from the present).
2090b3
# Next few lines update RECENT_DATE dynamically.
2090b3
2090b3
recent_date=$(date --date "7 month ago" +"%Y, %_m, %_d")
2090b3
sed -i "s/^RECENT_DATE = datetime.date(.*)/RECENT_DATE = datetime.date($recent_date)/" src/urllib3/connection.py
2090b3
Brian Stinson adf068
55fde0
%build
55fde0
%py2_build
55fde0
%if %{with python3}
55fde0
%py3_build
55fde0
%endif
55fde0
55fde0
55fde0
%install
55fde0
%py2_install
55fde0
%if %{with python3}
55fde0
%py3_install
55fde0
%endif
55fde0
55fde0
# Unbundle the Python 2 build
55fde0
rm -rf %{buildroot}/%{python2_sitelib}/urllib3/packages/six.py*
55fde0
rm -rf %{buildroot}/%{python2_sitelib}/urllib3/packages/ssl_match_hostname/
55fde0
55fde0
mkdir -p %{buildroot}/%{python2_sitelib}/urllib3/packages/
f594b0
ln -s %{python2_sitelib}/six.py %{buildroot}/%{python2_sitelib}/urllib3/packages/six.py
f594b0
ln -s %{python2_sitelib}/six.pyc %{buildroot}/%{python2_sitelib}/urllib3/packages/six.pyc
f594b0
ln -s %{python2_sitelib}/six.pyo %{buildroot}/%{python2_sitelib}/urllib3/packages/six.pyo
55fde0
f594b0
ln -s %{python2_sitelib}/backports/ssl_match_hostname %{buildroot}/%{python2_sitelib}/urllib3/packages/ssl_match_hostname
55fde0
55fde0
%if %{with python3}
55fde0
# Unbundle the Python 3 build
55fde0
rm -rf %{buildroot}/%{python3_sitelib}/urllib3/packages/six.py*
55fde0
rm -rf %{buildroot}/%{python3_sitelib}/urllib3/packages/__pycache__/six*
55fde0
rm -rf %{buildroot}/%{python3_sitelib}/urllib3/packages/ssl_match_hostname/
55fde0
55fde0
mkdir -p %{buildroot}/%{python3_sitelib}/urllib3/packages/
f594b0
ln -s %{python3_sitelib}/six.py \
f594b0
      %{buildroot}/%{python3_sitelib}/urllib3/packages/six.py
f594b0
ln -s %{python3_sitelib}/__pycache__/six.cpython-%{python3_version_nodots}.opt-1.pyc \
f594b0
      %{buildroot}/%{python3_sitelib}/urllib3/packages/__pycache__/
f594b0
ln -s %{python3_sitelib}/__pycache__/six.cpython-%{python3_version_nodots}.pyc \
f594b0
      %{buildroot}/%{python3_sitelib}/urllib3/packages/__pycache__/
55fde0
# urllib3 requires Python 3.5 to use the standard library's match_hostname,
f594b0
# which we ship in RHEL8, so we can safely replace the bundled version with
55fde0
# this stub which imports the necessary objects.
55fde0
cp %{SOURCE1} %{buildroot}/%{python3_sitelib}/urllib3/packages/ssl_match_hostname.py
55fde0
%endif
55fde0
55fde0
%check
f594b0
pushd test
f594b0
PYTHONPATH=%{buildroot}%{python2_sitelib}:%{python2_sitelib} %{__python2} -m pytest -v
f594b0
popd
55fde0
%if %{with python3}
55fde0
py.test-3
55fde0
%endif
55fde0
55fde0
%files -n python2-%{srcname}
55fde0
%license LICENSE.txt
55fde0
%doc CHANGES.rst README.rst CONTRIBUTORS.txt
55fde0
%{python2_sitelib}/urllib3/
55fde0
%{python2_sitelib}/urllib3-*.egg-info
55fde0
55fde0
55fde0
%if %{with python3}
55fde0
%files -n python3-%{srcname}
55fde0
%license LICENSE.txt
55fde0
%doc CHANGES.rst README.rst CONTRIBUTORS.txt
55fde0
%{python3_sitelib}/urllib3/
55fde0
%{python3_sitelib}/urllib3-*.egg-info
55fde0
%endif
55fde0
55fde0
55fde0
%changelog
2090b3
* Thu Nov 12 2020 Tomas Orsava <torsava@redhat.com> - 1.24.2-3
2090b3
- Update RECENT_DATE dynamically
2090b3
Related: rhbz#1883890 rhbz#1761380
2090b3
2090b3
* Fri Oct 09 2020 Charalampos Stratakis <cstratak@redhat.com> - 1.24.2-2
2090b3
- Security fix for CVE-2020-26137
2090b3
Resolves: rhbz#1883890
2090b3
f594b0
* Fri May 03 2019 Tomas Orsava <torsava@redhat.com> - 1.24.2-1
f594b0
- Rebased to 1.24.2 to fix CVE-2019-11324
f594b0
- Added patches for CVE-2019-11236 (AKA CVE-2019-9740)
f594b0
- Resolves: rhbz#1706765 rhbz#1706762
721b52
f594b0
* Thu Apr 25 2019 Tomas Orsava <torsava@redhat.com> - 1.23-7
f594b0
- Bumping due to problems with modular RPM upgrade path
f594b0
- Resolves: rhbz#1695587
8fc530
55fde0
* Tue Jul 31 2018 Lumír Balhar <lbalhar@redhat.com> - 1.23-6
55fde0
- Make possible to disable python3 subpackage
f594b0
55fde0
* Mon Jul 16 2018 Lumír Balhar <lbalhar@redhat.com> - 1.23-5
55fde0
- First version for python27 module