- #!/bin/bash
- read -p 'Checking DKIM length for: ' DOMAIN
- SELECTOR=default._domainkey
- # Put the pubkey stuff from the DKIM record into a tmp file
- dig txt $SELECTOR.$DOMAIN +short | awk -F'p=' '{print $2}' > /tmp/$DOMAIN.key.txt
- # Strip out unnecessary characters
- sed -i 's/[^a-zA-Z0-9+'/']//g' /tmp/$DOMAIN.key.txt
- # Line wrap so openssl command will work
- fold -w 78 /tmp/$DOMAIN.key.txt > /tmp/$DOMAIN.key
- rm -f /tmp/$DOMAIN.key.txt
- # Insert the pubkey blocks
- sed -i '1 i\-----BEGIN PUBLIC KEY-----' /tmp/$DOMAIN.key
- echo "-----END PUBLIC KEY-----" >> /tmp/$DOMAIN.key
- echo " "
- echo "DKIM TXT RECORD:"
- echo "****************"
- dig txt $SELECTOR.$DOMAIN +short
- echo " "
- echo "PUBKEY:"
- echo "*******"
- cat /tmp/$DOMAIN.key
- echo " "
- echo "STRENGTH:"
- echo "*********"
- openssl rsa -noout -text -pubin < /tmp/$DOMAIN.key
- rm -f /tmp/$DOMAIN.key