2019-12-06 17:08:05 -06:00
#!/bin/bash
2021-01-10 21:42:46 -06:00
source /opt/aninix/Uniglot/Bash/header
2019-12-06 17:08:05 -06:00
unset canaryText
# cscanary=https://cryptostorm.is/canary.txt
# cskeyserver=pgp.mit.edu
# cskey=E9C7C942
keyserver=pool.sks-keyservers.net
key=1CC1E3F4ED06F296
2022-11-13 21:06:57 -06:00
canary=https://aninix.net/AniNIX/WarrantCanary/raw/branch/main/canary.asc
2021-01-10 21:42:46 -06:00
unset gitCommit
2019-12-06 17:08:05 -06:00
alJazeera='https://www.aljazeera.com/xml/rss/all.xml'
2021-01-10 21:42:46 -06:00
alJazeeraDate="$(date +%Y/%m/%d | sed -s 's#/0#/#g')"
2020-03-24 01:42:56 -05:00
npr='https://feeds.npr.org/1004/rss.xml'
2021-01-10 21:42:46 -06:00
nprdate="$(date +%Y/%m/%d)"
2019-12-06 17:08:05 -06:00
function Usage() {
# Show helptext
# param retcode: what to exit
retcode=$1
echo "Usage: $0 -V # Verify the AniNIX's warrant canary"
echo " $0 -V -k KEY -K KEYSERVER -c CANARY # Verify another warrant canary"
echo " $0 -s # Seed a warrant canary."
echo "Add -v to increase verbosity."
exit $retcode
}
2019-12-07 11:22:09 -06:00
2019-12-06 17:08:05 -06:00
function ConfirmGPGKeys() {
# Try to make sure we either have or can pull the key
if ! gpg2 --fingerprint "$key"; then
gpg --keyserver "$keyserver" --recv-key "$key"
2019-12-07 11:22:09 -06:00
if ! gpg2 --fingerprint "$key"; then
2019-12-06 17:08:05 -06:00
echo Cannot pull the key: "$key".
exit 1;
fi
fi
}
function RecentNews() {
# Pull the first recent news article from an RSS feed.
# param rssFeed: the url to pull
rssFeed="$1"
2021-01-10 21:42:46 -06:00
date="$2"
2022-02-16 09:29:57 -06:00
curl -s "$rssFeed" | grep "$date" | egrep -m 5 link | tail -n 1 | cut -f 2 -d '>' | cut -f 1 -d '?' | cut -f 1 -d '<'
2019-12-06 17:08:05 -06:00
}
2021-01-10 21:42:46 -06:00
function CreateCanary() {
rm ./canary.asc
cat > ./canary << EOM
2022-11-13 21:06:57 -06:00
As of $(date +%F), the AniNIX has not received any National Security Letters or FISA court orders, and we have not been subject to any gag order(s) by a FISA court, or any other similar court(s) of any government. AniNIX has never placed any backdoors in our hardware or software and has not received any requests to do so. AniNIX has never disclosed any user communications to any third party. No searches or seizures of any kind have ever been performed on AniNIX assets.
2019-12-06 17:08:05 -06:00
The next two updates should be on or before:
* `date -d @$(( $time + 7776000 )) +%F`
* `date -d @$(( $time + 15552000 )) +%F`
Recent news:
2021-01-10 21:42:46 -06:00
* $(RecentNews "$alJazeera" "$alJazeeraDate")
* $(RecentNews "$npr" "$nprdate")
2019-12-06 17:08:05 -06:00
To verify this message, on the terminal import our public key from $keyserver and verify the canary:
2022-11-13 21:06:57 -06:00
$ gpg --fetch-keys https://aninix.net/AniNIX/ShadowArch/raw/branch/main/EtcFiles/aninix.gpg
2019-12-06 17:08:05 -06:00
$ gpg2 --fingerprint $key
$(gpg2 --fingerprint $key)
$ gpg --verify <(curl -s $canary) 2>&1 | grep 'Good signature'
2021-01-10 21:42:46 -06:00
gpg: Good signature from "DarkFeather <ircs://aninix.net:6697/DarkFeather>" [ultimate]
2019-12-06 17:08:05 -06:00
There will most likely be other lines in the output from that last command, but as long as it says "Good signature", the verification worked correctly.
EOM
2021-01-10 21:42:46 -06:00
}
function CanarySeed() {
header Creating and signing a canary message
time=`date +%s`
# Create the canary.
CreateCanary
# Try signing
gpg --default-key "$key" --personal-digest-preferences sha512 --clear-sign ./canary
retcode=$?
if [ $retcode -eq 0 ]; then header Success; else errorheader Fail; exit "$retcode"; fi
# Git commit for consistent history
if [ -n "$gitCommit" ]; then
git add canary canary.asc
git commit -m "Canary update for $(date +%F)"
git push
echo
git log -n 1
fi
# Exit
exit 0
2019-12-06 17:08:05 -06:00
}
function CanaryVerify() {
# Verify a canary
header Fingerprinting:
ConfirmGPGKeys
echo
header Verification:
if [ -f "$canary" ]; then
canaryText="$(cat "$canary")"
else
canaryText="$(curl -s "$canary")"
fi
gpg --verify <(echo "$canaryText") 2>&1 | grep -v 'WARNING: not a detached signature'
retcode=$?
echo
header Human-readable text:
echo "$canaryText" | grep -B 99 'To verify this' | grep -v 'To verify this'
exit $retcode
}
# Parse arguments
2021-01-10 21:42:46 -06:00
while getopts 'c:ghk:K:svV' OPTION; do
2019-12-06 17:08:05 -06:00
case "$OPTION" in
c) canary="$OPTARG" ;;
2021-01-10 21:42:46 -06:00
g) gitCommit=1 ;;
2019-12-06 17:08:05 -06:00
h) echo Use this script to seed or verify a warrant canary; Usage 0 ;;
k) key="$OPTARG" ;;
K) keyserver="$OPTARG" ;;
s) CanarySeed ;;
v) set -x ;;
V) CanaryVerify ;;
*) Usage 1 ;;
esac
done
CanaryVerify