Repository navigation
python-virtualenv: remove affected roots from embedded pip wheels #19710
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
Merged
jslobodzian
merged 4 commits into
fasttrack/3.0
from
users/joslobo/emudhra-python-virtualenv-20261023
Oct 25, 2026
+165
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8cbc5ac
[python-virtualenv] Distrust affected eMudhra and AAA certificate roots
aa96987
python-virtualenv: repair pinned tox 4 package checks
042d455
python-virtualenv: run package checks without test patches
c267d3f
python-virtualenv: inline test constraints in package checks
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
SPECS/python-virtualenv/remove-compromised-wheel-ca-roots.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| Subject: [PATCH] Distrust incident-related eMudhra and AAA trust anchors | ||
|
|
||
| Remove only the affected trust anchors, including the AAA cross-signing | ||
| path. Preserve the unaffected emSign G1, C1 and C3 anchors. | ||
| Reference: https://emudhra.we-have-a-problem.com/ | ||
| Upstream-status: Azure Linux trust-store backport | ||
|
|
||
| --- /dev/null | ||
| +++ b/Tools/remove-untrusted-wheel-roots.py | ||
| @@ -0,0 +1,109 @@ | ||
| +"""Remove incident-related trust anchors from bundled wheels and renew RECORD.""" | ||
| + | ||
| +import argparse | ||
| +import base64 | ||
| +import csv | ||
| +import hashlib | ||
| +import io | ||
| +from pathlib import Path | ||
| +import re | ||
| +import ssl | ||
| +import tempfile | ||
| +import zipfile | ||
| + | ||
| + | ||
| +UNTRUSTED_SHA256 = { | ||
| + "d7a7a0fb5d7e2731d771e9484ebcdef71d5f0c3e0a2948782bc83ee0ea699ef4", | ||
| + "86a1ecba089c4a8d3bbe2734c612ba341d813e043cf9e8a862cd5c57a36bbe6b", | ||
| +} | ||
| +CERTIFICATE = re.compile( | ||
| + rb"-----BEGIN CERTIFICATE-----\s+[A-Za-z0-9+/=\s]+?-----END CERTIFICATE-----" | ||
| +) | ||
| + | ||
| + | ||
| +def prepare_wheel(path): | ||
| + with zipfile.ZipFile(path) as archive: | ||
| + infos = archive.infolist() | ||
| + if len({info.filename for info in infos}) != len(infos): | ||
| + raise ValueError(f"{path}: duplicate wheel members") | ||
| + records = [ | ||
| + info.filename | ||
| + for info in infos | ||
| + if info.filename.endswith(".dist-info/RECORD") | ||
| + ] | ||
| + if len(records) != 1: | ||
| + raise ValueError(f"{path}: expected exactly one wheel RECORD") | ||
| + record = records[0] | ||
| + if any( | ||
| + name in archive.namelist() for name in (record + ".jws", record + ".p7s") | ||
| + ): | ||
| + raise ValueError(f"{path}: cannot rewrite a signed wheel") | ||
| + payload = {info.filename: archive.read(info) for info in infos} | ||
| + | ||
| + removed = 0 | ||
| + | ||
| + def retain_certificate(match): | ||
| + nonlocal removed | ||
| + der = ssl.PEM_cert_to_DER_cert(match.group().decode("ascii")) | ||
| + if hashlib.sha256(der).hexdigest() in UNTRUSTED_SHA256: | ||
| + removed += 1 | ||
| + return b"" | ||
| + return match.group() | ||
| + | ||
| + for name, data in payload.items(): | ||
| + if name.endswith((".pem", ".crt")): | ||
| + payload[name] = CERTIFICATE.sub(retain_certificate, data) | ||
| + | ||
| + if not removed: | ||
| + return None, 0 | ||
| + | ||
| + output = io.StringIO(newline="") | ||
| + writer = csv.writer(output, lineterminator="\n") | ||
| + for info in infos: | ||
| + name = info.filename | ||
| + if info.is_dir(): | ||
| + continue | ||
| + if name == record: | ||
| + writer.writerow((name, "", "")) | ||
| + else: | ||
| + data = payload[name] | ||
| + digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()) | ||
| + writer.writerow((name, "sha256=" + digest.rstrip(b"=").decode(), len(data))) | ||
| + payload[record] = output.getvalue().encode("utf-8") | ||
| + return (path, infos, payload), removed | ||
| + | ||
| + | ||
| +def main(): | ||
| + parser = argparse.ArgumentParser(description=__doc__) | ||
| + parser.add_argument("--expected-removals", type=int, required=True) | ||
| + parser.add_argument("wheels", nargs="+", type=Path) | ||
| + args = parser.parse_args() | ||
| + plans = [] | ||
| + total = 0 | ||
| + for path in args.wheels: | ||
| + plan, removed = prepare_wheel(path) | ||
| + if plan is not None: | ||
| + plans.append(plan) | ||
| + total += removed | ||
| + print(f"{path}: removing {removed} affected trust anchors") | ||
| + if total != args.expected_removals: | ||
| + raise ValueError( | ||
| + f"Expected {args.expected_removals} trust anchors, found {total}; " | ||
| + "review the bundled wheels before changing this expectation" | ||
| + ) | ||
| + for path, infos, payload in plans: | ||
| + with tempfile.NamedTemporaryFile( | ||
| + dir=path.parent, prefix=path.name + ".", suffix=".tmp", delete=False | ||
| + ) as temporary: | ||
| + temporary_path = Path(temporary.name) | ||
| + try: | ||
| + with zipfile.ZipFile(temporary_path, "w") as archive: | ||
| + for info in infos: | ||
| + archive.writestr(info, payload[info.filename]) | ||
| + temporary_path.replace(path) | ||
| + finally: | ||
| + temporary_path.unlink(missing_ok=True) | ||
| + | ||
| + | ||
| +if __name__ == "__main__": | ||
| + main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check section is not green