Skip to content

Instantly share code, notes, and snippets.

@jsrjenkins
Last active March 23, 2021 07:59
Show Gist options
  • Save jsrjenkins/a29a3b27a10d0b815acf551b1fda938d to your computer and use it in GitHub Desktop.
Save jsrjenkins/a29a3b27a10d0b815acf551b1fda938d to your computer and use it in GitHub Desktop.
Obtain the server certificate for offlineimap. Takes server as first argument, optional second argument for port.
!/bin/bash
## The first argument is the server
## the second [optional] argument is the port, default is 993.
server=$1
port=${2:-993}
SSL_CERT_DIR=""
openssl s_client -connect $server:$port </dev/null 2>/dev/null | openssl x509 -fingerprint -noout -text -in /dev/stdin | grep "^SHA1 Fingerprint=" | awk -F"=" '{split($2,a," ");gsub(/"/, "", a[1]);print a[1]}' | sed 's/://g' | xclip
echo "The certificate signature is now on the clipboard."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment