mirror of
https://github.com/step-security/harden-runner.git
synced 2026-06-05 22:47:05 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import * as core from "@actions/core";
|
|
import * as crypto from "crypto";
|
|
import * as fs from "fs";
|
|
|
|
const CHECKSUMS = {
|
|
tls: {
|
|
amd64: "0bd500769646f0a90c0dfe9ac59699d5165bed549a9870c031b861146af337b2", // v1.3.2
|
|
arm64: "c2448ac205fd90f46abba31c13cf34c3b997824881502f736315fb08ac0a5a5c",
|
|
},
|
|
non_tls: {
|
|
amd64: "a9f1842e3d7f3d38c143dbe8ffe1948e6c8173cd04da072d9f9d128bb400844a", // v0.13.7
|
|
},
|
|
};
|
|
|
|
export function verifyChecksum(
|
|
downloadPath: string,
|
|
isTLS: boolean,
|
|
variant: string
|
|
) {
|
|
const fileBuffer: Buffer = fs.readFileSync(downloadPath);
|
|
const checksum: string = crypto
|
|
.createHash("sha256")
|
|
.update(fileBuffer)
|
|
.digest("hex"); // checksum of downloaded file
|
|
|
|
let expectedChecksum: string = "";
|
|
|
|
if (isTLS) {
|
|
expectedChecksum = CHECKSUMS["tls"][variant];
|
|
} else {
|
|
expectedChecksum = CHECKSUMS["non_tls"][variant];
|
|
}
|
|
|
|
if (checksum !== expectedChecksum) {
|
|
core.setFailed(
|
|
`Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`
|
|
);
|
|
}
|
|
|
|
core.debug("Checksum verification passed.");
|
|
}
|