summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/.scripts/gpg-test.sh
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-03-25 23:38:13 -0500
committerToby Vincent <tobyv13@gmail.com>2022-03-25 23:38:13 -0500
commite6051a38a672182c7f7dfa083ca1e72b97803c94 (patch)
tree734e251bab033169399432fe1c93fc879dfab578 /scripts/.scripts/gpg-test.sh
parentbb375ba979dfc0c575443f8309ee52d0fd446a26 (diff)
feat: migrated to gnu stow
Diffstat (limited to 'scripts/.scripts/gpg-test.sh')
-rw-r--r--scripts/.scripts/gpg-test.sh102
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts/.scripts/gpg-test.sh b/scripts/.scripts/gpg-test.sh
new file mode 100644
index 0000000..f23b83d
--- /dev/null
+++ b/scripts/.scripts/gpg-test.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+
+TEMP=$(getopt -o hvdsea: --long help,verbose,debug,signature,encryption,authentication \
+ -n 'javawrap' -- "$@")
+
+if [ $? != 0 ]; then
+ echo "Terminating..." >&2
+ exit 1
+fi
+
+eval set -- "$TEMP"
+
+usage() {
+ cat <<EOF
+usage: $0 [OPTIONS]
+
+ -h,--help Show this message
+ -v,--verbose Show test output
+ -d,--debug NOT IMPLEMENTED
+ -s,--signature Test signature key
+ -e,--encryption Test encryption key
+ -a,--authentication Test authentication key
+EOF
+}
+
+VERBOSE=false
+DEBUG=false
+SIGNATURE=false
+ENCRYPTION=false
+AUTHENTICATION=false
+ALL=true
+
+while true; do
+ case "$1" in
+ -h | --help)
+ usage
+ exit 0
+ ;;
+ -v | --verbose)
+ VERBOSE=true
+ shift
+ ;;
+ -d | --debug)
+ DEBUG=true
+ shift
+ ;;
+ -s | --signature)
+ ALL=false
+ SIGNATURE=true
+ shift
+ ;;
+ -e | --encryption)
+ ALL=false
+ ENCRYPTION=true
+ shift
+ ;;
+ -a | --authentication)
+ ALL=false
+ AUTHENTICATION=true
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *) break ;;
+ esac
+done
+
+function print_result() {
+ if [ $? -ne 0 ]; then
+ echo "Failed: $?"
+ else
+ echo "Succeeded"
+ fi
+
+ if [ $VERBOSE -eq "true" ]; then
+ echo "\nOutput:\n$result"
+ fi
+}
+
+if [[ $ALL -eq "true" || $SIGNITURE -eq "true" ]]; then
+ echo "Testing signiture key..."
+ result="$(echo '' | gpg --clearsign &>/dev/null 2>&1)"
+ print_result result
+fi
+
+if [[ $ALL -eq "true" || $ENCRYPTION -eq "true" ]]; then
+ echo "Testing encryption key..."
+ temp="$(mktemp -d)"
+ echo "secret file contents: 42" >$temp/test.txt
+
+ result="$(gpg --output $temp/test.gpg -e $temp/test.txt 2>&1 && gpg --output $temp/test.out -d $temp/test.txt.gpg 2>&1)"
+ grep '42' $temp/test.out 2>&1
+ print_result result
+fi
+
+if [[ $ALL -eq "true" || $AUTHENTICATION -eq "true" ]]; then
+ echo "Testing authentication key..."
+ result="$(ssh-add -l)"
+ print_result result
+fi