Repository navigation
Verify registry checksums, including MD5 and SHA-1 - #3
Merged
Merged
Conversation
Registries publish checksums that are not SRI: algorithm-prefixed hex such as Cargo's sha256-<hex>, npm's and Packagist's SHA-1 shasum, Conda's MD5. Callers could not parse or verify them, so a valid checksum was treated as unusable. - Add verification-only MD5 and SHA1 algorithms, calculated by NewReader and accepted by ParseHex with their digest lengths checked - Add ParseChecksum for a single algorithm-prefixed hexadecimal checksum, Digest.Checksum for its canonical form, and Result.VerifyDigest to check a stream against one exact digest - Keep MD5 and SHA-1 out of SRI: ParseSRI rejects them, Digest.SRI is empty for them, FormatSRI leaves them out, and Result.Verify refuses them - Rank algorithms by an explicit strength order rather than the order of the constants, which the new algorithms no longer follow - Document MD5 and SHA-1 as compatibility checks only Closes git-pkgs#1
This was referenced Oct 14, 2026
simonchrz
added a commit
to simonchrz/proxy
that referenced
this pull request
Oct 14, 2026
v0.2.0 adds verification-only SHA-1 and MD5, algorithm-prefixed checksum parsing and exact-digest verification (git-pkgs/integrity#3).
simonchrz
added a commit
to simonchrz/proxy
that referenced
this pull request
Oct 14, 2026
v0.2.0 adds verification-only SHA-1 and MD5, algorithm-prefixed checksum parsing and exact-digest verification (git-pkgs/integrity#3).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1.
Registries publish checksums that aren't SRI. Some are algorithm-prefixed hex (Cargo, Pub, RubyGems and others give
sha256-<hex>). Some use SHA-1: npm'sdist.shasumfallback and Packagist'sdist.shasum. Conda falls back to MD5, and Vagrant gives the algorithm and hex separately. This module couldn't parse or verify any of those, so the proxy treated a valid checksum as unusable.Changes
Algorithms (
algorithm.go)MD5andSHA1after the existing constants, so the existing values don't change.NewReadercalculates both.ParseHexaccepts all five algorithms and checks the 16-byte and 20-byte lengths.byStrength): MD5 < SHA-1 < SHA-256 < SHA-384 < SHA-512. Before,strongestAlgorithmcompared the constants' numeric values, which no longer follow strength.Registry checksums (
digest.go,reader.go)ParseChecksumparses one algorithm-prefixed hexadecimal checksum,<alg>-<hex>or<alg>:<hex>. It is case-insensitive and ignores surrounding whitespace.Digest.Checksumreturns the canonical<alg>-<hex>form.Result.VerifyDigestchecks a completed stream against one exact digest in any algorithm. It needs a complete stream (ErrIncompleteotherwise) and needs the reader to have calculated that algorithm.SRI stays strict
ParseSRIrejects MD5 and SHA-1, even as valid base64 of the right length.Digest.SRIreturns""for them, andFormatSRIleaves them out.Result.Verifykeeps the SRI strongest-algorithm rule. It refuses an SRI list that contains a weak digest, even one built by hand.Docs
Julia's
git-tree-sha1is left out, as the issue says: it identifies a tree, not the downloaded tarball.Tests
checksum_test.go:ParseChecksum: all five algorithms, both separators, upper case and whitespace, plus malformed values (no prefix, wrong length, base64, unknown algorithm, two entries).ParseSRI(alone and in a list), have no SRI encoding, and are refused byResult.Verify.VerifyDigest: the reader calculates MD5 and SHA-1.VerifyDigestpasses on a match, fails on a mismatch, needs a complete stream, and needs the calculated algorithm (or the zeroDigest).The existing multi-hash SRI tests pass unchanged. A new
FuzzParseChecksumround-trips throughChecksum.I checked that the tests catch regressions by breaking each rule in turn: weak names in
ParseSRI, SRI encoding for weak digests,Verifyaccepting them,VerifyDigestalways matching or skipping the completeness check, and ranking by constant order. Every one fails a test.go test -race ./..., 20 s ofFuzzParseChecksumand 10 s ofFuzzSRIRoundTrip,make lint's golangci-lint linters (v2.13.1) and govulncheck all pass.This unblocks git-pkgs/proxy#473's follow-up: npm's
dist.shasumfallback and Packagist'sdist.shasumcheck.