diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | LICENSE | 7 | ||||
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | parcimini.bash | 48 | ||||
-rw-r--r-- | parcimini.service | 8 |
7 files changed, 99 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a6b807 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/parcimini @@ -0,0 +1,7 @@ +Copyright 2019 Tom Ryder + +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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b8144fe --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.POSIX: +.PHONY: all install clean +.SUFFIXES: +.SUFFIXES: .bash +PREFIX = /usr/local +BASH = /bin/bash +ALL = parcimini +.bash: + $(BASH) -c : + awk -v bash=$(BASH) 'NR == 1 { print "#!" bash } 1' $< > $@ + chmod +x ./$@ +all: $(ALL) +install: $(ALL) + mkdir -p -- $(PREFIX)/bin + cp -- parcimini $(PREFIX)/bin +clean: + rm -f -- $(ALL) diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc1601b --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +Parcimini +========= + +Refresh GnuPG keyring slowly, in random order, with random waits between each +refresh, looping indefinitely. Intended as an incompatible alternative for +[parcimonie](https://github.com/EtiennePerot/parcimonie.sh). + +You will almost certainly want `use-tor` in your `dirmngr.conf` for this to be +useful at all. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under an [MIT License][2]. + +[1]: https://sanctum.geek.nz/ +[2]: https://www.opensource.org/licenses/MIT @@ -0,0 +1 @@ +0.1.0 diff --git a/parcimini.bash b/parcimini.bash new file mode 100644 index 0000000..11c7207 --- /dev/null +++ b/parcimini.bash @@ -0,0 +1,48 @@ +self=parcimini + +# Base interval between key retrievals from first arg; default 20 mins +interval=${1:-1200} + +# Check we have gpg2 and shuf, neither of which are POSIX +hash gpg2 || exit +hash shuf || exit + +# Make a temporary file for the key listings, delete on exit +trap 'rm -f "$list"' EXIT +list=$(mktemp) || exit + +# Define a function to retrieve all keychain fingerprints +key_ids() { + gpg2 --batch --no-tty --list-keys --with-colons | + awk 'BEGIN { FS = ":" } +$1 == "pub" { pub = 1 ; next } +$1 == "fpr" && pub { pub = 0 ; key_ids[$(NF-1)]++ } +END { for (key_id in key_ids) print key_id }' +} + +# Log process start +printf >&2 '%s: Started; base interval %u seconds.\n' \ + "$self" "$interval" + +# While we're able to write the key list to the file, refresh all of them +while key_ids > "$list" ; do + printf >&2 '%s: Beginning new round; %u key IDs found.\n' \ + "$self" "$(sed '$=;d' "$list")" + + # Shuffle list and read each ID + shuf "$list" | + while read -r key_id ; do + + # Sleep for a random interval + spell=$((RANDOM % interval + 1)) + printf >&2 '%s: Sleeping for %u seconds...\n' \ + "$self" "$spell" + sleep "$spell" + + # Retrieve key + printf >&2 '%s: Retrieving key %s...\n' \ + "$self" "$key_id" + gpg2 --batch --no-tty --recv-key "$key_id" + + done +done diff --git a/parcimini.service b/parcimini.service new file mode 100644 index 0000000..3de1530 --- /dev/null +++ b/parcimini.service @@ -0,0 +1,8 @@ +[Service] +ExecStart=/usr/local/bin/parcimini +Restart=always +PrivateTmp=true +NoNewPrivileges=true + +[Install] +WantedBy=default.target |