Last active
July 9, 2024 19:00
-
-
Save bsodmike/6a574382f5d553dfff8c4b759fca1dde to your computer and use it in GitHub Desktop.
Shell script (Fish) to upload all revoked GnuPG (GPG) keys to a keyserver
This file contains 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
#!/opt/homebrew/bin/fish | |
# | |
# Upload all revoked GnuPG (GPG) keys to a keyserver. | |
# Usage: fish ./upload_revoked.sh | |
# | |
# Copyright (c) Michael de Silva | |
# Profile: https://desilva.io/about | |
# Email: [email protected] // PGP: https://bit.ly/3W8u9R8 | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of | |
# this software and associated documentation files (the "Software"), to deal in | |
# the Software without restriction, including without limitation the rights to | |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
# the Software, and to permit persons to whom the Software is furnished to do so, | |
# subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
set -l keyserver "keys.openpgp.org" | |
set -l revoked_keys_array $(gpg --list-keys --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u) | |
set -l valid_keys $(echo "YOUR-KEY-ID") | |
set -l revoked_keys | |
for el in $revoked_keys_array | |
for v_el in $valid_keys | |
if test $v_el != $el | |
set -a revoked_keys $el | |
end | |
end | |
end | |
if test $(count $revoked_keys_array) = $(count $revoked_keys) | |
echo "ERROR the number of revoked keys must be less than the count of valid keys!" | |
exit 1 | |
end | |
for r_key in $revoked_keys | |
gpg --list-keys $r_key | grep "revoked" | |
if test $status -eq 0 | |
echo "Key-id: $r_key has been REVOKED!" | |
echo "" | |
echo "Send key to keyserver" | |
echo -e "n\n" |gpg --command-fd 0 --send-keys --keyserver "$keyserver" "$r_key" | |
echo "Verify revocation" | |
echo -e "n\n" |gpg --command-fd 0 --keyserver "$keyserver" --search-keys "$r_key" | grep "revoked" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment