Skip to content

Commit 28f6daf

Browse files
committed
Add a release validation script
Currently, part of release process involves (causally) confirming that the release artifacts pass gpg/sha1/sha256sum checks. It would be nice if we could automate that a bit. This script allows a user to automatically download draft release artifacts and confirm that their signatures/sha1sum/sha256 sum match those of the included artifact files It also introduces the optional feature to do a per-file level validation of the release using an SBOM file. If we choose to include SBOMS in our releases (see openssl/openssl#29131), this script will for each file in the archive: 1) confirm that a node in the SBOM file exists for it 2) confirm that the sha256sum of the file in the archive matches that of the sum included in the SBOM 3) confirm that the sha256sum of the corresponding file from the git tree matches that of the sum included in the SBOM By confirming these three elements we can have a greater degree of confidence that our automated release pipeline did not alter any of our source files from the initial source that we obtained from git.
1 parent b2829a8 commit 28f6daf

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

release-tools/validate_release.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/sh
2+
3+
####################################################################
4+
# Usage: validate_release.sh <release-tag>
5+
#
6+
# Requirements for usage
7+
#
8+
# 1) You need to have the following tools installed
9+
# a) gpg
10+
# b) jq
11+
# c) ghcli
12+
#
13+
# Additional requirements
14+
# 1) you must be authenticated in ghcli as a user that has access to draft releases
15+
# 2) You must have the openssl public key imported to your gpg key ring
16+
######################################################################
17+
18+
TEMPDIR=$(mktemp -d /tmp/validation.XXXXXX)
19+
20+
trap "rm -rf $TEMPDIR" EXIT
21+
22+
RELEASE=$1
23+
24+
mkdir $TEMPDIR/assets
25+
cd $TEMPDIR/assets
26+
27+
# check tool status
28+
if ! command -v jq >/dev/null 2>&1; then
29+
echo "You must have jq installed to use this tool"
30+
exit 1
31+
fi
32+
33+
if ! command -v gpg >/dev/null 2>&1; then
34+
echo "You must have gpg installed to use this tool"
35+
exit 1
36+
fi
37+
38+
if ! command -v gh >/dev/null 2>&1; then
39+
echo "You must have gh installed to use this tool"
40+
exit 1
41+
fi
42+
43+
# Ensure the openssl public key is in our keyring
44+
gpg --list-keys BA5473A2B0587B07FB27CF2D216094DFD0CB81EF >/dev/null 2>&1
45+
if [ $? -ne 0 ]; then
46+
echo "OpenSSL GPG key not found in keyring, can't validate release"
47+
echo "Please import openssls gpg public key from https://keys.openpgp.org/vks/v1/by-fingerprint/BA5473A2B0587B07FB27CF2D216094DFD0CB81EF"
48+
exit 1
49+
fi
50+
51+
# Ensure we are logged in via gh
52+
gh auth status
53+
if [ $? -ne 0 ]; then
54+
echo "Not logged into github, please authenticate via gh auth login"
55+
exit 1
56+
fi
57+
58+
# Get the release
59+
echo "Downloading release artifacts for $RELEASE"
60+
gh release download -R openssl/openssl $RELEASE
61+
62+
if [ $? -ne 0 ]; then
63+
echo "Release download failed"
64+
exit 1
65+
fi
66+
67+
# Validate the signatures and sha256/sha1 sums
68+
echo "Verifying archive signature"
69+
gpg --verify $RELEASE.tar.gz.asc $RELEASE.tar.gz
70+
71+
if [ $? -ne 0 ]; then
72+
echo "Release Signature validation failed"
73+
exit 1
74+
fi
75+
76+
echo "Verifying archive sha1sum"
77+
sha1sum --check $RELEASE.tar.gz.sha1
78+
79+
if [ $? -ne 0 ]; then
80+
echo "Release SHA1sum validation failed"
81+
exit 1
82+
fi
83+
84+
echo "Verifying archive sha256sum"
85+
sha256sum --check $RELEASE.tar.gz.sha256
86+
87+
if [ $? -ne 0 ]; then
88+
echo "Release SHA1sum validation failed"
89+
exit 1
90+
fi
91+
92+
SKIP_SBOM=no
93+
if [ ! -f $RELEASE-sbom.json.asc ]; then
94+
echo "This release has no SBOM artifact, is that expected[n/y]?"
95+
read ANSWER
96+
case "$ANSWER" in
97+
y*)
98+
SKIP_SBOM=yes
99+
;;
100+
*)
101+
echo "Failing validation as we expect an SBOM artifact"
102+
exit 1
103+
;;
104+
esac
105+
fi
106+
107+
if [ "$SKIP_SBOM" == "yes" ]; then
108+
echo "Skipping SBOM signature validation"
109+
else
110+
echo "Verifying SBOM signature"
111+
gpg --verify $RELEASE-sbom.json.asc $RELEASE-sbom.json
112+
113+
if [ $? -ne 0 ]; then
114+
echo "SBOM signature validation failed"
115+
exit 1
116+
fi
117+
fi
118+
119+
# Extract the archive, and fetch the corresponding git tag
120+
echo "Extracting archive"
121+
tar xf $RELEASE.tar.gz
122+
123+
if [ $? -ne 0 ]; then
124+
echo "Extract of archive failed"
125+
exit 1
126+
fi
127+
128+
echo "Cloning repository"
129+
git clone --branch $RELEASE --single-branch https://github.com/openssl/openssl
130+
131+
if [ $? -ne 0 ]; then
132+
echo "Git clone failed"
133+
exit 1
134+
fi
135+
GITTAGCOMMIT=$(cd openssl; git rev-parse HEAD)
136+
137+
if [ "$SKIP_SBOM" == "no" ]; then
138+
echo "Validating SBOM contents..this will take a moment"
139+
140+
SBOMFILE=./$RELEASE-sbom.json
141+
for archivefile in $(cd $RELEASE; find * -type f); do
142+
if [ ! -s $RELEASE/$archivefile ]; then
143+
echo "$archivefile is zero length, skipping"
144+
continue
145+
fi
146+
GITSHA256=$(sha256sum openssl/$archivefile | awk '{print $1}')
147+
SBOMFILE256=$(sha256sum $RELEASE/$archivefile | awk '{print $1}')
148+
SBOM256=$(jq -r --arg sbfile "$archivefile" '.files[] | select(has("fileName")) | select(.fileName==$sbfile) | .checksums[1].checksumValue' $SBOMFILE)
149+
# every non-zero length file in the archive needs to have an SBOM entry
150+
if [ "$SBOM256" == "" ]; then
151+
echo "$archivefile is missing from SBOM, failing validation!"
152+
exit 1
153+
fi
154+
if [ "$GITSHA256" != "$SBOM256" ]; then
155+
echo "$archivefile sha256sums don't match between git and release tarball!"
156+
exit 1
157+
fi
158+
if [ "$GITSHA256" != "$SBOMFILE256" ]; then
159+
echo "$archivefile sha256sums don't match between sbom and release tarball!"
160+
exit 1
161+
fi
162+
done
163+
fi
164+
165+
echo "====================================================="
166+
echo "Release integrity validated!"
167+
cat $RELEASE.tar.gz.sha1
168+
cat $RELEASE.tar.gz.sha256
169+
echo "GIT TAG COMMIT $GITTAGCOMMIT"
170+
echo "====================================================="
171+
exit 0
172+

0 commit comments

Comments
 (0)