Gentoo Archives: gentoo-portage-dev

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

Replies