Skip to content

Commit d3ead17

Browse files
committed
feat(cmd/rofl): Verify integrity of cached artifacts
1 parent a384561 commit d3ead17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/rofl/build/artifacts.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,16 @@ func maybeDownloadArtifact(kind, uri string) string {
6363
switch {
6464
case err == nil:
6565
// Already exists in cache.
66-
// TODO: Verify checksum and discard if invalid.
66+
if knownHash != "" {
67+
h := sha256.New()
68+
if _, err = io.Copy(h, f); err != nil {
69+
cobra.CheckErr(fmt.Errorf("failed to verify cached %s artifact: %w", kind, err))
70+
}
71+
artifactHash := fmt.Sprintf("%x", h.Sum(nil))
72+
if artifactHash != knownHash {
73+
cobra.CheckErr(fmt.Errorf("corrupted cached %s artifact file '%s' (expected: %s got: %s)", kind, cacheFn, knownHash, artifactHash))
74+
}
75+
}
6776
f.Close()
6877

6978
fmt.Printf(" (using cached artifact)\n")

0 commit comments

Comments
 (0)