Add support for pinning tools to a checksum (#1098)
Tools in the tools input can now be pinned to a checksum using the tool:version@sha256:<hash> or tool:version@sha512:<hash> syntax. The downloaded tool is verified against the checksum on all platforms, including when it is served from the tools cache, and it is removed along with its cache entry if the verification fails. Checksum verification is supported for tools downloaded as phar archives. Specifying a checksum for tools set up using composer packages or custom package scripts results in an error. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
b9ef68088b
commit
8ca9579834
@@ -122,6 +122,24 @@ get_sha256() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to verify the checksum of a file.
|
||||
# checksum format: sha256:<hash> or sha512:<hash>
|
||||
verify_checksum() {
|
||||
local file_path=$1
|
||||
local checksum=$2
|
||||
local algo="${checksum%%:*}"
|
||||
local expected="${checksum#*:}"
|
||||
local actual=
|
||||
if command -v "${algo}sum" >/dev/null; then
|
||||
actual="$(sudo "${algo}sum" "$file_path" | cut -d' ' -f1)"
|
||||
elif command -v shasum >/dev/null; then
|
||||
actual="$(sudo shasum -a "${algo#sha}" "$file_path" | cut -d' ' -f1)"
|
||||
elif command -v openssl >/dev/null; then
|
||||
actual="$(sudo openssl dgst -"$algo" "$file_path" | awk '{print $NF}')"
|
||||
fi
|
||||
[ -n "$actual" ] && [ "$(echo "$actual" | tr '[:upper:]' '[:lower:]')" = "$(echo "$expected" | tr '[:upper:]' '[:lower:]')" ]
|
||||
}
|
||||
|
||||
# Function to download a file using cURL.
|
||||
# mode: -s pipe to stdout, -v save file and return status code
|
||||
# execute: -e save file as executable
|
||||
|
||||
Reference in New Issue
Block a user