Skip to content

Instantly share code, notes, and snippets.

@djmetzle
Last active December 12, 2022 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djmetzle/4a5fbb21c2e4d6ecb9f350671b0c1347 to your computer and use it in GitHub Desktop.
Save djmetzle/4a5fbb21c2e4d6ecb9f350671b0c1347 to your computer and use it in GitHub Desktop.
Script to fetch and calculate OpenID Connect thumbprint for Github Actions (or others)
GITHUB_ACTIONS='token.actions.githubusercontent.com'
OIDC_PATH='.well-known/openid-configuration'
HOST=$(curl https://$GITHUB_ACTIONS/$OIDC_PATH \
| jq -r '.jwks_uri | split("/")[2]')
echo "Fetching thumbprint for: $HOST"
RAWCERT=$(echo | openssl s_client -servername $HOST -showcerts -connect $HOST:443 2> /dev/null)
CERT=$(echo "$RAWCERT" | sed -n -e '/BEGIN/h' -e '/BEGIN/,/END/H' -e '$x' -e '$p' | tail -n +2)
SSLPRINT=$(openssl x509 -fingerprint -noout <<< $CERT)
THUMBPRINT=$(echo $SSLPRINT | sed -e "s/.*=//" -e "s/://g" | tr "ABCDEF" "abcdef")
echo "thumbprint: $THUMBPRINT"
@djmetzle
Copy link
Author

djmetzle commented Dec 12, 2022

The arcane version peppered around in various places online does not copy+paste to linux (because of a tail +2).
This rewrite should accomplish the same thing, calculating the fingerprint, but hopefully names a few of the intermediary steps, to better hint at how the thumbprint is assembled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment