wrap: add functionality to specify whether insecure downloads should be used

We have a fallback route in `meson subprojects download` and friends,
which tries to retrieve wrapdb urls via http, if Python was not built
with SSL support.

Stop doing this. Replace it with a command line option to specify that
insecure downloads are wanted, and reference it in the error message if
downloading fails due to SSL issues.
pull/10200/head
Eli Schwartz 3 years ago committed by Xavier Claessens
parent aa495ff758
commit b28e6aead4
  1. 5
      mesonbuild/msubprojects.py
  2. 35
      mesonbuild/wrap/wrap.py

@ -25,6 +25,7 @@ if T.TYPE_CHECKING:
subprojects: T.List[str]
types: str
subprojects_func: T.Callable[[], bool]
allow_insecure: bool
class UpdateArguments(Arguments):
rebase: bool
@ -575,6 +576,8 @@ def add_common_arguments(p: argparse.ArgumentParser) -> None:
help=f'Comma-separated list of subproject types. Supported types are: {ALL_TYPES_STRING} (default: all)')
p.add_argument('--num-processes', default=None, type=int,
help='How many parallel processes to use (Since 0.59.0).')
p.add_argument('--allow-insecure', default=False, action='store_true',
help='Allow insecure server connections.')
def add_subprojects_argument(p: argparse.ArgumentParser) -> None:
p.add_argument('subprojects', nargs='*',
@ -643,7 +646,7 @@ def run(options: 'Arguments') -> int:
if not os.path.isdir(subprojects_dir):
mlog.log('Directory', mlog.bold(src_dir), 'does not seem to have subprojects.')
return 0
r = Resolver(src_dir, 'subprojects')
r = Resolver(src_dir, 'subprojects', wrap_frontend=True, allow_insecure=options.allow_insecure)
if options.subprojects:
wraps = [wrap for name, wrap in r.wraps.items() if name in options.subprojects]
else:

@ -66,21 +66,36 @@ def whitelist_wrapdb(urlstr: str) -> urllib.parse.ParseResult:
raise WrapException(f'WrapDB did not have expected SSL https url, instead got {urlstr}')
return url
def open_wrapdburl(urlstring: str) -> 'http.client.HTTPResponse':
global SSL_WARNING_PRINTED
def open_wrapdburl(urlstring: str, allow_insecure: bool = False, have_opt: bool = False) -> 'http.client.HTTPResponse':
if have_opt:
insecure_msg = '\n\n To allow connecting anyway, pass `--allow-insecure`.'
else:
insecure_msg = ''
url = whitelist_wrapdb(urlstring)
if has_ssl:
try:
return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(url), timeout=REQ_TIMEOUT))
except urllib.error.URLError as excp:
raise WrapException(f'WrapDB connection failed to {urlstring} with error {excp}')
# following code is only for those without Python SSL
msg = f'WrapDB connection failed to {urlstring} with error {excp}.'
if isinstance(excp.reason, ssl.SSLCertVerificationError):
if allow_insecure:
mlog.warning(f'{msg}\n\n Proceeding without authentication.')
else:
raise WrapException(f'{msg}{insecure_msg}')
else:
raise WrapException(msg)
elif not allow_insecure:
raise WrapException(f'SSL module not available in {sys.executable}: Cannot contact the WrapDB.{insecure_msg}')
else:
# following code is only for those without Python SSL
global SSL_WARNING_PRINTED
if not SSL_WARNING_PRINTED:
mlog.warning(f'SSL module not available in {sys.executable}: WrapDB traffic not authenticated.')
SSL_WARNING_PRINTED = True
# If we got this far, allow_insecure was manually passed
nossl_url = url._replace(scheme='http')
if not SSL_WARNING_PRINTED:
mlog.warning(f'SSL module not available in {sys.executable}: WrapDB traffic not authenticated.')
SSL_WARNING_PRINTED = True
try:
return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(nossl_url), timeout=REQ_TIMEOUT))
except urllib.error.URLError as excp:
@ -212,6 +227,8 @@ class Resolver:
subdir: str
subproject: str = ''
wrap_mode: WrapMode = WrapMode.default
wrap_frontend: bool = False
allow_insecure: bool = False
def __post_init__(self) -> None:
self.subdir_root = os.path.join(self.source_dir, self.subdir)
@ -491,7 +508,7 @@ class Resolver:
tmpfile = tempfile.NamedTemporaryFile(mode='wb', dir=self.cachedir, delete=False)
url = urllib.parse.urlparse(urlstring)
if url.hostname and url.hostname.endswith(WHITELIST_SUBDOMAIN):
resp = open_wrapdburl(urlstring)
resp = open_wrapdburl(urlstring, allow_insecure=self.allow_insecure, have_opt=self.wrap_frontend)
elif WHITELIST_SUBDOMAIN in urlstring:
raise WrapException(f'{urlstring} may be a WrapDB-impersonating URL')
else:

Loading…
Cancel
Save