-
Notifications
You must be signed in to change notification settings - Fork 0
Add signed pack trust verification #38
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
Merged
Changes from all commits
Commits
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
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,44 @@ | ||
| from pathlib import Path | ||
| import json | ||
|
|
||
| from detlab.registry import calculate_checksum | ||
|
|
||
|
|
||
|
|
||
| def load_metadata(metadata_path: Path) -> dict: | ||
| return json.loads(metadata_path.read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
|
|
||
| def verify_checksum(archive_path: Path, expected_checksum: str) -> bool: | ||
| calculated = calculate_checksum(archive_path) | ||
| return calculated == expected_checksum | ||
|
|
||
|
|
||
|
|
||
| def verify_pack(archive_path: Path, metadata_path: Path) -> dict: | ||
| metadata = load_metadata(metadata_path) | ||
|
|
||
| expected_checksum = metadata.get("checksum") | ||
| verified = verify_checksum(archive_path, expected_checksum) | ||
|
|
||
| return { | ||
| "name": metadata.get("name"), | ||
| "version": metadata.get("version"), | ||
| "verified": verified, | ||
| "checksum": expected_checksum, | ||
| "archive": archive_path.name, | ||
| } | ||
|
|
||
|
|
||
|
|
||
| def generate_trust_metadata(name: str, version: str, checksum: str) -> dict: | ||
| return { | ||
| "name": name, | ||
| "version": version, | ||
| "checksum": checksum, | ||
| "trust": { | ||
| "verified": True, | ||
| "algorithm": "sha256", | ||
| }, | ||
| } |
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,44 @@ | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from detlab.trust import generate_trust_metadata, verify_checksum, verify_pack | ||
| from detlab.registry import calculate_checksum | ||
|
|
||
|
|
||
| def test_verify_checksum(tmp_path: Path): | ||
| archive = tmp_path / "pack.tar.gz" | ||
| archive.write_text("detlab-pack", encoding="utf-8") | ||
|
|
||
| checksum = calculate_checksum(archive) | ||
|
|
||
| assert verify_checksum(archive, checksum) is True | ||
|
|
||
|
|
||
| def test_verify_pack(tmp_path: Path): | ||
| archive = tmp_path / "windows-core-1.0.0.tar.gz" | ||
| archive.write_text("detlab-pack", encoding="utf-8") | ||
|
|
||
| checksum = calculate_checksum(archive) | ||
|
|
||
| metadata = { | ||
| "name": "windows-core", | ||
| "version": "1.0.0", | ||
| "checksum": checksum, | ||
| "archive": archive.name, | ||
| } | ||
|
|
||
| metadata_path = tmp_path / "windows-core.json" | ||
| metadata_path.write_text(json.dumps(metadata), encoding="utf-8") | ||
|
|
||
| result = verify_pack(archive, metadata_path) | ||
|
|
||
| assert result["verified"] is True | ||
| assert result["name"] == "windows-core" | ||
|
|
||
|
|
||
| def test_generate_trust_metadata(): | ||
| metadata = generate_trust_metadata("windows-core", "1.0.0", "abc123") | ||
|
|
||
| assert metadata["name"] == "windows-core" | ||
| assert metadata["trust"]["algorithm"] == "sha256" | ||
| assert metadata["trust"]["verified"] is True |
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.
This new documented workflow is not reachable from the CLI:
pyproject.tomlpointsdetlabatdetlab.main:app, anddetlab/main.pyonly registers the existing top-level commands with nopackTyper sub-app orverifycommand, while the new trust functions are never imported there. Users following this example will get an unknown-command error instead of pack verification, so the CLI needs to expose this workflow or the docs should not advertise it.Useful? React with 👍 / 👎.