Why SAML needs certificates
SAML trust rests on signatures. An identity provider signs its responses or assertions with a private key, and the app checks them with the matching public key. The app can also sign its requests, and either side can encrypt for the other. In every case, the public key is shared as an X.509 certificate.
Most of the time the certificates travel in metadata. To set up a connection by hand, or to check that two systems trust the same key, you need to get the certificate out of the metadata in a form other tools accept. That is what this tool does.
Where certificates sit in metadata
Each role in a metadata document can have md:KeyDescriptor elements. Inside is an XML Signature ds:KeyInfo with a ds:X509Certificate element that holds the certificate as Base64-encoded DER.
<md:KeyDescriptor use="signing">
<ds:KeyInfo>
<ds:KeyName>sample-key-id</ds:KeyName>
<ds:X509Data>
<ds:X509Certificate>MIICmjCCAYICCQDQbs6sY6JobDANBgkqhkiG9w0BAQsFADAP…</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</md:KeyDescriptor>The use attribute says what the key is for: signing or encryption. Without it, the key serves both. Metadata may list several keys, for example a signing key and an encryption key, or an old and a new signing key during a rollover.
PEM, Base64 and fingerprints
Base64 in XML
The value in ds:X509Certificate is the certificate’s DER bytes in Base64, often on one line or wrapped at any width, with no header lines.
PEM
PEM is the same Base64 wrapped at 64 characters per line, between a -----BEGIN CERTIFICATE----- line and an -----END CERTIFICATE----- line. Command-line tools, web servers and most libraries expect PEM.
Fingerprints
A fingerprint is a hash of the certificate’s DER bytes, shown as hex pairs. Two people can compare fingerprints over chat or a ticket to confirm they hold the same certificate, without sending the certificate itself. SHA-256 is the one to compare. SHA-1 fingerprints still appear in older consoles; they identify a certificate but are not suitable as a security check on their own.
openssl x509 -in idp.pem -noout -subject -enddate
openssl x509 -in idp.pem -noout -fingerprint -sha256
openssl x509 -in idp.pem -noout -fingerprint -sha1What this tool does
Paste metadata, or any XML that contains ds:X509Certificate elements. The tool finds every certificate, lists each one once with where it was found and what it is used for, and shows:
- Subject and issuer, and whether the certificate is self-signed.
- Not before and not after dates, with an expired or in date badge.
- Key type and size, and the signature algorithm.
- Serial number.
- SHA-1 and SHA-256 fingerprints, computed with the browser’s Web Crypto.
- The certificate as PEM and as one line of Base64.
What it does not do
It does not check whether a certificate chains to a trusted authority, and it does not check revocation. SAML trust usually does not depend on either: most identity providers use self-signed certificates, and trust comes from how you received the metadata. The tool never sees a private key, and it does not need one.
How to use it
- Open the metadata URL in a browser tab and copy the XML, or open the metadata file.
- Paste it into the tool.
- Find the certificate with the use you need, usually signing.
- Copy the PEM for files and command-line tools, or the one-line Base64 for settings fields.
- Compare the SHA-256 fingerprint with the one the other party gave you.
Use cases
Setting up an app by hand
Some apps cannot import metadata and ask for an SSO URL and a signing certificate instead. Paste the identity provider’s metadata here, copy the SSO URL from the metadata viewer and the PEM from this tool.
Keycloak as identity provider
Keycloak signs SAML documents with the realm’s active RSA key. Its certificate appears in the realm descriptor at https://<host>/realms/<realm>/protocol/saml/descriptor, and in the admin console under Realm settings, Keys. A default realm key is self-signed with the realm name as its subject, which is what you see here for the sample realm.
Keycloak as service provider
When Keycloak brokers sign-in through another SAML identity provider, it must trust that provider’s signing certificate. In the identity provider’s settings, the Validating X509 certificates field holds it. Importing the provider’s metadata fills it in; this tool helps when you set it by hand or want to check what was imported.
Comparing keys during an incident
When signatures start failing, extract the certificate from the identity provider’s current metadata and compare its fingerprint with the one configured in the app. If they differ, the identity provider has rolled its key and the app has not caught up.
Certificate rollover
Signing keys should change from time to time, and must change if they leak. A rollover without downtime goes like this:
- Create the new key at the identity provider, but keep signing with the old one.
- Publish both certificates in metadata, and give the new one to every app that does not read metadata.
- Wait until all apps trust the new certificate.
- Switch signing to the new key.
- Remove the old certificate from metadata after a grace period.
In Keycloak you can do this with key providers: add a new RSA key provider, keep the old key enabled, and choose which key is active. Active keys sign; passive keys are kept for verifying only.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Tool says not valid Base64 | Text copied with extra characters or cut off | Copy the whole element content again |
| Fingerprints do not match the other side | Comparing SHA-1 with SHA-256, or a different certificate | Compare the same hash of the same certificate |
| App rejects a valid-looking certificate | App wants PEM with headers, or Base64 without | Use the output the app asks for |
| Certificate is expired | Identity provider never rolled its key | Roll the key; some apps accept expired certificates, others do not |
Security notes
- Certificates are public. Sharing them is safe; sharing a private key is not.
- Trust comes from the channel. Fetch metadata over https from the party itself, or check fingerprints with them out of band.
- An unexpected new certificate in metadata is worth asking about before you trust it.
Reading the certificate fields
| Field | What to look for |
|---|---|
| Subject | Who the certificate names. For a Keycloak realm key it is the realm name. |
| Issuer | Who signed it. Equal to the subject when self-signed, which is normal for SAML. |
| Not after | When it expires. Plan a rollover well before this date. |
| Key | Type and size. RSA 2048 bit is the usual minimum today. |
| Signature algorithm | How the certificate itself was signed. SHA-256 with RSA is common. |
| Serial | Identifies the certificate within its issuer. Useful in support tickets. |
The certificate’s own signature algorithm says nothing about how SAML messages are signed. A certificate signed with SHA-256 can carry a key that signs SAML messages with SHA-1, or the other way round. The SAML signature algorithm is a setting at the identity provider, visible in each message’s ds:SignatureMethod.
Encryption certificates
An app that wants encrypted assertions publishes an encryption certificate in its own metadata, with use="encryption" or no use. The identity provider encrypts each assertion with that public key, and only the app’s private key can read it.
In Keycloak, a SAML client’s Encrypt assertions setting uses the app’s encryption certificate, which you can import under the client’s Keys tab. Extract it from the app’s metadata here if the app gave you metadata rather than a PEM file. Rolling an encryption key needs care too: if the identity provider switches to the new certificate before the app can decrypt with the new key, every sign-in fails.