Checksums & Signatures for Artifacts
An artifact repository moves files between machines you don't fully control: CI agents, proxies, CDNs, developer laptops. Two questions have to be answerable for every file:
- Integrity: is this the same file that was uploaded? A checksum (SHA-256, SHA-512) answers it.
- Authenticity: was it uploaded by someone allowed to publish it? A signature answers it.
Checksums catch corruption and accidental replacement. They don't stop an attacker who can replace both the file and its checksum. Signatures do, as long as the private key is safe. The details of signing are in Supply Chain Security; this lesson covers how artifact repositories use both.
Checksums in repository managers
Every major repository manager computes SHA-1, MD5, SHA-256 (and often SHA-512) on upload and stores artifacts by checksum internally (that's how deduplication works). Clients use them:
- Maven uploads
x.jar.sha1/.md5(and.sha256/.sha512on request) next to every file and verifies them on download. - Artifactory accepts a
X-Checksum-Sha256header on upload and can do a checksum deploy: if it already has a blob with that checksum, it links it without transferring the bytes again. - npm, pip (
--require-hashes), Cargo and Go (go.sum) store the expected hash in the lockfile and refuse a mismatch, which protects you even against a compromised repository. See Pinning by Hash. - Conan stores recipe and package revisions (hashes), and vcpkg's binary cache keys binaries by an ABI hash.
Publishing a release with checksums
This session builds a small library, packages it deterministically, writes a SHA256SUMS file the way most projects publish it, and verifies it, including what a corrupted download looks like:
mkdir -p rel/src && cd rel
printf 'int engine_version() { return 140; }\n' > src/engine.cpp
cat > CMakeLists.txt <<'CM'
cmake_minimum_required(VERSION 3.25)
project(Engine VERSION 1.4.0 LANGUAGES CXX)
add_library(engine STATIC src/engine.cpp)
install(TARGETS engine ARCHIVE DESTINATION lib)
CM
package() { # build, install to a staging dir, and create a reproducible tarball
rm -rf build stage && cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release > /dev/null
cmake --build build > /dev/null && cmake --install build --prefix stage > /dev/null
tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C stage -cf - . \
| gzip -n > dist/engine-1.4.0-linux-x86_64.tar.gz
}
mkdir -p dist && package
(cd dist && sha256sum engine-1.4.0-linux-x86_64.tar.gz > SHA256SUMS)
first=$(cut -c1-64 dist/SHA256SUMS)
package
second=$(sha256sum dist/engine-1.4.0-linux-x86_64.tar.gz | cut -c1-64)
echo "rebuilt package has the same checksum: $([ "$first" = "$second" ] && echo yes || echo no)"
echo "--- a consumer verifies the download:"
mkdir -p downloads && cp dist/* downloads/ && cd downloads
sha256sum -c SHA256SUMS
echo "--- a corrupted download (one byte flipped):"
printf '\x00' | dd of=engine-1.4.0-linux-x86_64.tar.gz bs=1 seek=100 conv=notrunc status=none
sha256sum -c SHA256SUMS; echo "exit code $?"rebuilt package has the same checksum: yes
--- a consumer verifies the download:
engine-1.4.0-linux-x86_64.tar.gz: OK
--- a corrupted download (one byte flipped):
engine-1.4.0-linux-x86_64.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
exit code 1
The reproducible packaging (sorted names, fixed mtime from SOURCE_DATE_EPOCH, fixed owner, gzip -n without a timestamp) matters here: because rebuilding gives the same bytes, a checksum identifies what was built, not when. That lets anyone confirm a release by rebuilding it (Reproducible Builds).
Adding a signature
A checksum file downloaded from the same place as the artifact proves nothing if that place is compromised. Signing the checksum file (or the artifact) with a key whose public half consumers already trust closes the gap. With plain OpenSSL and an Ed25519 key:
mkdir -p sign && cd sign
printf 'engine 1.4.0 payload\n' > engine-1.4.0.tar.gz
sha256sum engine-1.4.0.tar.gz > SHA256SUMS
openssl genpkey -algorithm ed25519 -out release.key
openssl pkey -in release.key -pubout -out release.pub
openssl pkeyutl -sign -inkey release.key -rawin -in SHA256SUMS -out SHA256SUMS.sig
echo "--- consumer: verify the signature, then the checksums"
openssl pkeyutl -verify -pubin -inkey release.pub -rawin -in SHA256SUMS -sigfile SHA256SUMS.sig
sha256sum -c SHA256SUMS
echo "--- an attacker replaces the file AND regenerates SHA256SUMS:"
printf 'evil payload\n' > engine-1.4.0.tar.gz
sha256sum engine-1.4.0.tar.gz > SHA256SUMS
sha256sum -c SHA256SUMS
openssl pkeyutl -verify -pubin -inkey release.pub -rawin -in SHA256SUMS -sigfile SHA256SUMS.sig--- consumer: verify the signature, then the checksums
Signature Verified Successfully
engine-1.4.0.tar.gz: OK
--- an attacker replaces the file AND regenerates SHA256SUMS:
engine-1.4.0.tar.gz: OK
Signature Verification Failure
The checksum check alone is fooled; the signature check isn't. In practice, projects sign with GPG (SHA256SUMS.asc), minisign/signify, or Sigstore's cosign (keyless signing with a transparency log), and repository managers store the signatures next to the artifacts (Maven Central requires .asc signatures for every file).
Checklist for an artifact pipeline
- Compute checksums in the build that produced the artifact, not later, and upload them with it.
- Verify checksums on every download in CI (lockfile hashes,
sha256sum -c, Maven's checksum policy set tofail). - Sign releases with a key that lives in a protected CI environment or KMS, never on a laptop; or use keyless signing.
- Publish the public key (or signing identity) somewhere independent of the artifact host.
- Keep checksums and signatures through promotion: promotion copies bytes, so they stay valid.
Test yourself
An attacker can replace both an artifact and its SHA256SUMS file on the server. What still protects consumers?
- Nothing
- A signature over SHA256SUMS verified with a public key the consumer already trusts
- A longer hash
- Downloading twice
Why does reproducible packaging (fixed mtime, sorted names, gzip -n) matter for checksums?
- It makes files smaller
- Rebuilding gives the same bytes, so a checksum identifies what was built, and anyone can confirm it
- sha256sum requires it
- It encrypts the archive
How do lockfile hashes (go.sum, pip --require-hashes) differ from repository-side checksums?
- They are the same
- The expected hash is stored in your repository, so even a compromised artifact server can't swap the file
- They are only for speed
- They replace signatures entirely