| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Ecluse.Core.Worker.Integrity
Description
The integrity gate is the security crux of the worker.
A mirrored artifact is later served from the private upstream __without re-running the rules__, so a corrupt or tampered artifact must never enter it. Verification is therefore the gate: a hash mismatch fails the job with no publish and is logged loudly. The digests verified are the re-admitted artifact's, the exact set the worker's ingest re-evaluation floor-checked against current metadata, so the digest the bytes are gated on is always one current policy admitted; the queue payload contributes no digest to the gate.
Synopsis
Documentation
data IntegrityResult Source #
The result of verifying fetched bytes against the admitted integrity digests.
A sum type, not a Bool, so the mismatch carries the detail an operator needs to
explain why a publish was refused.
Constructors
| IntegrityVerified | The bytes matched the most authoritative admitted digest. |
| IntegrityMismatch Text | The bytes failed the integrity gate. Carries a human-readable detail (the digest they were checked against, or that the strongest one was uncomputable). |
Instances
| Show IntegrityResult Source # | |
Defined in Ecluse.Core.Worker.Integrity Methods showsPrec :: Int -> IntegrityResult -> ShowS # show :: IntegrityResult -> String # showList :: [IntegrityResult] -> ShowS # | |
| Eq IntegrityResult Source # | |
Defined in Ecluse.Core.Worker.Integrity Methods (==) :: IntegrityResult -> IntegrityResult -> Bool # (/=) :: IntegrityResult -> IntegrityResult -> Bool # | |
verifyIntegrity :: NonEmpty Hash -> ByteString -> IntegrityResult Source #
Verify fetched artifact bytes against the most authoritative integrity digest the version carries -- never against a weaker one while a stronger is present.
A real npm version carries both a modern SRI sha512 digest and the legacy SHA-1
shasum. Passing on any match would let an artifact that matches the weak SHA-1
but fails the strong sha512 through -- and SHA-1 collision resistance is broken, so
that is exploitable. So the gate verifies the bytes against the one digest the
shared selection names (authoritativeDigest -- the
same authority order the serve-side admission floor ranks by): the bytes pass iff
that digest matches. A weaker digest can neither override nor rescue a failed strong
one, and because the selection is shared, this gate and the admission floor can never
rank the same digest set two different ways.
The bytes are recomputed in that digest's own algorithm through the shared
computeDigest, the one definition of which algorithms Écluse can
verify. That computable set covers every algorithm the public integrity floor admits, so an
admitted artifact is always verifiable here. Each SRI Hash carries exactly one
<alg>-<base64> component (mkSriHashes splits a joined wire
string at construction), so the digest body compared is always a single component's,
never a joined string. If the selected digest is in an algorithm the worker cannot
recompute, the gate fails closed: a tampered artifact must never be admitted on
the strength of a hash an attacker could forge.
This is the tamper gate before a publish: a mismatch fails the job and never publishes a corrupt or substituted artifact into the private upstream.
>>>import Ecluse.Core.Package (mkHash, HashAlg (SHA1))>>>fmap (\h -> verifyIntegrity (h :| []) "Hello World") (mkHash SHA1 "0a4d55a8d778e5022fab701977c5d840bbc486d0")Right IntegrityVerified
>>>fmap (\h -> verifyIntegrity (h :| []) "Hello World") (mkHash SHA1 "da39a3ee5e6b4b0d3255bfef95601890afd80709")Right (IntegrityMismatch "the SHA1 digest did not match the fetched bytes")