-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add support for OAuth 2.0 Attestation-based client authentication #47962
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34acfc0
Add support for OAuth 2.0 Attestation-based client authentication
tdiesler c8a8a26
-- address review comments from @IngridPuppet
tdiesler 6c46eb6
-- add OIDCMockClientAttester and ECDSAProvider
tdiesler 04adf4c
-- test client attestation happy flow
tdiesler f5be153
-- address review comments from @mposolda (thanks)
tdiesler 0fb3861
-- revisit key algorithm handling
tdiesler 0687153
-- reverse unrelated DPoP changes
tdiesler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/src/main/java/org/keycloak/jose/jws/crypto/ECDSAProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2026 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.keycloak.jose.jws.crypto; | ||
|
|
||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.security.PublicKey; | ||
| import java.security.cert.X509Certificate; | ||
|
|
||
| import org.keycloak.common.util.PemUtils; | ||
| import org.keycloak.crypto.ECDSASignatureVerifierContext; | ||
| import org.keycloak.crypto.KeyUse; | ||
| import org.keycloak.crypto.KeyWrapper; | ||
| import org.keycloak.jose.jws.Algorithm; | ||
| import org.keycloak.jose.jws.JWSInput; | ||
|
|
||
| /** | ||
| * @author <a href="mailto:[email protected]">Thomas Diesler</a> | ||
| */ | ||
| public class ECDSAProvider implements SignatureProvider { | ||
|
|
||
| public static String getJavaAlgorithm(Algorithm alg) { | ||
| switch (alg) { | ||
| case ES256: | ||
| return "SHA256withECDSA"; | ||
| case ES384: | ||
| return "SHA384withECDSA"; | ||
| case ES512: | ||
| return "SHA512withECDSA"; | ||
| default: | ||
| throw new IllegalArgumentException("Not a supported ECDSA Algorithm: " + alg); | ||
| } | ||
| } | ||
|
|
||
| public static boolean verify(JWSInput jws, PublicKey publicKey) { | ||
| String alg = jws.getHeader().getAlgorithm().name(); | ||
| try { | ||
| KeyWrapper kw = new KeyWrapper(); | ||
| kw.setPublicKey(publicKey); | ||
| kw.setUse(KeyUse.SIG); | ||
| kw.setType("EC"); | ||
| kw.setAlgorithm(alg); | ||
| byte[] data = jws.getEncodedSignatureInput().getBytes(StandardCharsets.UTF_8); | ||
| byte[] signature = jws.getSignature(); | ||
| return new ECDSASignatureVerifierContext(kw).verify(data, signature); | ||
| } catch (Exception e) { | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean verify(JWSInput input, String cert) { | ||
| return verifyViaCertificate(input, cert); | ||
| } | ||
|
|
||
| // Private --------------------------------------------------------------------------------------------------------- | ||
|
|
||
| private static boolean verifyViaCertificate(JWSInput input, String cert) { | ||
| X509Certificate certificate; | ||
| try { | ||
| certificate = PemUtils.decodeCertificate(cert); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| return verify(input, certificate.getPublicKey()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is really needed? I assume that if client is authenticating with ABCA, it should be always confidential client? Is it possible to make sure that only confidential clients authenticate with ABCA?
Public clients are not supposed to authenticate with any client authentication methods. They usually use just
client_idparameter to "identify" themselves in the request andfor this purpose, we just useexpectedClientAuthTypeset toKeycloakModelUtils.getDefaultClientAuthenticatorType().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was indeed a change in the spec from “mechanism for public clients to authenticate” to “general client authentication mechanism”. The draft decoupled itself from OAuth’s client-type distinction entirely - it effectively introduces a third model: attested clients (orthogonal to public/confidential).
This shift aligns with the underlying idea: attestation provides hardware/software-backed proof which can substitute:
Without this change, the AttestationBasedClientAuthenticator is not called for confidential clients. I added a test thereof.
Note, an invalid abca request or missing attester pub key currently fails in the AttestationBasedClientAuthenticator but is silently ignored because some other ClientAuthenticator succeeds - this might be a TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, more details would be good. Maybe we can discuss on one of our next meetings?
Just to doublecheck: Is it this specification draft, which you talk about https://datatracker.ietf.org/doc/html/draft-ietf-oauth-attestation-based-client-auth-08 ?
This change is OK in this PR, but we possibly need to figure this as a follow-up to avoid directly referencing the concrete authenticator from
ClientAuthenticationFlow.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually https://www.ietf.org/archive/id/draft-ietf-oauth-attestation-based-client-auth-07.html
which I have bookmarked. I could however not find a reference to it in https://openid.net/specs/openid4vc-high-assurance-interoperability-profile-1_0-final.html @thomasdarimont could you perhaps confirm the exact abca spec version that we ought to use?