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