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: https://github.com/nodejs/node/issues/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: https://github.com/nodejs/node/pull/27370
This commit is contained in:
parent
744cdecbf4
commit
d04b376717
20
configure.py
20
configure.py
@ -1261,7 +1261,8 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
|
|||||||
|
|
||||||
def configure_intl(o):
|
def configure_intl(o):
|
||||||
def icu_download(path):
|
def icu_download(path):
|
||||||
with open('tools/icu/current_ver.dep') as f:
|
depFile = 'tools/icu/current_ver.dep';
|
||||||
|
with open(depFile) as f:
|
||||||
icus = json.load(f)
|
icus = json.load(f)
|
||||||
# download ICU, if needed
|
# download ICU, if needed
|
||||||
if not os.access(options.download_path, os.W_OK):
|
if not os.access(options.download_path, os.W_OK):
|
||||||
@ -1270,7 +1271,12 @@ def configure_intl(o):
|
|||||||
attemptdownload = nodedownload.candownload(auto_downloads, "icu")
|
attemptdownload = nodedownload.candownload(auto_downloads, "icu")
|
||||||
for icu in icus:
|
for icu in icus:
|
||||||
url = icu['url']
|
url = icu['url']
|
||||||
md5 = icu['md5']
|
(expectHash, hashAlgo, allAlgos) = nodedownload.findHash(icu)
|
||||||
|
if not expectHash:
|
||||||
|
error('''Could not find a hash to verify ICU download.
|
||||||
|
%s may be incorrect.
|
||||||
|
For the entry %s,
|
||||||
|
Expected one of these keys: %s''' % (depFile, url, ' '.join(allAlgos)))
|
||||||
local = url.split('/')[-1]
|
local = url.split('/')[-1]
|
||||||
targetfile = os.path.join(options.download_path, local)
|
targetfile = os.path.join(options.download_path, local)
|
||||||
if not os.path.isfile(targetfile):
|
if not os.path.isfile(targetfile):
|
||||||
@ -1279,13 +1285,13 @@ def configure_intl(o):
|
|||||||
else:
|
else:
|
||||||
print('Re-using existing %s' % targetfile)
|
print('Re-using existing %s' % targetfile)
|
||||||
if os.path.isfile(targetfile):
|
if os.path.isfile(targetfile):
|
||||||
print('Checking file integrity with MD5:\r')
|
print('Checking file integrity with %s:\r' % hashAlgo)
|
||||||
gotmd5 = nodedownload.md5sum(targetfile)
|
gotHash = nodedownload.checkHash(targetfile, hashAlgo)
|
||||||
print('MD5: %s %s' % (gotmd5, targetfile))
|
print('%s: %s %s' % (hashAlgo, gotHash, targetfile))
|
||||||
if (md5 == gotmd5):
|
if (expectHash == gotHash):
|
||||||
return targetfile
|
return targetfile
|
||||||
else:
|
else:
|
||||||
warn('Expected: %s *MISMATCH*' % md5)
|
warn('Expected: %s *MISMATCH*' % expectHash)
|
||||||
warn('\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile)
|
warn('\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile)
|
||||||
return None
|
return None
|
||||||
icu_config = {
|
icu_config = {
|
||||||
|
@ -46,9 +46,19 @@ def retrievefile(url, targetfile):
|
|||||||
print(' ** Error occurred while downloading\n <%s>' % url)
|
print(' ** Error occurred while downloading\n <%s>' % url)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def md5sum(targetfile):
|
def findHash(dict):
|
||||||
"""md5sum a file. Return the hex digest."""
|
"""Find an available hash type."""
|
||||||
digest = hashlib.md5()
|
# choose from one of these
|
||||||
|
availAlgos = hashlib.algorithms_guaranteed
|
||||||
|
for hashAlgo in availAlgos:
|
||||||
|
if hashAlgo in dict:
|
||||||
|
return (dict[hashAlgo], hashAlgo, availAlgos)
|
||||||
|
# error
|
||||||
|
return (None, None, availAlgos)
|
||||||
|
|
||||||
|
def checkHash(targetfile, hashAlgo):
|
||||||
|
"""Check a file using hashAlgo. Return the hex digest."""
|
||||||
|
digest = hashlib.new(hashAlgo)
|
||||||
with open(targetfile, 'rb') as f:
|
with open(targetfile, 'rb') as f:
|
||||||
chunk = f.read(1024)
|
chunk = f.read(1024)
|
||||||
while chunk != "":
|
while chunk != "":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user