Repository navigation
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
<
8000
template class="js-comment-button-template">
32 changes: 31 additions & 1 deletion
32
common/src/main/java/org/keycloak/common/crypto/CryptoIntegration.java
9 changes: 4 additions & 5 deletions
9
crypto/elytron/src/main/java/org/keycloak/crypto/elytron/AesKeyWrapAlgorithmProvider.java
Loading
Loading
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
25 changes: 25 additions & 0 deletions
25
common/src/main/java/org/keycloak/common/crypto/CryptoProviderFactory.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,25 @@ | ||
| /* | ||
| * 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.common.crypto; | ||
|
|
||
| public interface CryptoProviderFactory { | ||
|
|
||
| String getName(); | ||
|
|
||
| CryptoProvider create(FipsMode fipsMode); | ||
| } |
54 changes: 54 additions & 0 deletions
54
common/src/main/java/org/keycloak/common/crypto/FipsProvider.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,54 @@ | ||
| /* | ||
| * 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.common.crypto; | ||
|
|
||
| public enum FipsProvider { | ||
| AUTO("auto"), | ||
| BOUNCY_CASTLE("bouncycastle"), | ||
| GLASSLESS("glassless"); | ||
|
|
||
| private static final String BOUNCY_CASTLE_FIPS_PROVIDER = | ||
| "org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider.class"; | ||
|
|
||
| private final String optionName; | ||
|
|
||
| FipsProvider(String optionName) { | ||
| this.optionName = optionName; | ||
| } | ||
|
|
||
| public static FipsProvider valueOfOption(String name) { | ||
| for (FipsProvider provider : values()) { | ||
| if (provider.optionName.equals(name)) { | ||
| return provider; | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Unknown FIPS provider: " + name); | ||
| } | ||
|
|
||
| public FipsProvider resolve(ClassLoader classLoader) { | ||
| if (this != AUTO) { | ||
| return this; | ||
| } | ||
| return classLoader.getResource(BOUNCY_CASTLE_FIPS_PROVIDER) == null ? GLASSLESS : BOUNCY_CASTLE; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return optionName; | ||
| } | ||
| } |
96 changes: 96 additions & 0 deletions
96
common/src/test/java/org/keycloak/common/crypto/CryptoProviderFactoryTest.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,96 @@ | ||
| /* | ||
| * 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.common.crypto; | ||
|
|
||
| import java.lang.reflect.Proxy; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class CryptoProviderFactoryTest { | ||
|
|
||
| @Test | ||
| public void shouldSelectFactoryByNameAndPassFipsMode() { | ||
| CryptoProvider expected = provider(); | ||
| AtomicReference<FipsMode> selectedMode = new AtomicReference<>(); | ||
| List<CryptoProviderFactory> factories = Arrays.asList( | ||
| factory("default", provider(), new AtomicReference<>()), | ||
| factory("glassless", expected, selectedMode)); | ||
|
|
||
| CryptoProvider actual = CryptoIntegration.detectProvider(factories, "glassless", FipsMode.STRICT); | ||
|
|
||
| assertSame(expected, actual); | ||
| assertEquals(FipsMode.STRICT, selectedMode.get()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRejectMissingFactory() { | ||
| IllegalStateException cause = assertThrows(IllegalStateException.class, | ||
| () -> CryptoIntegration.detectProvider(Collections.emptyList(), "glassless", FipsMode.STRICT)); | ||
|
|
||
| assertEquals("Expected one crypto provider named 'glassless', found 0", cause.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRejectDuplicateFactories() { | ||
| List<CryptoProviderFactory> factories = Arrays.asList( | ||
| factory("glassless", provider(), new AtomicReference<>()), | ||
| factory("glassless", provider(), new AtomicReference<>())); | ||
|
|
||
| IllegalStateException cause = assertThrows(IllegalStateException.class, | ||
| () -> CryptoIntegration.detectProvider(factories, "glassless", FipsMode.STRICT)); | ||
|
|
||
| assertEquals("Expected one crypto provider named 'glassless', found 2", cause.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRejectNullProvider() { | ||
| IllegalStateException cause = assertThrows(IllegalStateException.class, | ||
| () -> CryptoIntegration.detectProvider( | ||
| Collections.singletonList(factory("glassless", null, new AtomicReference<>())), "glassless", FipsMode.STRICT)); | ||
|
|
||
| assertEquals("Crypto provider factory 'glassless' returned null", cause.getMessage()); | ||
| } | ||
|
|
||
| private static CryptoProviderFactory factory(String name, CryptoProvider provider, AtomicReference<FipsMode> selectedMode) { | ||
| return new CryptoProviderFactory() { | ||
| @Override | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public CryptoProvider create(FipsMode fipsMode) { | ||
| selectedMode.set(fipsMode); | ||
| return provider; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private static CryptoProvider provider() { | ||
| return (CryptoProvider) Proxy.newProxyInstance(CryptoProvider.class.getClassLoader(), | ||
| new Class<?>[] { CryptoProvider.class }, (proxy, method, args) -> null); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
common/src/test/java/org/keycloak/common/crypto/FipsProviderTest.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,78 @@ | ||
| /* | ||
| * 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.common.crypto; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class FipsProviderTest { | ||
|
|
||
| @Test | ||
| public void shouldResolveProviderOptions() { | ||
| assertEquals(FipsProvider.AUTO, FipsProvider.valueOfOption("auto")); | ||
| assertEquals(FipsProvider.BOUNCY_CASTLE, FipsProvider.valueOfOption("bouncycastle")); | ||
| assertEquals(FipsProvider.GLASSLESS, FipsProvider.valueOfOption("glassless")); | ||
| assertEquals("auto", FipsProvider.AUTO.toString()); | ||
| assertEquals("bouncycastle", FipsProvider.BOUNCY_CASTLE.toString()); | ||
| assertEquals("glassless", FipsProvider.GLASSLESS.toString()); | ||
| assertThrows(IllegalArgumentException.class, () -> FipsProvider.valueOfOption("unknown")); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldSelectGlasslessWhenBouncyCastleIsUnavailable() { | ||
| assertEquals(FipsProvider.GLASSLESS, FipsProvider.AUTO.resolve(new ClassLoader(null) { | ||
| })); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldSelectBouncyCastleWhenItsProviderClassIsAvailable() { | ||
| ClassLoader classLoader = new ClassLoader(null) { | ||
| @Override | ||
| public java.net.URL getResource(String name) { | ||
| return "org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider.class".equals(name) | ||
| ? FipsProviderTest.class.getResource("FipsProviderTest.class") | ||
| : null; | ||
| } | ||
| }; | ||
|
|
||
| assertEquals(FipsProvider.BOUNCY_CASTLE, FipsProvider.AUTO.resolve(classLoader)); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldPreserveExplicitProviderSelection() { | ||
| ClassLoader classLoader = new ClassLoader(null) { | ||
| @Override | ||
| public java.net.URL getResource(String name) { | ||
| return FipsProviderTest.class.getResource("FipsProviderTest.class"); | ||
| } | ||
| }; | ||
|
|
||
| assertEquals(FipsProvider.GLASSLESS, FipsProvider.GLASSLESS.resolve(classLoader)); | ||
| assertEquals(FipsProvider.BOUNCY_CASTLE, FipsProvider.BOUNCY_CASTLE.resolve(new ClassLoader(null) { | ||
| })); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldKeepExistingProviderClassNames() { | ||
| assertEquals("org.keycloak.crypto.fips.FIPS1402Provider", FipsMode.NON_STRICT.getProviderClassName()); | ||
| assertEquals("org.keycloak.crypto.fips.Fips1402StrictCryptoProvider", FipsMode.STRICT.getProviderClassName()); | ||
| assertEquals("org.keycloak.crypto.def.DefaultCryptoProvider", FipsMode.DISABLED.getProviderClassName()); | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
crypto/default/src/main/java/org/keycloak/crypto/def/DefaultCryptoProviderFactory.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,38 @@ | ||
| /* | ||
| * 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.crypto.def; | ||
|
|
||
| import org.keycloak.common.crypto.CryptoProvider; | ||
| import org.keycloak.common.crypto.CryptoProviderFactory; | ||
| import org.keycloak.common.crypto.FipsMode; | ||
|
|
||
| public class DefaultCryptoProviderFactory implements CryptoProviderFactory { | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "default"; | ||
| } | ||
|
|
||
| @Override | ||
| public CryptoProvider create(FipsMode fipsMode) { | ||
| if (fipsMode.isFipsEnabled()) { | ||
| throw new IllegalArgumentException("The default crypto provider does not support FIPS mode"); | ||
| } | ||
| return new DefaultCryptoProvider(); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...ult/src/main/resources/META-INF/services/org.keycloak.common.crypto.CryptoProviderFactory
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,18 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| org.keycloak.crypto.def.DefaultCryptoProviderFactory |
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.
GlaSSLess FIPS implementation #51082
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