Skip to content

Commit db3ce65

Browse files
authored
Merge pull request #196 from sethmlarson/sha256
Verify SHA256 digest of downloaded wheels
2 parents 81baf67 + 89ca669 commit db3ce65

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scripts/generate.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Update all the get-pip.py scripts."""
2-
2+
import hashlib
33
import io
44
import itertools
55
import operator
@@ -90,7 +90,7 @@ def get_all_pip_versions() -> Dict[Version, Tuple[str, str]]:
9090
retval = {}
9191
for version in versions:
9292
wheels = [
93-
(file["url"], file["md5_digest"])
93+
(file["url"], file["digests"]["sha256"])
9494
for file in data["releases"][str(version)]
9595
if file["url"].endswith(".whl")
9696
]
@@ -149,12 +149,18 @@ def determine_template(version: Version):
149149
return template
150150

151151

152-
def download_wheel(url: str, expected_md5: str) -> bytes:
152+
def download_wheel(url: str, expected_sha256: str) -> bytes:
153153
session = requests.session()
154154
cached_session = CacheControl(session, cache=FileCache(".web_cache"))
155155

156156
response = cached_session.get(url)
157-
return response.content
157+
response_content = response.content
158+
159+
hashobj = hashlib.sha256()
160+
hashobj.update(response_content)
161+
assert hashobj.hexdigest() == expected_sha256
162+
163+
return response_content
158164

159165

160166
def populated_script_constraints(original_constraints):

0 commit comments

Comments
 (0)