File indexing completed on 2024-11-10 04:05:17
0001 #!/usr/bin/env bash 0002 # 0003 # SPDX-License-Identifier: GPL-3.0-or-later 0004 # 0005 0006 set -x 0007 set -e 0008 0009 APPIMAGE_PATH="${1}" 0010 0011 if [ -z $APPIMAGE_PATH ]; then 0012 echo "path to appimage (arg1) is not set" 0013 exit 1 0014 fi 0015 0016 tempdir="$(mktemp validate_appimage_signature.XXXXXX -d -p /tmp)" 0017 0018 destination=$(basename $APPIMAGE_PATH) 0019 0020 ascfile="${tempdir}/${destination}.digest.asc" 0021 digestfile="${tempdir}/${destination}.digest" 0022 sigkeyfile="${tempdir}/sig_pubkey" 0023 tempkeyringpath="${tempdir}/keyring" 0024 tmpappimage="$tempdir/tmp.AppImage" 0025 0026 # get offsets and lengths of .sha256_sig and .sig_key sections of the AppImage 0027 SIG_OFFSET=$(objdump -h "${APPIMAGE_PATH}" | grep .sha256_sig | awk '{print $6}') 0028 SIG_LENGTH=$(objdump -h "${APPIMAGE_PATH}" | grep .sha256_sig | awk '{print $3}') 0029 0030 KEY_OFFSET=$(objdump -h "${APPIMAGE_PATH}" | grep .sig_key | awk '{print $6}') 0031 KEY_LENGTH=$(objdump -h "${APPIMAGE_PATH}" | grep .sig_key | awk '{print $3}') 0032 0033 cp $APPIMAGE_PATH $tmpappimage 0034 0035 # restore the original, for generating checksum 0036 dd if=/dev/zero bs=1 seek=$(($(echo 0x$SIG_OFFSET))) count=$(($(echo 0x$SIG_LENGTH))) of="${tmpappimage}" conv=notrunc 0037 dd if=/dev/zero bs=1 seek=$(($(echo 0x$KEY_OFFSET))) count=$(($(echo 0x$KEY_LENGTH))) of="${tmpappimage}" conv=notrunc 0038 0039 sha256sum $tmpappimage | cut -d " " -f 1 | tr -d '\n' > $digestfile 0040 0041 # extract signature 0042 dd if="${APPIMAGE_PATH}" bs=1 skip=$(($(echo 0x$SIG_OFFSET))) count=$(($(echo 0x$SIG_LENGTH))) of="${ascfile}" 0043 # extract the public part of the signing key 0044 dd if=${APPIMAGE_PATH} bs=1 skip=$(($(echo 0x$KEY_OFFSET))) count=$(($(echo 0x$KEY_LENGTH))) of="${sigkeyfile}" 0045 0046 cat $sigkeyfile | gpg2 --no-default-keyring --keyring $tempkeyringpath --import 0047 gpg2 --no-default-keyring --keyring $tempkeyringpath --verify $ascfile $digestfile 0048 0049 # cleanup 0050 rm -rf $tempdir