Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/, pym/portage/dbapi/
Date: Mon, 31 Jul 2017 16:31:23
Message-Id: 1501518605.1d821469d6b72ce051b02908f17302c500945788.zmedico@gentoo
1 commit: 1d821469d6b72ce051b02908f17302c500945788
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jul 19 07:25:05 2017 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Jul 31 16:30:05 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1d821469
7
8 emerge --getbinpkg: https support for If-Modified-Since
9
10 When https certificate and hostname verification is enabled for
11 stdlib http clients (PEP 476), use python for If-Modified-Since
12 header support. When python lacks PEP 476 support, continue to
13 use FETCHCOMMAND for https certificate and hostname verification
14 (see security bug 469888).
15
16 X-Gentoo-bug: 625246
17 X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=625246
18 Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>
19
20 pym/portage/dbapi/bintree.py | 10 ++++++----
21 pym/portage/util/_urlopen.py | 12 ++++++++++++
22 2 files changed, 18 insertions(+), 4 deletions(-)
23
24 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
25 index c833968c2..95bd5dbf8 100644
26 --- a/pym/portage/dbapi/bintree.py
27 +++ b/pym/portage/dbapi/bintree.py
28 @@ -18,7 +18,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
29 'portage.util:atomic_ofstream,ensure_dirs,normalize_path,' + \
30 'writemsg,writemsg_stdout',
31 'portage.util.path:first_existing',
32 - 'portage.util._urlopen:urlopen@_urlopen',
33 + 'portage.util._urlopen:urlopen@_urlopen,have_pep_476@_have_pep_476',
34 'portage.versions:best,catpkgsplit,catsplit,_pkg_str',
35 )
36
37 @@ -851,9 +851,9 @@ class binarytree(object):
38 download_timestamp + ttl > time.time():
39 raise UseCachedCopyOfRemoteIndex()
40
41 - # Don't use urlopen for https, since it doesn't support
42 - # certificate/hostname verification (bug #469888).
43 - if parsed_url.scheme not in ('https',):
44 + # Don't use urlopen for https, unless
45 + # PEP 476 is supported (bug #469888).
46 + if parsed_url.scheme not in ('https',) or _have_pep_476():
47 try:
48 f = _urlopen(url, if_modified_since=local_timestamp)
49 if hasattr(f, 'headers') and f.headers.get('timestamp', ''):
50 @@ -965,6 +965,8 @@ class binarytree(object):
51 "\n")
52 rmt_idx = pkgindex
53 except EnvironmentError as e:
54 + # This includes URLError which is raised for SSL
55 + # certificate errors when PEP 476 is supported.
56 writemsg(_("\n\n!!! Error fetching binhost package" \
57 " info from '%s'\n") % _hide_url_passwd(base_url))
58 # With Python 2, the EnvironmentError message may
59
60 diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py
61 index 4cfe183b1..fc9db74a0 100644
62 --- a/pym/portage/util/_urlopen.py
63 +++ b/pym/portage/util/_urlopen.py
64 @@ -26,6 +26,18 @@ if sys.hexversion >= 0x3000000:
65 # and the file-'mtime'
66 TIMESTAMP_TOLERANCE = 5
67
68 +
69 +def have_pep_476():
70 + """
71 + Test whether ssl certificate verification is enabled by default for
72 + stdlib http clients (PEP 476).
73 +
74 + @returns: bool, True if ssl certificate verification is enabled by
75 + default
76 + """
77 + return hasattr(__import__('ssl'), '_create_unverified_context')
78 +
79 +
80 def urlopen(url, if_modified_since=None):
81 parse_result = urllib_parse.urlparse(url)
82 if parse_result.scheme not in ("http", "https"):