How can I calculate the thumbprint of an OpenID Connect server?

When creating an OpenID Connect Provider (for e.g. AWS), I need to specify a thumbprint for the connector. What is it, and how do I get it?

E.g. from How can I connect GitHub actions with AWS deployments without using a secret key?

resource "aws_iam_openid_connect_provider" "github" {
  url = "https://token.actions.githubusercontent.com"
  client_id_list = [
    "githubactions",
  ]
  thumbprint_list = [
    "6938fd4d98bab03faadb97b34396831e3780aea1",
  ]
}

Solution 1:

A thumbprint of an Open ID Connector is a SHA1 hash of the public certificate of the host. To calculate it, you need to obtain the service's certificate, and then calculate the hash using a tool like openssl.

Consider creating a thumbprint for the GitHub OpenID connector for GitHub actions https://token.actions.githubusercontent.com (for example, because you are interested in wiring up GitHub Actions with AWS).

You can run the following script to calculate the thumbprint:

% HOST=$(curl https://vstoken.actions.githubusercontent.com/.well-known/openid-configuration \
| jq -r '.jwks_uri | split("/")[2]')
% echo | openssl s_client -servername $HOST -showcerts -connect $HOST:443 2> /dev/null \
| sed -n -e '/BEGIN/h' -e '/BEGIN/,/END/H' -e '$x' -e '$p' | tail +2 \
| openssl x509 -fingerprint -noout \
| sed -e "s/.*=//" -e "s/://g" \
| tr "ABCDEF" "abcdef"
6938fd4d98bab03faadb97b34396831e3780aea1

What does this all mean?

The OpenID Configuration 'well known service', located at https://.../.well-known/openid-configuration provides a list of known services, including the .jwks_uri, which looks like this:

{
  "issuer": "https://token.actions.githubusercontent.com",
  "jwks_uri": "https://token.actions.githubusercontent.com/.well-known/jwks",
  "subject_types_supported": [
    "public",
    "pairwise"
  ],
  "response_types_supported": [
    "id_token"
  ],
  "claims_supported": [
    "sub",
    "aud",
    "exp",
    "iat",
    "iss",
    "jti",
    "nbf",
    "ref",
    "repository",
    "repository_owner",
    "run_id",
    "run_number",
    "run_attempt",
    "actor",
    "workflow",
    "head_ref",
    "base_ref",
    "event_name",
    "ref_type",
    "environment",
    "job_workflow_ref"
  ],
  "id_token_signing_alg_values_supported": [
    "RS256"
  ],
  "scopes_supported": [
    "openid"
  ]
}

In this case, it tells the client that the host to connect to for the Json Web Key Service URI is located at https://token.actions.githubusercontent.com/.well-known/jwks, but the only thing we need (for the SSL certificate) is the host name token.actions.githubusercontent.com. We can use JQ to pipe this to the split("/") function and obtain the [2] element, which in this case is just the host name.

In this example, the host name is the same as the one we originally queried, but it could well be different.

Getting the certificates from the host can be done with OpenSSL; we use openssl s_client -servername $HOST -showcerts -connect $HOST:443 to make a TLS connection to the host and dump its certificates. Since we don't actually need to send any data, we pipe the output of echo to initiate session communication.

This will result in an output looking like:

CONNECTED(00000005)
---
Certificate chain
 0 s:/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=*.actions.githubusercontent.com
   i:/C=US/O=DigiCert Inc/CN=DigiCert TLS RSA SHA256 2020 CA1
-----BEGIN CERTIFICATE-----
MIIG9jCCBd6gAwIBAgIQCFCR4fqbkQJJbzQZsc87qzANBgkqhkiG9w0BAQsFADBP
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMSkwJwYDVQQDEyBE
aWdpQ2VydCBUTFMgUlNBIFNIQTI1NiAyMDIwIENBMTAeFw0yMjAxMTEwMDAwMDBa
Fw0yMzAxMTEyMzU5NTlaMHsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9y
bmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRUwEwYDVQQKEwxHaXRIdWIsIElu
Yy4xKDAmBgNVBAMMHyouYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20wggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCcHl5GgNgXYUI5Zz085Ar9wSiI
gdDnOkaXof2u3pcJ1138Tlz6aheVqXfJ8MOAups0LTr9j/dTHAGWKQz0qdyUdYIJ
FwiOlkmphoP+a4xVJXbdVVN7qvmfV8f0YnG5oGVyx9hDl/30JReVIYPbC8JNSiIW
2jMYnjqPu41tPclNNroW9K8gJUzT/WE4LRHohOmR1GbC1xQ8YlFS6pFs+X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xSb290Q0EuY3JsMDAGA1UdIAQpMCcwBwYFZ4EMAQEwCAYG
Z4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEBAHer
t3onPa679n/gWlbJhKrKW3EX3SJH/E6f7tDBpATho+vFScH90cnfjK+URSxGKqNj
OSD5nkoklEHIqdninFQFBstcHL4AGw+oWv8Zu2XHFq8hVt1hBcnpj5h232sb0HIM
ULkwKXq/YFkQZhM6LawVEWwtIwwCPgU7/uWhnOKK24fXSuhe50gG66sSmvKvhMNb
g0qZgYOrAKHKCjxMoiWJKiKnpPMzTFuMLhoClw+dj20tlQj7T9rxkTgl4ZxuYRiH
as6xuwAwapu3r9rxxZf+ingkquqTgLozZXq8oXfpf2kUCwA/d5KxTVtzhwoT0JzI
8ks5T1KESaZMkE4f97Q=
-----END CERTIFICATE-----
---
Server certificate
subject=/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=*.actions.githubusercontent.com
issuer=/C=US/O=DigiCert Inc/CN=DigiCert TLS RSA SHA256 2020 CA1
---
No client certificate CA names sent
Server Temp Key: ECDH, P-384, 384 bits
---
SSL handshake has read 3571 bytes and written 398 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: 223C0000364B663D9E1AD1A1287F2F351C1E6D66075F206C8802B43EC6110B7A
    Session-ID-ctx: 
    Master-Key: BBA59654810DE8EF29C2CEBB9CD1D4B886D2FF89359F24A664B31B7F71E7F1CFE719734548216CFC626EC39498EC4BE9
    Start Time: 1642416883
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

There's some additional messages printed to stderr from this, which we don't need, so redirect that to null with 2> /dev/null.

The real content here that we need is just the content between the BEGIN and END sections; specifically, the last one. An easy way to do this if you have tac installed is simply to dump it backwards, print out the content between the END and BEGIN certificate, and then stop; followed by reversing it with tac again.

Since tac doesn't exist on macOS, it's possible to use native sed to do the work:

  • sed -n -- run sed, but don't print any output by default
    • -e '/BEGIN/h' -- when you see BEGIN, set the sed hold buffer to the line
    • -e '/BEGIN/,/END/H' -- for all lines between BEGIN and END, append them to the hold buffer (h sets the value, H appends it, but we end up with two BEGINs here)
    • -e '$x' -e '$p' -- when you get to the end of the file ($) swap the hold buffer for the output buffer (x) and then print it (p)
  • tail +2 -- prints out from line 2 onwards, to avoid the duplicated BEGIN from above.
  • openssl x509 -fingerprint -noout -- pipe the output to openssl which will give a fingerprint result of the form SHA1 Fingerprint= 69:38:FD:4D:98:BA:B0:3F:AA:DB:97:B3:43:96:83:1E:37:80:AE:A1
  • sed -e "s/.*=//" -e "s/://g" -- remove everything up to and including the = sign, and then drop all the colons (:) from the output
  • tr "ABCDEF" "abcdef" -- swap A for a, B for b etc. (Technically not needed but makes it seem less shouty.

The ultimate result of this, 6938fd4d98bab03faadb97b34396831e3780aea1, is the thumbprint that can be used when configuring your OpenID client, such as at How can I connect GitHub actions with AWS deployments without using a secret key?

Note that GitHub (accidentally) updated their thumbprint recently, so the result has changed from a031c46782e6e6c662c2c87c76da9aa62ccabd8e to 6938fd4d98bab03faadb97b34396831e3780aea1