Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config to prevent thumbprint converting to hex before encoding #2331

Merged
merged 6 commits into from
Jan 22, 2024

Conversation

ashanthamara
Copy link
Contributor

@ashanthamara ashanthamara commented Jan 21, 2024

Proposed changes in this pull request

Fix wso2/product-is#18817

As per the specifications (RFC7515) the x5t#s256 value of the JWKS endpoint should be,

The "x5t#S256" (X.509 certificate SHA-256 thumbprint) Header Parameter is a base64url-encoded SHA-256 thumbprint (a.k.a. digest) of the DER encoding of the X.509 certificate [RFC5280] corresponding to the key used to digitally sign the JWS. Note that certificate thumbprints are also sometimes known as certificate fingerprints.

Hence, this will revert the #2128 and use the JWK library to get the x5t#S256 value.

For the backward compatibility a config has been introduced.

If someone wants to hexify the thumbprint, add following config to the deployment.toml file

[oauth.jwks_endpoint]
is_thumbprint_hexify_required = true

Before the Fix

x5t#S256

"x5t#S256": "MDJlNjIxN2E1OGZlOGVmMGQxOTFlMzBmNmFjZjQ0Y2YwOGY0N2I0YzE4YzZjNjRhYmRmMmQ0ODdiNDhjMGEwMA"

jwks response

{
    "keys": [
        {
            "kty": "RSA",
            "x5t#S256": "MDJlNjIxN2E1OGZlOGVmMGQxOTFlMzBmNmFjZjQ0Y2YwOGY0N2I0YzE4YzZjNjRhYmRmMmQ0ODdiNDhjMGEwMA",
            "e": "AQAB",
            "use": "sig",
            "kid": "MDJlNjIxN2E1OGZlOGVmMGQxOTFlMzBmNmFjZjQ0Y2YwOGY0N2I0YzE4YzZjNjRhYmRmMmQ0ODdiNDhjMGEwMA_RS256",
            "x5c": [
                "MIIDqTCCApGgAwIBAgIEYfEVSjANBgkqhkiG9w0BAQsFADBkMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxDTALBgNVBAoMBFdTTzIxDTALBg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9+kvpNQ94yFmEuhtDByvDijxAqvlin3TPIfy8="
            ],
            "alg": "RS256",
            "n": "kdgncoCrz655Lq8pTdX07eoVBjdZDCUE6ueBd0D1hpJ0_zE3x3Az6tlvzs98PsPuGzaQOMmuLa4qxNJ-OKxJmutDUlClpuvxuf-jyq4gCV5tEIILWRMBjlBEpJfWm63-VKKU4nvBWNJ7KfhWjl8-DUdNSh2pCDLpUObmb9Kquqc1x4BgttjN4rx_P-3_v-1jETXzIP1L44yHtpQNv0khYf4j_aHjcEri9ykvpz1mtdacbrKK25N4V1HHRwDqZiJzOCCISXDuqB6wguY_v4n0l1XtrEs7iCyfRFwNSKNrLqr23tR1CscmLfbH6ZLg5CYJTD-1uPSx0HMOB4Wv51PbWw"
        }
    ]
}

After the Fix

x5t#S256

"x5t#S256": "AuYhelj-jvDRkeMPas9Ezwj0e0wYxsZKvfLUh7SMCgA"

jwks response

{
    "keys": [
        {
            "kty": "RSA",
            "x5t#S256": "AuYhelj-jvDRkeMPas9Ezwj0e0wYxsZKvfLUh7SMCgA",
            "e": "AQAB",
            "use": "sig",
            "kid": "MDJlNjIxN2E1OGZlOGVmMGQxOTFlMzBmNmFjZjQ0Y2YwOGY0N2I0YzE4YzZjNjRhYmRmMmQ0ODdiNDhjMGEwMA_RS256",
            "x5c": [
                "MIIDqTCCApGgAwIBAgIEYfEVSjANBgkqhkiG9w0BAQsFADBkMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxDTALBgNVBAoMBFdTTzIxDTALBgNVBAsMBFdTTzIxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMjAxMjYwOTMyNThaFw0yNDA0MzAwOTMyNThaMGQxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzENMAsGA1UECgwEV1NPMjENMAsGA1UECwwEV1NPMjESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqh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qc1x4BgttjN4rx_P-3_v-1jETXzIP1L44yHtpQNv0khYf4j_aHjcEri9ykvpz1mtdacbrKK25N4V1HHRwDqZiJzOCCISXDuqB6wguY_v4n0l1XtrEs7iCyfRFwNSKNrLqr23tR1CscmLfbH6ZLg5CYJTD-1uPSx0HMOB4Wv51PbWw"
        }
    ]
}

Related PR

Related Issue

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/7605383076

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/7605383076
Status: failure

JWK parsedJWK = JWK.parse(certificate);
jwk.x509CertSHA256Thumbprint(parsedJWK.getX509CertSHA256Thumbprint());
} else {
jwk.x509CertSHA256Thumbprint(new Base64URL(OAuth2Util.getThumbPrint(certificate, alias)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will produce double encoding right? Wihtin the getThumbprint method aren't we encode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base64URL is just taking the string value and create a Base64URL instance where it doesn't encode it again. hence this won't be a problem

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/7606495700

Copy link
Contributor

@Thumimku Thumimku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, since this is a behavioural change please initiate and migration issue

@DMHP DMHP merged commit d9acead into wso2-extensions:master Jan 22, 2024
2 checks passed
@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/7606495700
Status: failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JWKS endpoint returns x5t#s256 value incompatible with the RFC specification
5 participants