Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to verify parameter checksums in parameters.json #1251

Merged
merged 2 commits into from
Aug 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions scripts/verify-parameters-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh

# This script verifies that a given `.params` file (and the corresponding
# `.vk` file) is part of `parameters.json` and has the correct digest.
#
# This script runs on POSIX compatible shells. You need to have standard
# utilities (`basename`, `head`, `grep`) as well as have `jq` and `b2sum`
# installed.
#
# The inputs are a `parameter.json` file and a `.params' file.

if [ "${#}" -ne 2 ]; then
echo "Verify that a given .params file (and the corresponding .vk file)"
echo "is part of parameters.json and has the correct digest."
echo ""
echo "Usage: $(basename "${0}") parameters.json parameter-file.params"
exit 1
fi

if ! command -v b2sum >/dev/null 2>&1
then
echo "ERROR: 'b2sum' needs to be installed."
exit 1
fi

if ! command -v jq >/dev/null 2>&1
then
echo "ERROR: 'jq' needs to be installed."
exit 1
fi

PARAMS_JSON=${1}
PARAMS_ID="${2%.*}"

PARAMS_FILE="${PARAMS_ID}.params"
VK_FILE="${PARAMS_ID}.vk"

# Transforms the `parameters.json` into a string that consists of digest and
# filename pairs.
PARAMS_JSON_DATA=$(jq -r 'to_entries[] | "\(.value.digest) \(.key)"' "${PARAMS_JSON}")

VK_HASH_SHORT=$(b2sum "${VK_FILE}"|head --bytes 32)
if echo "${PARAMS_JSON_DATA}"|grep --silent "${VK_HASH_SHORT} ${VK_FILE}"; then
echo "ok Correct digest of VK file was found in ${PARAMS_JSON}."
else
echo "not ok ERROR: Digest of VK file was *not* found/correct in ${PARAMS_JSON}."
exit 1
fi

PARAMS_HASH_SHORT=$(b2sum "${PARAMS_FILE}"|head --bytes 32)
if echo "${PARAMS_JSON_DATA}"|grep --silent "${PARAMS_HASH_SHORT} ${PARAMS_FILE}"; then
echo "ok Correct digest of params file was found in ${PARAMS_JSON}."
else
echo "not ok ERROR: Digest of params file was *not* found/correct in ${PARAMS_JSON}."
exit 1
fi

echo "# Verification successfully completed."