Skip to content

Commit

Permalink
Add skip ssl check to Goma tpl build script
Browse files Browse the repository at this point in the history
  • Loading branch information
wortiz committed Oct 3, 2024
1 parent 6e16608 commit 093b636
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions tpls/install-tpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
parser.add_argument(
"INSTALL_DIR", help="Install location of TPLs", type=pathlib.Path
)
parser.add_argument(
"--skip-ssl-verify",
help="Disable SSL checks on download",
dest="skip_ssl_verify",
action="store_true",
)
parser.set_defaults(skip_ssl_verify=False)

for p in packages:
pm = importlib.import_module("tpl_tools." + ".".join(["packages", p]))
Expand Down Expand Up @@ -204,6 +211,7 @@
tpl_registry,
args.build_shared,
prebuilt=True,
skip_ssl_verify=args.skip_ssl_verify
)
if build.check(True):
build.logger.log("Package {} found at {}".format(pc.name, package_dir))
Expand Down
4 changes: 3 additions & 1 deletion tpls/tpl_tools/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
registry,
build_shared,
prebuilt=False,
skip_ssl_verify=False,
):
self._dependencies = []
self._configure_options = []
Expand Down Expand Up @@ -66,7 +67,8 @@ def download(self):
sha256 = self._package.sha256
filename = os.path.join(self._download_dir, self._package.filename)
self.logger.log("Downloading file: {}".format(filename))
success = utils.download_file(url, filename, sha256)
verify = not self.skip_ssl_verify
success = utils.download_file(url, filename, sha256, verify)
if success:
self.logger.log("Successfully downloaded: {}".format(filename))
return success
Expand Down
14 changes: 11 additions & 3 deletions tpls/tpl_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def find_file(name, path):
return None


def download_file(url, filename, sha256=None):
def download_file(url, filename, sha256=None, verify=True):
skip_download = False
if os.path.exists(filename):
print("")
Expand All @@ -56,8 +56,16 @@ def download_file(url, filename, sha256=None):
skip_download = True

if not skip_download:
with urllib.request.urlopen(url) as req, open(filename, "wb") as f:
shutil.copyfileobj(req, f)
if verify:
with urllib.request.urlopen(url) as req, open(filename, "wb") as f:
shutil.copyfileobj(req, f)
else:
import ssl
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(url, context=context) as req, open(filename, "wb") as f:
shutil.copyfileobj(req, f)

if os.path.isfile(filename):
if not sha256 is None:
Expand Down

0 comments on commit 093b636

Please sign in to comment.