Created
May 7, 2022 23:26
-
-
Save vsajip/3f6b092d8d72e3b68b3ce21ec3e013b7 to your computer and use it in GitHub Desktop.
Test GnuPG verification of a detached signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command_status() { | |
if [ $1 = '0' ]; then | |
echo $'\e[1;32m'Result: Success$'\e[0m' | |
else | |
echo $'\e[1;31m'Result: Failure \(exit code = $1\)$'\e[0m' | |
fi | |
} | |
GPG=gpg2 | |
rm -rf keys | |
mkdir -p keys | |
chmod 0700 keys | |
killall gpg-agent > /dev/null 2>&1 | |
cat << EOF > key_data.txt | |
Key-Type: DSA | |
Key-Length: 1024 | |
Subkey-Type: ELG-E | |
Subkey-Length: 2048 | |
Name-Comment: A test user | |
Name-Real: Andrew Able | |
Name-Email: [email protected] | |
Passphrase: aable | |
Expire-Date: 0 | |
%commit | |
EOF | |
COMMON_ARGS="--status-fd 2 --no-tty --no-verbose --fixed-list-mode --batch --with-colons --homedir keys" | |
echo $'\e[1;33m'GPG version ...$'\e[0m' | |
${GPG} ${COMMON_ARGS} --version | head -1 | |
echo $'\e[1;33m'Generating a key ...$'\e[0m' | |
${GPG} ${COMMON_ARGS} --gen-key < key_data.txt 2>&1 | tee key_info.txt | |
command_status $? | |
KEYID=$(tail -1 key_info.txt | awk '{ print $(NF)}') | |
# echo $'\e[1;33m'Key ID: ${KEYID}$'\e[0m' | |
rm key_data.txt key_info.txt | |
echo $'\e[1;33m'Creating random data to sign ...$'\e[0m' | |
dd if=/dev/urandom of=data-to-sign bs=1 count=1024 > /dev/null 2>&1 | |
echo $'\e[1;33m'Signing data, asking for a detached signature ...$'\e[0m' | |
echo aable | ${GPG} --pinentry-mode loopback ${COMMON_ARGS} --passphrase-fd 0 -sa --detach-sign --default-key ${KEYID} | tee sig.asc | |
command_status $? | |
echo $'\e[1;33m'Trying to verify data ...$'\e[0m' | |
${GPG} ${COMMON_ARGS} --verify sig.asc data-to-sign | |
command_status $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment