-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathverify-artifacts.sh
More file actions
executable file
·97 lines (83 loc) · 2.9 KB
/
Copy pathverify-artifacts.sh
File metadata and controls
executable file
·97 lines (83 loc) · 2.9 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
#! /usr/bin/env bash
set -e
ARTIFACTS_DIR="packages/compass/dist"
echo "Verifying artifacts at $ARTIFACTS_DIR"
ls -l $ARTIFACTS_DIR
# Use tmp directory for all gpg operations/the rpm database
GPG_HOME=$(mktemp -d)
TMP_FILE=$(mktemp)
COMPASS_KEY="https://pgp.mongodb.com/compass.asc"
trap_handler() {
local code=$?
if [ $code -eq 0 ]; then
echo "Verification successful"
else
echo "Verification failed with exit code $code"
cat "$TMP_FILE"
fi
rm -f "$TMP_FILE"
rm -rf "$GPG_HOME"
exit $code
}
trap trap_handler ERR EXIT
verify_using_gpg() {
echo "Verifying $1 using gpg"
gpg --homedir $GPG_HOME --verify $ARTIFACTS_DIR/$1.sig $ARTIFACTS_DIR/$1 > "$TMP_FILE" 2>&1
}
verify_using_powershell() {
echo "Verifying $1 using powershell"
powershell Get-AuthenticodeSignature -FilePath $ARTIFACTS_DIR/$1 > "$TMP_FILE" 2>&1
# Get-AuthenticodeSignature just outputs text, it doesn't exit with a non-zero
# code if the file is not signed
if grep -q NotSigned "$TMP_FILE"; then
echo "File $1 is not signed"
exit 1
fi
}
verify_using_codesign() {
echo "Verifying $1 using codesign"
codesign -dv --verbose=4 $ARTIFACTS_DIR/$1 > "$TMP_FILE" 2>&1
}
verify_using_rpm() {
# RPM packages are signed using gpg and the signature is embedded in the package.
# Here, we need to import the key in `rpm` and then verify the signature.
echo "Importing key into rpm"
rpm --dbpath "$GPG_HOME" --import $COMPASS_KEY > "$TMP_FILE" 2>&1
# Even if the file is not signed, the command below will exit with 0 and output something like: digests OK
# So we need to check the output of the command to see if the file is signed successfully.
echo "Verifying $1 using rpm"
output=$(rpm --dbpath "$GPG_HOME" -K $ARTIFACTS_DIR/$1)
# Check if the output contains the string "pgp md5 OK"
if [[ $output != *"digests signatures OK"* ]]; then
echo "File $1 is not signed"
exit 1
fi
}
setup_gpg() {
echo "Importing Compass public key"
curl $COMPASS_KEY | gpg --homedir $GPG_HOME --import > "$TMP_FILE" 2>&1
}
if [ "$IS_WINDOWS" = true ]; then
verify_using_powershell $WINDOWS_EXE_NAME
verify_using_powershell $WINDOWS_MSI_NAME
echo "Skipping verification for Windows artifacts using gpg: $WINDOWS_ZIP_NAME, $WINDOWS_NUPKG_NAME"
DEBUG=compass* npm run -w mongodb-compass verify-package-contents
elif [ "$IS_UBUNTU" = true ]; then
setup_gpg
verify_using_gpg $LINUX_DEB_NAME
verify_using_gpg $LINUX_TAR_NAME
DEBUG=compass* npm run -w mongodb-compass verify-package-contents
elif [ "$IS_RHEL" = true ]; then
setup_gpg
verify_using_rpm $RHEL_RPM_NAME
verify_using_gpg $RHEL_TAR_NAME
DEBUG=compass* npm run -w mongodb-compass verify-package-contents
elif [ "$IS_OSX" = true ]; then
setup_gpg
verify_using_gpg $OSX_ZIP_NAME
verify_using_codesign $OSX_DMG_NAME
DEBUG=compass* npm run -w mongodb-compass verify-package-contents
else
echo "Unknown OS, failed to verify file signing"
exit 1
fi