Skip to content

Commit

Permalink
feat(cmd/rofl): Verify integrity of cached artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jan 16, 2025
1 parent f7cae5b commit 1983c80
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/rofl/build/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ func maybeDownloadArtifact(kind, uri string) string {
switch {
case err == nil:
// Already exists in cache.
// TODO: Verify checksum and discard if invalid.
if knownHash != "" {
h := sha256.New()
if _, err = io.Copy(h, f); err != nil {
cobra.CheckErr(fmt.Errorf("failed to verify cached %s artifact: %w", kind, err))
}
artifactHash := fmt.Sprintf("%x", h.Sum(nil))
if artifactHash != knownHash {
cobra.CheckErr(fmt.Errorf("corrupted cached %s artifact file '%s' (expected: %s got: %s)", kind, cacheFn, knownHash, artifactHash))
}
}
f.Close()

fmt.Printf(" (using cached artifact)\n")
Expand Down

0 comments on commit 1983c80

Please sign in to comment.