Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: verify with gpg if md5 is not present in update-icu #50507

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

islandryu
Copy link
Contributor

Fix: #50498

The problem may be that md5 is not present in the icu, but even in such a case, I used .asc to pass the validation.

If the absence of md5 is clearly an icu issue, this PR will be closed.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Nov 1, 2023
@islandryu islandryu marked this pull request as draft November 1, 2023 15:17
@islandryu islandryu changed the title Verify with gpg if md5 is not present in update-icu tools: verify with gpg if md5 is not present in update-icu Nov 1, 2023
@islandryu islandryu force-pushed the chore/enableVerifyWithSignatureIcu branch from 7eda2d2 to 996127a Compare November 1, 2023 15:35
@@ -41,6 +41,9 @@ NEW_VERSION_TGZ="icu4c-${LOW_DASHED_NEW_VERSION}-src.tgz"
NEW_VERSION_TGZ_URL="https://github.com/unicode-org/icu/releases/download/release-${DASHED_NEW_VERSION}/$NEW_VERSION_TGZ"

NEW_VERSION_MD5="https://github.com/unicode-org/icu/releases/download/release-${DASHED_NEW_VERSION}/icu4c-${LOW_DASHED_NEW_VERSION}-src.md5"
NEW_VERSION_TGZ_ASC_URL="https://github.com/unicode-org/icu/releases/download/release-${DASHED_NEW_VERSION}/icu4c-${LOW_DASHED_NEW_VERSION}-src.tgz.asc"

KEY_URL="https://raw.githubusercontent.com/unicode-org/icu/release-$(echo $NEW_VERSION | sed 's/\./-/')/KEYS"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know myself if the key is correct at this URL.

@islandryu islandryu marked this pull request as ready for review November 1, 2023 15:40
@targos
Copy link
Member

targos commented Nov 1, 2023

We need to decide what to do with https://github.com/nodejs/node/blob/main/tools/icu/current_ver.dep if we can't use md5 anymore (I don't know what's the purpose of that file)

@richardlau
Copy link
Member

We need to decide what to do with https://github.com/nodejs/node/blob/main/tools/icu/current_ver.dep if we can't use md5 anymore (I don't know what's the purpose of that file)

It's used to validate ICU downloads if configure is run with --with-icu-source with a URL.

node/BUILDING.md

Lines 778 to 782 in a037b88

From a tarball URL:
```bash
./configure --with-intl=full-icu --with-icu-source=http://url/to/icu.tgz
```

node/configure.py

Lines 1646 to 1679 in a037b88

def configure_intl(o):
def icu_download(path):
depFile = tools_path / 'icu' / 'current_ver.dep'
icus = json.loads(depFile.read_text(encoding='utf-8'))
# download ICU, if needed
if not os.access(options.download_path, os.W_OK):
error('''Cannot write to desired download path.
Either create it or verify permissions.''')
attemptdownload = nodedownload.candownload(auto_downloads, "icu")
for icu in icus:
url = icu['url']
(expectHash, hashAlgo, allAlgos) = nodedownload.findHash(icu)
if not expectHash:
error(f'''Could not find a hash to verify ICU download.
{depFile} may be incorrect.
For the entry {url},
Expected one of these keys: {' '.join(allAlgos)}''')
local = url.split('/')[-1]
targetfile = Path(options.download_path, local)
if not targetfile.is_file():
if attemptdownload:
nodedownload.retrievefile(url, targetfile)
else:
print(f'Re-using existing {targetfile}')
if targetfile.is_file():
print(f'Checking file integrity with {hashAlgo}:\r')
gotHash = nodedownload.checkHash(targetfile, hashAlgo)
print(f'{hashAlgo}: {gotHash} {targetfile}')
if expectHash == gotHash:
return targetfile
warn(f'Expected: {expectHash} *MISMATCH*')
warn(f'\n ** Corrupted ZIP? Delete {targetfile} to retry download.\n')
return None

@islandryu
Copy link
Contributor Author

It's used to validate ICU downloads if configure is run with --with-icu-source with a URL.

If we're going to verify it based on .asc, we're going to need a dedicated process at the point you indicated.

I think it would be good to save the public key and signature information in current_ver.dep or a separate file and verify it as well as md5.

@islandryu islandryu force-pushed the chore/enableVerifyWithSignatureIcu branch from 996127a to 582e809 Compare November 5, 2023 01:32
Comment on lines +74 to +75
def checkGPG(targetfile, key_url, sig_url):
key_data = download_file(key_url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gpg verification of modification based on url stored in current_ver.dep

@bnoordhuis
Copy link
Member

cc @srl295 in case you missed this pull request

@srl295
Copy link
Member

srl295 commented Nov 6, 2023

cc @srl295 in case you missed this pull request

I missed it, but it's fixed upstream

Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

@islandryu islandryu force-pushed the chore/enableVerifyWithSignatureIcu branch from 582e809 to a05004f Compare November 7, 2023 11:30
@@ -84,6 +82,7 @@ rm -rf "$DEPS_DIR/icu"

perl -i -pe "s|\"url\": .*|\"url\": \"$NEW_VERSION_TGZ_URL\",|" "$TOOLS_DIR/icu/current_ver.dep"

perl -i -pe "$REGEX" "$TOOLS_DIR/icu/current_ver.dep"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflict resolved
and changed writing of current_ver.dep to be done after icu file change

@aduh95
Copy link
Contributor

aduh95 commented May 11, 2024

This needs a rebase.

ICU releases may not include md5 files to verify code
Added a branch to verify from .asc file using gpg in such cases

Fixes: nodejs#50498
@islandryu islandryu force-pushed the chore/enableVerifyWithSignatureIcu branch from a05004f to 368605a Compare May 20, 2024 11:12
@islandryu
Copy link
Contributor Author

The rebase is done.

@aduh95 aduh95 requested a review from srl295 May 20, 2024 15:10
Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If gpg isn't installed AND the md5 is present, then the md5 should be used.

https://unicode-org.atlassian.net/jira/software/c/projects/ICU/issues/ICU-22567 was a bug and not a new direction for ICU.

I would suggest a logic change here:

  • if the md5 signature is available, verify it.
  • if gpg is installed AND the signature is available, verify it.

Warn if neither are available.
Warn if gpg wasn't installed (that is, could not verify provenance.)

configure.py Outdated

warn(f'Expected: {expectHash} *MISMATCH*')
warn(f'\n ** Corrupted ZIP? Delete {targetfile} to retry download.\n')
if "gpg" in icu:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also verify that gpg is present and installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srl295

Changed to check both gpg and md5.

  • Only warn when md5 cannot be obtained.
  • Only warn if gpg signature cannot be obtained or gpg is not installed
  • If neither is available, warn and no update.
  • If either fails verification, warn out and no update

@srl295
Copy link
Member

srl295 commented May 20, 2024

Absence of md5 is an ICU issue and was fixed, However verifying with gpg is not a bad idea.

@islandryu islandryu requested a review from srl295 May 21, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tools: update-icu.sh is broken
7 participants