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