-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38932 from sberyozkin/oidc_hybrid_certificate_chain
Fix NPE when OIDC token must be verified with the chain with OIDC server returning no JWKs
- Loading branch information
Showing
12 changed files
with
133 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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
51 changes: 51 additions & 0 deletions
51
integration-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/TestUtils.java
This file contains 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,51 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.security.PrivateKey; | ||
import java.security.cert.X509Certificate; | ||
import java.util.List; | ||
|
||
import io.quarkus.oidc.runtime.OidcUtils; | ||
import io.smallrye.jwt.build.Jwt; | ||
import io.smallrye.jwt.util.KeyUtils; | ||
import io.smallrye.jwt.util.ResourceUtils; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class TestUtils { | ||
|
||
public static String createTokenWithInlinedCertChain(String preferredUserName) throws Exception { | ||
X509Certificate rootCert = KeyUtils.getCertificate(ResourceUtils.readResource("/ca.cert.pem")); | ||
X509Certificate intermediateCert = KeyUtils.getCertificate(ResourceUtils.readResource("/intermediate.cert.pem")); | ||
X509Certificate subjectCert = KeyUtils.getCertificate(ResourceUtils.readResource("/www.quarkustest.com.cert.pem")); | ||
PrivateKey subjectPrivateKey = KeyUtils.readPrivateKey("/www.quarkustest.com.key.pem"); | ||
|
||
String bearerAccessToken = getAccessTokenWithCertChain( | ||
List.of(subjectCert, intermediateCert, rootCert), | ||
subjectPrivateKey, | ||
preferredUserName); | ||
|
||
assertX5cOnlyIsPresent(bearerAccessToken); | ||
return bearerAccessToken; | ||
} | ||
|
||
public static String getAccessTokenWithCertChain(List<X509Certificate> chain, | ||
PrivateKey privateKey, String preferredUserName) throws Exception { | ||
return Jwt.preferredUserName(preferredUserName) | ||
.groups("admin") | ||
.issuer("https://server.example.com") | ||
.audience("https://service.example.com") | ||
.jws().chain(chain) | ||
.sign(privateKey); | ||
} | ||
|
||
public static void assertX5cOnlyIsPresent(String token) { | ||
JsonObject headers = OidcUtils.decodeJwtHeaders(token); | ||
assertTrue(headers.containsKey("x5c")); | ||
assertFalse(headers.containsKey("kid")); | ||
assertFalse(headers.containsKey("x5t")); | ||
assertFalse(headers.containsKey("x5t#S256")); | ||
} | ||
|
||
} |