Section 17.20

A hash is not an authorization decision

Question

What does a digest match prove about a consumed artifact?

Short answer

A digest match proves only byte identity: the bytes the consumer hashed are, beyond any practical doubt, the bytes from which the reference digest was computed. Two assumptions carry that conclusion: no one can find different bytes with the same digest, and the reference digest came from a source the consumer trusts, by a route an attacker cannot alter. The match does not prove who made the bytes, that this consumer may use them in this way, that they are the current version, or that they are correct or safe.

Terms in the question

Full answer

What the comparison establishes. Write HH for the hash function, xx for the bytes the consumer holds and dd for the reference digest, which its author computed from bytes x0x_0. A match means H(x)=d=H(x0)H(x) = d = H(x_0). If xx differed from x0x_0, the two would be different inputs with the same digest. For SHA-256 nobody knows how to find such a pair. A different input picked at random matches a given digest with probability about 2−2562^{-256}, and the best known general method of finding any two inputs with the same digest needs about 21282^{128} hash computations. The consumer therefore concludes that x=x0x = x_0.

Two properties of the hash function back that conclusion, in two different situations.

SHA-1 (Secure Hash Algorithm 1) lost collision resistance in practice in 2017, when researchers published two different PDF files with the same SHA-1 digest [312].

The match inherits all its meaning from the reference. The conclusion is only that xx equals whatever dd was computed from. If an attacker can choose dd, the attacker computes dd from a harmful file, and the match proves nothing about origin. This happens whenever the artifact and its digest come from the same place: a compromised download server serves a harmful file together with the correct digest of that harmful file. The origin of the bytes is established by protecting the reference, not by the hash. The reference can be protected by a digital signature §5.14 made with a key the consumer already trusts, by a digest built into the consumer in advance, or by a separate channel that the attacker cannot change.

What a match leaves open.

  1. Authority. Authorization §1.7 is the decision that a given party may use given bytes in a given way. A digest names bytes; it grants no permission. The same bytes can be approved as a document to display and forbidden as a program to run. The signed approval must therefore name the role of the bytes as well as their digest, and the consumer must check the role.

  2. Freshness. An old version still matches its own digest. An attacker who sends again a correctly signed old manifest together with its old, vulnerable artifact passes both the signature check and the digest check. Only a comparison with the lowest version the consumer still accepts, called anti-rollback §8.26, stops it. Update systems such as TUF §21.10 (The Update Framework) also give signed metadata an expiry time, so that a consumer detects an attacker who keeps showing it old metadata.

  3. Correctness and safety. A digest matches a malformed or malicious file as readily as a good one, if that file is the one that was hashed. Parsing and validating the content are separate checks.

  4. Production history. The digest says nothing about which source code and which build produced the bytes. Nor does it tell a copy from the original: a rule that requires the exact file a given step produced cannot be checked with a digest, because a byte-identical copy from elsewhere has the same digest.

  5. Identity at the time of use. The match covers the bytes that were hashed, at the moment they were hashed. Suppose the consumer hashes a file that it finds by its path, then opens the path again to use the file. An attacker who replaces the file, or a symbolic link §13.10 along the path, in between makes the consumer use different bytes. This is a time-of-check to time-of-use §9.26 (TOCTOU) error. Reading through one file descriptor §15.21, the handle that the OS gives for one open file, removes the race on the path, but not a writer who changes the file itself. The full repair is to read the bytes once into memory that nothing else can change, hash that copy and use that copy.

Correct use. A consumer that relies on a digest checks, in this order: the protection of the reference, such as a signature made with a trusted key; that the signed statement allows this artifact, in this role, on this consumer; that the version is not below the lowest accepted one; that the digest of the one copy it read matches; and that the content parses and passes validation. It then uses that same copy.

Worked example

The SHA-256 digest of the three ASCII bytes abc is

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

Changing only the last byte, which gives abd, produces

a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9

The two digests share no visible pattern. A one-byte change produces an unrelated digest, which is why equal digests identify the exact bytes.

A device stores the lowest firmware version it accepts: 7. A year ago the vendor signed manifest version 5. It lists image AA with SHA-256 digest D5D_5 and the role “firmware for model X”. Version 5 has a known flaw. An attacker who recorded that update sends it to the device again. The device runs four checks.

  1. The signature on the manifest verifies with the vendor’s public key. Pass: the vendor really signed this manifest.

  2. The SHA-256 digest of the received image equals D5D_5. Pass: the image is exactly the one the vendor signed for.

  3. The role “firmware for model X” matches this device and the intended use. Pass.

  4. The version must not be below the stored lowest version, and 5≥75 \ge 7 is false. Reject.

The checks of origin and integrity §1.9 both passed. Only the freshness check §1.26 stopped the downgrade. Without check 4, the device installs a genuine, authenticated, byte-exact image with a known flaw.

The same vendor also signed an entry for a help page, with digest DhD_h and the role “document”. An installer that accepted any signed entry with a matching digest would accept the bytes of the help page as firmware to run. Check 3 rejects them, because their entry names the role “document”, not “firmware for model X”.

Follow-up questions and limits

Does a match with a checksum §4.32 prove the same thing? No. A non-cryptographic checksum such as a CRC (cyclic redundancy check) detects accidental errors, but an attacker can easily construct different bytes with the same CRC value. A CRC match therefore proves nothing against an attacker.

Are two artifacts with equal digests the same object? They hold the same bytes. They may still be different copies, with different histories, owners and permissions.

Does a signature make the digest unnecessary? No. The signature covers the manifest, and the manifest covers the artifact only through the digest it lists. Each check covers one link of the chain from the signer to the bytes in use.

This answer does not cover how the trusted key is distributed, protected or replaced, or how the content of an artifact is validated.

Fullest treatment: Content integrity versus input authority (§15.34).

Related entries: Integrity (§1.9), Content-addressed identity (§13.2), File descriptor versus pathname (§15.21), Namespace and symlink resolution (§13.9), Cryptographic digest versus path identity (§13.3), Rollback versus anti-rollback (§8.26), Collision resistance (§5.5), Digital signature (§5.14), Time-of-check to time-of-use (TOCTOU) (§9.26). Further reading: [7, 312].