Skip to content

Instantly share code, notes, and snippets.

@nemunaire
Last active June 26, 2018 21:41
Show Gist options
  • Save nemunaire/447c989e9f098c679edb to your computer and use it in GitHub Desktop.
Save nemunaire/447c989e9f098c679edb to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ "$1" = "-draft1" ] || [ "$1" = "-draft2" ]
then
shift
alias khash='python -c "import sys; import base64; print(base64.b32encode(sys.stdin.readline().strip().encode()).decode().lower())"'
elif [ "$1" = "-draft3" ]
then
shift
alias khash='sha224sum | cut -d " " -f 1'
else
alias khash='sha256sum | sed -E "s/^(.{56}).*/\1/"'
fi
[ $# -lt 1 ] && { echo "Please provide your email address as first argument" >&2; exit 1; }
ADDR="$1"
LOCAL=$(echo -n "${ADDR}" | cut -d "@" -f 1)
DOMAIN=$(echo -n "${ADDR}" | cut -d "@" -f 2)
if [ $# -ge 2 ]
then
ADDR="$2"
fi
if ! gpg --list-keys ${ADDR} > /dev/null 2> /dev/null
then
echo $(echo -n "$LOCAL" | khash)._openpgpkey.$DOMAIN.
elif [ $(gpg --list-keys "${ADDR}" | grep pub | wc -l) -gt 1 ]
then
echo "There are several keys matching the given argument(s)."
gpg --list-keys "${ADDR}"
echo "As second argument, give the fingerprint of the good key"
else
echo $(echo -n "$LOCAL" | khash | cut -d " " -f 1)._openpgpkey.$DOMAIN. IN OPENPGPKEY $(gpg --export --export-options export-minimal "${ADDR}" | base64 | tr -d "\n")
fi
#!/bin/sh
if [ "$1" = "-draft1" ] || [ "$1" = "-draft2" ]
then
shift
alias khash='python -c "import sys; import base64; print(base64.b32encode(sys.stdin.readline().strip().encode()).decode().lower())"'
elif [ "$1" = "-draft3" ]
then
shift
alias khash='sha224sum | cut -d " " -f 1'
else
alias khash='sha256sum | sed -E "s/^(.{56}).*/\1/"'
fi
[ $# -lt 1 ] && { echo "Please provide your email address as first argument" >&2; exit 1; }
ADDR="$1"
LOCAL=$(echo -n "${ADDR}" | cut -d "@" -f 1)
DOMAIN=$(echo -n "${ADDR}" | cut -d "@" -f 2)
if [ $# -ge 2 ]
then
ADDR="$2"
fi
echo $(echo -n "$LOCAL" | khash | cut -d " " -f 1)._smimecert.$DOMAIN. IN SMIMEA #$(gpg --export --export-options export-minimal "${ADDR}" | base64 | tr -d "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment