Skip to content

Instantly share code, notes, and snippets.

@irrashai
Created March 29, 2019 14:43
Show Gist options
  • Select an option

  • Save irrashai/a1aba77872475982d601bab16e970c73 to your computer and use it in GitHub Desktop.

Select an option

Save irrashai/a1aba77872475982d601bab16e970c73 to your computer and use it in GitHub Desktop.
check_quad9_keys: A script that checks for changes in Quad9 key used in stubby.yml
#!/bin/bash
# This script checks for changes in Quad9 key used in stubby.yml
# If it's the same = OK
# If changed, fetch the new key and update
# Replace with stubby location
PATH="/opt/getdns/etc/stubby"
cd $path
# Fetch the key
newkey=$(echo | openssl s_client -connect '9.9.9.9:853' 2>/dev/null | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64)
# Update the key in stubby
oldkey=$(yq r stubby.yml upstream_recursive_servers[0].tls_pubkey_pinset[0].value)
echo "Old key: $oldkey"
echo "New key: $newkey"
yaml_array="upstream_recursive_servers"
if [ "$newkey" != "$oldkey" ]
then
for i in $yaml_array; do
yq w -i stubby.yml $yaml_array[$i].tls_pubkey_pinset[0].value $newkey
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment