Merge pull request #72 from alan-strohm/maintenance/gramps42

9076: don't check SSL certs on Mac when fetching addons.
This commit is contained in:
John Ralls 2015-11-27 13:00:53 -08:00
commit 0f72a796c2

View File

@ -173,8 +173,11 @@ class Zipfile(object):
""" """
return os.path.split(name)[1] return os.path.split(name)[1]
def available_updates(): def urlopen_maybe_no_check_cert(URL):
whattypes = config.get('behavior.check-for-update-types') """
Similar to urllib.request.urlopen, but disables certificate
verification on Mac.
"""
context = None context = None
from urllib.request import urlopen from urllib.request import urlopen
if mac(): if mac():
@ -182,6 +185,16 @@ def available_updates():
context = create_default_context() context = create_default_context()
context.check_hostname = False context.check_hostname = False
context.verify_mode = CERT_NONE context.verify_mode = CERT_NONE
timeout = 10 # seconds
fp = None
try:
fp = urlopen(URL, timeout=timeout, context=context)
except TypeError:
fp = urlopen(URL, timeout=timeout)
return fp
def available_updates():
whattypes = config.get('behavior.check-for-update-types')
LOG.debug("Checking for updated addons...") LOG.debug("Checking for updated addons...")
langs = glocale.get_language_list() langs = glocale.get_language_list()
@ -193,16 +206,12 @@ def available_updates():
(config.get("behavior.addons-url"), lang)) (config.get("behavior.addons-url"), lang))
LOG.debug(" trying: %s" % URL) LOG.debug(" trying: %s" % URL)
try: try:
fp = urlopen(URL, timeout=10, context=context) # seconds fp = urlopen_maybe_no_check_cert(URL)
except: except:
try: try:
URL = ("%s/listings/addons-%s.txt" % URL = ("%s/listings/addons-%s.txt" %
(config.get("behavior.addons-url"), lang[:2])) (config.get("behavior.addons-url"), lang[:2]))
fp = urlopen(URL, timeout=10, context=context) fp = urlopen_maybe_no_check_cert(URL)
except TypeError:
URL = ("%s/listings/addons-%s.txt" %
(config.get("behavior.addons-url"), lang[:2]))
fp = urlopen(URL, timeout=10)
except Exception as err: # some error except Exception as err: # some error
LOG.warning("Failed to open addon metadata for {lang} {url}: {err}". LOG.warning("Failed to open addon metadata for {lang} {url}: {err}".
format(lang=lang, url=URL, err=err)) format(lang=lang, url=URL, err=err))
@ -277,7 +286,7 @@ def load_addon_file(path, callback=None):
path.startswith("https://") or path.startswith("https://") or
path.startswith("ftp://")): path.startswith("ftp://")):
try: try:
fp = urlopen(path) fp = urlopen_maybe_no_check_cert(path)
except: except:
if callback: if callback:
callback(_("Unable to open '%s'") % path) callback(_("Unable to open '%s'") % path)