Skip to content

SAML metadata certificate extractor

Pull the signing and encryption certificates out of SAML metadata as PEM, with their subject, expiry date and SHA-1 and SHA-256 fingerprints.

Runs in your browser. Nothing you paste is sent to us.

Metadata

A sample Keycloak realm descriptor with a throwaway certificate is filled in. Paste metadata or any XML that holds ds:X509Certificate elements.

Certificates found in the metadata are listed here.

How to use it

  1. Paste the metadata XML.
  2. Each certificate is listed once, with where it was found and what it is used for.
  3. Copy the PEM for tools that want a file, or the one-line Base64 for settings fields.
  4. Compare the fingerprints with the ones the other party gave you.

What to know

Metadata holds certificates in ds:X509Certificate elements as Base64 without line breaks or PEM headers. Most tools want PEM: the same Base64 in lines of 64 characters between BEGIN and END CERTIFICATE lines.

Fingerprints are hashes of the certificate’s bytes. They let two people confirm they hold the same certificate without sending it. SHA-256 is the safe one to compare; SHA-1 still appears in older consoles.

In Keycloak, a SAML identity provider takes the other side’s signing certificate in its Validating X509 certificates setting. A SAML client takes the app’s certificate under the client’s Keys tab.

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.

A signing key in metadata (sample)
<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.

The same values with OpenSSL
openssl x509 -in idp.pem -noout -subject -enddate
openssl x509 -in idp.pem -noout -fingerprint -sha256
openssl x509 -in idp.pem -noout -fingerprint -sha1

What 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

  1. Open the metadata URL in a browser tab and copy the XML, or open the metadata file.
  2. Paste it into the tool.
  3. Find the certificate with the use you need, usually signing.
  4. Copy the PEM for files and command-line tools, or the one-line Base64 for settings fields.
  5. 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:

  1. Create the new key at the identity provider, but keep signing with the old one.
  2. Publish both certificates in metadata, and give the new one to every app that does not read metadata.
  3. Wait until all apps trust the new certificate.
  4. Switch signing to the new key.
  5. 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

ProblemCauseFix
Tool says not valid Base64Text copied with extra characters or cut offCopy the whole element content again
Fingerprints do not match the other sideComparing SHA-1 with SHA-256, or a different certificateCompare the same hash of the same certificate
App rejects a valid-looking certificateApp wants PEM with headers, or Base64 withoutUse the output the app asks for
Certificate is expiredIdentity provider never rolled its keyRoll 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

FieldWhat to look for
SubjectWho the certificate names. For a Keycloak realm key it is the realm name.
IssuerWho signed it. Equal to the subject when self-signed, which is normal for SAML.
Not afterWhen it expires. Plan a rollover well before this date.
KeyType and size. RSA 2048 bit is the usual minimum today.
Signature algorithmHow the certificate itself was signed. SHA-256 with RSA is common.
SerialIdentifies 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.

Questions

Frequently asked questions

How do I get the certificate from SAML metadata?

Copy the text inside ds:X509Certificate. Wrap it at 64 characters per line and add BEGIN CERTIFICATE and END CERTIFICATE lines to get PEM. The tool does this for every certificate in the document.

How do I convert an X509Certificate to PEM?

Remove all whitespace, split the Base64 into lines of 64 characters, and put -----BEGIN CERTIFICATE----- before it and -----END CERTIFICATE----- after it.

What is a certificate fingerprint?

A hash of the certificate’s DER bytes. It identifies the certificate uniquely in practice, so two parties can compare fingerprints instead of whole certificates.

Should I compare SHA-1 or SHA-256 fingerprints?

SHA-256. SHA-1 is still shown by some consoles, but it is no longer considered collision resistant.

Where is the Keycloak SAML signing certificate?

In the realm’s SAML descriptor at /realms/<realm>/protocol/saml/descriptor, and in the admin console under Realm settings, Keys, where each key has a Certificate button.

Does an expired SAML certificate stop sign-in?

It depends on the app. Many SAML libraries check only that the key matches and ignore the dates. Others reject expired certificates, so plan rollovers before expiry.

Why are SAML certificates usually self-signed?

SAML trust is set up per connection: each side receives the other’s certificate directly or through metadata. A certificate authority adds little to that, so self-signed certificates are normal.

What key size should a SAML signing certificate have?

RSA 2048 bit is the usual minimum today, and larger keys are common. The certificate extractor shows the key type and size of each certificate.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.