Last active
January 28, 2022 06:58
-
-
Save morgwai/016fae4fd22f01e225509b76fee1d6c7 to your computer and use it in GitHub Desktop.
A script that gets WKD URL for the email address passed as the argument. See https://datatracker.ietf.org/doc/html/draft-koch-openpgp-webkey-service-13#section-3.1
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
#!/bin/bash | |
# Copyright (c) Piotr Morgwai Kotarbinski, Licensed under the Apache License, Version 2.0 | |
usage='usage: wkdurl [--direct | --advanced] [email protected]' ; | |
if [[ "${#}" -lt 1 ]] || [[ "${#}" -gt 2 ]] ; then | |
echo "${usage}" >&2 ; | |
exit 1 ; | |
fi ; | |
direct='false' ; | |
if [[ "${#}" -eq 2 ]] ; then | |
case "${1}" in | |
'--direct') | |
direct='true' ;; | |
'--advanced') | |
;; # advanced is the default setting above | |
*) | |
echo "unrecognized option '${1}', ${usage}" >&2 ; | |
exit 1 ;; | |
esac ; | |
shift ; | |
fi ; | |
IFS='@' read user domain <<< "${1}" ; | |
domain="${domain,,}" ; | |
if [[ -z "${user}" ]] || [[ -z "${domain}" ]] ; then | |
#TODO: validate email address format more | |
echo "invalid email address" >&2 ; | |
exit 2 ; | |
fi ; | |
hashedUser=$( echo -n "${user,,}" |sha1sum |cut -d ' ' -f 1 |xxd -r -p - |base32 |sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ234567/ybndrfg8ejkmcpqxot1uwisza345h769/' ) ; | |
urlencodedUser=$( echo -n "${user}" |python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read()))" ) ; | |
if "${direct}" ; then | |
echo "https://${domain}/.well-known/openpgpkey/hu/${hashedUser}?l=${urlencodedUser}" ; | |
else | |
echo "https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${hashedUser}?l=${urlencodedUser}" ; | |
fi ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment