|
| 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 | + |
| 136 | +if [ "$SKIP_SBOM" == "no" ]; then |
| 137 | + echo "Validating SBOM contents..this will take a moment" |
| 138 | + |
| 139 | + SBOMFILE=~/$RELEASE-sbom.json |
| 140 | + for archivefile in $(cd $RELEASE; find * -type f); do |
| 141 | + if [ ! -s $RELEASE/$archivefile ]; then |
| 142 | + echo "$archivefile is zero length, skipping" |
| 143 | + continue |
| 144 | + fi |
| 145 | + GITSHA256=$(sha256sum openssl/$archivefile | awk '{print $1}') |
| 146 | + SBOMFILE256=$(sha256sum $RELEASE/$archivefile | awk '{print $1}') |
| 147 | + SBOM256=$(jq -r --arg sbfile "$archivefile" '.files[] | select(has("fileName")) | select(.fileName==$sbfile) | .checksums[1].checksumValue' $SBOMFILE) |
| 148 | + # every non-zero length file in the archive needs to have an SBOM entry |
| 149 | + if [ "$SBOM256" == "" ]; then |
| 150 | + echo "$archivefile is missing from SBOM, failing validation!" |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | + if [ "$GITSHA256" != "$SBOM256" ]; then |
| 154 | + echo "$archivefile sha256sums don't match between git and release tarball!" |
| 155 | + exit 1 |
| 156 | + fi |
| 157 | + if [ "$GITSHA256" != "$SBOMFILE256" ]; then |
| 158 | + echo "$archivefile sha256sums don't match between sbom and release tarball!" |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | + done |
| 162 | +fi |
| 163 | + |
| 164 | +echo "=====================================================" |
| 165 | +echo "Release integrity validated!" |
| 166 | +echo "=====================================================" |
| 167 | +exit 0 |
| 168 | + |
0 commit comments