-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathverify_release.sh
More file actions
executable file
·213 lines (181 loc) · 7.53 KB
/
Copy pathverify_release.sh
File metadata and controls
executable file
·213 lines (181 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
# ==============================================================================
# Joltrin Release Verification Gate & Provenance Checker
# ==============================================================================
# Verifies cryptographic checksums, archive integrity, binary headers, and
# software bill of materials (SBOM) before release publishing.
#
# Usage:
# ./scripts/verify_release.sh [path-to-release-dir]
# ==============================================================================
set -euo pipefail
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
RELEASE_DIR="${1:-release}"
echo -e "${BLUE}==> Joltrin Release Verification Gate${NC}"
echo -e "Target Directory: ${RELEASE_DIR}"
if [ ! -d "$RELEASE_DIR" ]; then
echo -e "${RED}[FAIL] Release directory '${RELEASE_DIR}' does not exist.${NC}"
exit 1
fi
TOTAL_CHECKS=0
PASSED_CHECKS=0
FAILED_CHECKS=0
pass() {
local msg="$1"
echo -e " ${GREEN}✔ [PASS]${NC} ${msg}"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
}
fail() {
local msg="$1"
echo -e " ${RED}✖ [FAIL]${NC} ${msg}"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
}
warn() {
local msg="$1"
echo -e " ${YELLOW}⚠ [WARN]${NC} ${msg}"
}
# ------------------------------------------------------------------------------
# 1. Checksum Verification
# ------------------------------------------------------------------------------
echo -e "\n${BLUE}[1/4] Cryptographic Checksum Validation...${NC}"
CHECKSUM_FILE=""
if [ -f "${RELEASE_DIR}/SHA256SUMS" ]; then
CHECKSUM_FILE="${RELEASE_DIR}/SHA256SUMS"
elif [ -f "${RELEASE_DIR}/checksums.txt" ]; then
CHECKSUM_FILE="${RELEASE_DIR}/checksums.txt"
fi
if [ -n "$CHECKSUM_FILE" ]; then
pass "Checksum manifest found: ${CHECKSUM_FILE}"
# Run checksum verification inside release directory
VERIFY_STATUS="OK"
(
cd "$RELEASE_DIR"
MANIFEST_NAME="$(basename "$CHECKSUM_FILE")"
# Filter out manifest lines pointing to checksum files themselves
CLEAN_MANIFEST="$(grep -v "SHA256SUMS" "$MANIFEST_NAME" | grep -v "checksums.txt" || true)"
if [ -z "$CLEAN_MANIFEST" ]; then
echo "EMPTY_MANIFEST"
exit 0
fi
if command -v sha256sum &> /dev/null; then
echo "$CLEAN_MANIFEST" | sha256sum --check --ignore-missing --status - && echo "ALL_OK" || echo "FAILED"
elif command -v shasum &> /dev/null; then
echo "$CLEAN_MANIFEST" | shasum -a 256 -c --status - 2>/dev/null && echo "ALL_OK" || echo "FAILED"
else
echo "NO_TOOL"
fi
) > /tmp/checksum_result.txt 2>&1 || true
CHECK_OUT=$(cat /tmp/checksum_result.txt)
rm -f /tmp/checksum_result.txt
if [[ "$CHECK_OUT" == *"ALL_OK"* ]]; then
pass "Cryptographic SHA-256 signatures validated against all release artifacts"
elif [[ "$CHECK_OUT" == *"NO_TOOL"* ]]; then
warn "Neither 'sha256sum' nor 'shasum' available on host to verify hashes"
elif [[ "$CHECK_OUT" == *"EMPTY_MANIFEST"* ]]; then
warn "Checksum manifest contains no artifact entries"
else
fail "SHA-256 hash mismatch detected! Some release files have been altered or corrupted."
fi
else
warn "No SHA256SUMS or checksums.txt found in release directory"
fi
# ------------------------------------------------------------------------------
# 2. Archive Integrity Checks
# ------------------------------------------------------------------------------
echo -e "\n${BLUE}[2/4] Archive Integrity & Extraction Verification...${NC}"
ARCHIVE_COUNT=0
# Test .tar.gz archives
for archive in "${RELEASE_DIR}"/*.tar.gz; do
[ -e "$archive" ] || continue
ARCHIVE_COUNT=$((ARCHIVE_COUNT + 1))
if tar -tzf "$archive" > /dev/null 2>&1; then
pass "Archive $(basename "$archive") gzip stream & file table intact"
else
fail "Archive $(basename "$archive") is corrupted or truncated!"
fi
done
# Test .zip archives
for zipfile in "${RELEASE_DIR}"/*.zip; do
[ -e "$zipfile" ] || continue
ARCHIVE_COUNT=$((ARCHIVE_COUNT + 1))
if command -v unzip &> /dev/null; then
if unzip -t -q "$zipfile" > /dev/null 2>&1; then
pass "Zip archive $(basename "$zipfile") table of contents verified"
else
fail "Zip archive $(basename "$zipfile") is corrupted!"
fi
elif command -v python3 &> /dev/null; then
if python3 -c "import zipfile, sys; sys.exit(0 if zipfile.ZipFile('$zipfile').testzip() is None else 1)" 2>/dev/null; then
pass "Zip archive $(basename "$zipfile") verified via Python zipfile engine"
else
fail "Zip archive $(basename "$zipfile") failed CRC check!"
fi
else
warn "Skipping zip verification (neither 'unzip' nor 'python3' present)"
fi
done
if [ "$ARCHIVE_COUNT" -eq 0 ]; then
warn "No .tar.gz or .zip archive bundles found to test"
fi
# ------------------------------------------------------------------------------
# 3. Binary & Package Health Checks
# ------------------------------------------------------------------------------
echo -e "\n${BLUE}[3/4] Binary & Package Footprint Inspection...${NC}"
BIN_COUNT=0
for binary in "${RELEASE_DIR}"/*; do
[ -f "$binary" ] || continue
fname="$(basename "$binary")"
# Skip manifests, checksums, and metadata
if [[ "$fname" == "SHA256SUMS" || "$fname" == "checksums.txt" || "$fname" == *.json ]]; then
continue
fi
BIN_COUNT=$((BIN_COUNT + 1))
fsize=$(wc -c < "$binary" | tr -d ' ')
if [ "$fsize" -gt 1024 ]; then
pass "Artifact ${fname} has non-trivial size (${fsize} bytes)"
else
fail "Artifact ${fname} appears empty or truncated (${fsize} bytes)"
fi
done
if [ "$BIN_COUNT" -eq 0 ]; then
warn "No standalone binary artifacts found in ${RELEASE_DIR}"
fi
# ------------------------------------------------------------------------------
# 4. Software Bill of Materials (SBOM) Validation
# ------------------------------------------------------------------------------
echo -e "\n${BLUE}[4/4] Software Bill of Materials (SBOM) Verification...${NC}"
SBOM_FOUND=0
for sbom in "${RELEASE_DIR}"/*sbom*.json "${RELEASE_DIR}"/*.spdx.json; do
[ -e "$sbom" ] || continue
SBOM_FOUND=1
if command -v python3 &> /dev/null; then
if python3 -c "import json, sys; d = json.load(open('$sbom')); sys.exit(0 if 'spdxVersion' in d or 'bomFormat' in d or 'packages' in d else 1)" 2>/dev/null; then
pass "SBOM $(basename "$sbom") conforms to standard SPDX / CycloneDX format"
else
warn "SBOM $(basename "$sbom") is valid JSON but lacks standard top-level SBOM schema tags"
fi
else
pass "SBOM $(basename "$sbom") exists (Python not available for deep schema validation)"
fi
done
if [ "$SBOM_FOUND" -eq 0 ]; then
warn "No SBOM file (*sbom*.json or *.spdx.json) found in ${RELEASE_DIR}"
fi
# ------------------------------------------------------------------------------
# Summary
# ------------------------------------------------------------------------------
echo -e "\n=================================================================="
echo -e "Verification Complete: ${PASSED_CHECKS}/${TOTAL_CHECKS} checks passed."
if [ "$FAILED_CHECKS" -gt 0 ]; then
echo -e "${RED}[GATE REJECTED] ${FAILED_CHECKS} check(s) failed. Do not release artifacts.${NC}"
exit 1
else
echo -e "${GREEN}[GATE APPROVED] Release artifacts verified intact and authenticated.${NC}"
exit 0
fi