1
+ #! /usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ARTIFACTS_DIR=" packages/compass/dist"
6
+ echo " Verifying artifacts at $ARTIFACTS_DIR "
7
+ ls -l $ARTIFACTS_DIR
8
+
9
+ # Use tmp directory for all gpg operations
10
+ GPG_HOME=$( mktemp -d)
11
+ TMP_FILE=$( mktemp)
12
+ COMPASS_KEY=" https://pgp.mongodb.com/compass.asc"
13
+
14
+ trap_handler () {
15
+ local code=$?
16
+ if [ $code -eq 0 ]; then
17
+ echo " Verification successful"
18
+ else
19
+ echo " Verification failed with exit code $code "
20
+ cat " $TMP_FILE "
21
+ fi
22
+ rm -f " $TMP_FILE "
23
+ rm -rf " $GPG_HOME "
24
+ exit $code
25
+ }
26
+
27
+ trap trap_handler ERR EXIT
28
+
29
+ verify_using_gpg () {
30
+ echo " Verifying $1 using gpg"
31
+ gpg --homedir $GPG_HOME --verify $ARTIFACTS_DIR /$1 .sig $ARTIFACTS_DIR /$1 > " $TMP_FILE " 2>&1
32
+ }
33
+
34
+ verify_using_powershell () {
35
+ echo " Verifying $1 using powershell"
36
+ powershell Get-AuthenticodeSignature -FilePath $ARTIFACTS_DIR /$1 > " $TMP_FILE " 2>&1
37
+ }
38
+
39
+ verify_using_codesign () {
40
+ echo " Verifying $1 using codesign"
41
+ codesign -dv --verbose=4 $ARTIFACTS_DIR /$1 > " $TMP_FILE " 2>&1
42
+ }
43
+
44
+ verify_using_rpm () {
45
+ # RPM packages are signed using gpg and the signature is embedded in the package.
46
+ # Here, we need to import the key in `rpm` and then verify the signature.
47
+ echo " Importing key into rpm"
48
+ rpm --import $COMPASS_KEY > " $TMP_FILE " 2>&1
49
+ # Even if the file is not signed, the command below will exit with 0 and output something like: sha1 md5 OK
50
+ # So we need to check the output of the command to see if the file is signed successfully.
51
+ echo " Verifying $1 using rpm"
52
+ output=$( rpm -K $ARTIFACTS_DIR /$1 )
53
+ # Remove the imported key from rpm
54
+ rpm -e $( rpm -q gpg-pubkey --qf ' %{name}-%{version}-%{release}:%{summary}\n' | grep compass | awk -F: ' {print $1}' )
55
+
56
+ # Check if the output contains the string "pgp md5 OK"
57
+ if [[ $output != * " pgp md5 OK" * ]]; then
58
+ echo " File $1 is not signed"
59
+ exit 1
60
+ fi
61
+ }
62
+
63
+ setup_gpg () {
64
+ echo " Importing Compass public key"
65
+ curl $COMPASS_KEY | gpg --homedir $GPG_HOME --import > " $TMP_FILE " 2>&1
66
+ }
67
+
68
+ if [ " $IS_WINDOWS " = true ]; then
69
+ verify_using_powershell $WINDOWS_EXE_NAME
70
+ verify_using_powershell $WINDOWS_MSI_NAME
71
+ echo " Skipping verification for Windows artifacts using gpg: $WINDOWS_ZIP_NAME , $WINDOWS_NUPKG_NAME "
72
+ elif [ " $IS_UBUNTU " = true ]; then
73
+ setup_gpg
74
+ verify_using_gpg $LINUX_DEB_NAME
75
+ verify_using_gpg $LINUX_TAR_NAME
76
+ elif [ " $IS_RHEL " = true ]; then
77
+ setup_gpg
78
+ verify_using_rpm $RHEL_RPM_NAME
79
+ verify_using_gpg $RHEL_TAR_NAME
80
+ elif [ " $IS_OSX " = true ]; then
81
+ setup_gpg
82
+ verify_using_gpg $OSX_ZIP_NAME
83
+ verify_using_codesign $OSX_DMG_NAME
84
+ else
85
+ echo " Unknown OS, failed to verify file signing"
86
+ exit 1
87
+ fi
0 commit comments