Skip to content

Commit e7026f1

Browse files
srl295targos
authored andcommitted
build: allow icu download to use other hashes besides md5
- ICU uses sha512 instead of md5 in some recent releases - Use hashlib.algorithms_guaranteed to choose the following algorithms: sha1 sha224 sha384 sha256 sha512 md5 - No preference as to the priority of the algorithms - This commit does not change the hash used for ICU. Fixes: #27369 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-by: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-by: Richard Lau <riclau@uk.ibm.com> PR-URL: #27370
1 parent 071300b commit e7026f1

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

configure.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,8 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
12611261

12621262
def configure_intl(o):
12631263
def icu_download(path):
1264-
with open('tools/icu/current_ver.dep') as f:
1264+
depFile = 'tools/icu/current_ver.dep';
1265+
with open(depFile) as f:
12651266
icus = json.load(f)
12661267
# download ICU, if needed
12671268
if not os.access(options.download_path, os.W_OK):
@@ -1270,7 +1271,12 @@ def icu_download(path):
12701271
attemptdownload = nodedownload.candownload(auto_downloads, "icu")
12711272
for icu in icus:
12721273
url = icu['url']
1273-
md5 = icu['md5']
1274+
(expectHash, hashAlgo, allAlgos) = nodedownload.findHash(icu)
1275+
if not expectHash:
1276+
error('''Could not find a hash to verify ICU download.
1277+
%s may be incorrect.
1278+
For the entry %s,
1279+
Expected one of these keys: %s''' % (depFile, url, ' '.join(allAlgos)))
12741280
local = url.split('/')[-1]
12751281
targetfile = os.path.join(options.download_path, local)
12761282
if not os.path.isfile(targetfile):
@@ -1279,13 +1285,13 @@ def icu_download(path):
12791285
else:
12801286
print('Re-using existing %s' % targetfile)
12811287
if os.path.isfile(targetfile):
1282-
print('Checking file integrity with MD5:\r')
1283-
gotmd5 = nodedownload.md5sum(targetfile)
1284-
print('MD5: %s %s' % (gotmd5, targetfile))
1285-
if (md5 == gotmd5):
1288+
print('Checking file integrity with %s:\r' % hashAlgo)
1289+
gotHash = nodedownload.checkHash(targetfile, hashAlgo)
1290+
print('%s: %s %s' % (hashAlgo, gotHash, targetfile))
1291+
if (expectHash == gotHash):
12861292
return targetfile
12871293
else:
1288-
warn('Expected: %s *MISMATCH*' % md5)
1294+
warn('Expected: %s *MISMATCH*' % expectHash)
12891295
warn('\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile)
12901296
return None
12911297
icu_config = {

tools/configure.d/nodedownload.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ def retrievefile(url, targetfile):
4646
print(' ** Error occurred while downloading\n <%s>' % url)
4747
raise
4848

49-
def md5sum(targetfile):
50-
"""md5sum a file. Return the hex digest."""
51-
digest = hashlib.md5()
49+
def findHash(dict):
50+
"""Find an available hash type."""
51+
# choose from one of these
52+
availAlgos = hashlib.algorithms_guaranteed
53+
for hashAlgo in availAlgos:
54+
if hashAlgo in dict:
55+
return (dict[hashAlgo], hashAlgo, availAlgos)
56+
# error
57+
return (None, None, availAlgos)
58+
59+
def checkHash(targetfile, hashAlgo):
60+
"""Check a file using hashAlgo. Return the hex digest."""
61+
digest = hashlib.new(hashAlgo)
5262
with open(targetfile, 'rb') as f:
5363
chunk = f.read(1024)
5464
while chunk != "":

0 commit comments

Comments
 (0)