Skip to content

Instantly share code, notes, and snippets.

@korc
Created January 19, 2021 00:31
Show Gist options
  • Save korc/b744f2bc0f5823044ed70238388e985d to your computer and use it in GitHub Desktop.
Save korc/b744f2bc0f5823044ed70238388e985d to your computer and use it in GitHub Desktop.
#!/bin/sh
remote="$1"
test -d "$2" || {
echo "Usage: ${0##*/} <host:port> <cert_dirs..>" >&2
exit 1
}
shift
set -e
fplist="$(mktemp)"
on_exit() { rm -f "$fplist"; }
trap on_exit EXIT
gnutls-cli --print-cert $remote </dev/null | certtool -i | sed -E -n -e '/sha256:/{s/.*://;p}' -e '/Issuer: /{s/.*:/Subject:/;p}' >"$fplist"
fplist="$fplist" find "$@" \( -name '*.crt' -o -name '*.pem' \) -exec sh -c 'for crt;do grep -q "BEGIN CERTIFICATE" "$crt" || continue; certtool -i <"$crt" | grep -Fqf "$fplist" && echo "$crt";done' a {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment