Checksums and safe extraction
Quick answer
A cryptographic digest such as SHA-256 provides a compact fingerprint of file bytes. Compare it with a trusted expected digest before using a downloaded artifact. A matching digest helps verify integrity but does not independently prove who published the file or that its contents are safe.
Prepare the practice environment
Run python3 lab-fixtures/archives/setup.py as an ordinary user from the extracted package root in a disposable Linux environment. Enter the printed directory, check pwd, then run export LC_ALL=C; umask 077; set -o pipefail. Use a fresh fixture for each example and stop if a command fails unexpectedly. All archive and output paths must be new. Outputs below are not commands.
How it works
sha256sum FILE prints a digest and filename; sha256sum -c MANIFEST recomputes and compares the listed files, reporting status and a nonzero exit on failure. SHA-512 is another SHA-2 algorithm with a longer digest. In production obtain expected hashes or signatures from an authenticated trusted source; downloading both from an attacker-controlled location proves little. Only check manifests you trust, as filenames can reference other locations. For archives, inspect the member list and sizes where available; reject unexpected absolute paths, parent traversal, links, special files and excessive expanded size. Listings alone cannot reliably validate every archive feature or resource requirement. Do not unpack hostile archives in this lab. Use an appropriately isolated, resource-limited environment with no valuable data or privileges when handling unknown material, and do not execute extracted programs. A successful checksum or archive test is not a sandbox.
Think of the manifest as an expected fingerprint for a particular version of the file. If you change the file and then regenerate the manifest, a later check may pass even though the original has been lost. Keep the trusted manifest separate from the candidate and investigate a mismatch before accepting new bytes. Even matching bytes can belong to an unsafe archive; neither the digest nor a successful format test authorizes extraction of unknown content.
Try the examples
cp notes.txt copy.txtsha256sum copy.txt > SHA256SUMSsha256sum -c SHA256SUMSThe manifest is generated locally for this controlled demonstration. It is not independent publisher authentication.
Expected stdout:
copy.txt: OKcp notes.txt copy.txtsha256sum copy.txt > SHA256SUMSprintf "changed\n" >> copy.txtif sha256sum -c SHA256SUMS > check.log 2>&1; then exit 1else printf "changed copy rejected\n"fiOnly the copy changes. The failure branch is expected; inspect check.log for diagnostics. Never overwrite the expected digest to silence a mismatch.
Expected stdout:
changed copy rejectedtar -czf notes.tar.gz notes.txt report.txtsha512sum notes.tar.gz > SHA512SUMSsha512sum -c SHA512SUMS && tar -tzf notes.tar.gzThe checksum must succeed before listing. This example stops at inspection; extraction is a separate decision.
Expected stdout:
notes.tar.gz: OKnotes.txtreport.txtCommon mistakes
Do not mistake matching hashes for verified authorship. If a trusted digest does not match, stop and investigate rather than extracting anyway. Never run unknown extracted files or weaken path-safety checks.
Practice
Create a trusted local manifest for report.txt copied to report-copy.txt. Verify it, change only the copy, verify again, and record the failure status. Explain why a matching hash cannot authenticate an unknown publisher.
Related references
Study: sha256sum, sha512sum. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Checksums and safe extraction — Knowledge Check
Apply the lesson concepts to the controlled archive fixture.
What is necessary for a checksum to be meaningful against tampering?
What should happen after a trusted digest mismatch?
What does a checksum match not establish?
Why is listing an archive insufficient for safety?