8000 Add ECDH-ES JWE Algorithm Provider by justin-tay · Pull Request #23928 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add ECDH-ES JWE Algorithm Provider - #23928

Merged
mposolda merged 6 commits into
keycloak:mainfrom
justin-tay:gh23597
Aug 8, 2024
Merged

mposolda merged 6 commits into
keycloak:mainfrom
justin-tay:gh23597

Conversation

@justin-tay
@justin-tay justin-tay commented Oct 12, 2023 •
Copy link
Copy Markdown
Contributor

Closes #23597, Closes #23596

This adds support for the ECDH-ES, ECDH-ES+A128KW, ECDH-ES+A192KW and ECDH-ES+A256KW JWE algorithms.

This required changes to the JWEAlgorithmProvider interface.

For decoding the CEK the following parameters were needed

  • The JWE Header in order to get the alg, enc, epk, apu and apv attributes
  • The JWE Encryption Provider in order to determine the CEK length if ECDH-ES is used

For encoding the CEK the following parameters were needed

  • The JWE Header Builder in order to get the alg, enc, apu and apv attributes and set the epk, apu and apv attributes

This also required changes to the JWEHeader to add the epk, apu and apv attributes and to make it mutable via a builder.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.saml.AudienceProtocolMappersTest#testAudienceResolveFullScope

Keycloak CI - Base IT (6)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:136)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:103)
...

Report flaky test

@tnorimat tnorimat left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@justin-tay Thank you. I added some review comments. Could you check them?

BCFIPSEcdhEsAlgorithmProvider, ElytronEcdhEsAlgorithmProvider, and BCEcdhEsAlgorithmProvider have a lot of shared codes.

Also, BCFIPSEcdhEsAlgorithmProviderTest, ElytronEcdhEsAlgorithmProviderTest, and BCEcdhEsAlgorithmProviderTest have a lot of shared codes.

It might be good if you consider designing those classes to reduce redundant codes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you replace 2016 with 2024 or 2023?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have replaced it with 2024.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about setting ecdhAlgorithm directly?

    return createKeyWrapper(keyPair, ecdhAlgorithm, KeyUse.ENC);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have set the ecdhAlgorithm directly as suggested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about the following (inserting a space) ?

            if (Algorithm.ECDH_ES.equals(algorithm)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have fixed the formatting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you.

@justin-tay
Copy link
Copy Markdown
Contributor Author

@tnorimat Thanks for the review! You are correct that there appears to be shared codes between the different EcdhEsAlgorithmProvider implementations and tests but I'm not sure where would be an appropriate place to put them as the crypto modules seem quite self contained and in a lot of cases there are also subtle differences in the implementation due to the differences in the API provided between BC, BCFIPS and Elytron so it's not that easy to share.

@tnorimat
tnorimat commented Aug 7, 2024
Copy link
Copy Markdown
Contributor

@justin-tay I see, so we keep your original codes in each BC, BCFIPS and Elytron modules even if these have shared codes.

@rmartinc
rmartinc commented Aug 7, 2024
Copy link
Copy Markdown
Contributor

@tnorimat @justin-tay The problem with duplicated code in crypto projects is old and it happens with other files (for example check BCFIPSOCSPProvider and BCOCSPProvider and many others). Maybe one possible solution is creating a crypto common project and put there the shared classes. But I think that is clearly outside the scope of this PR.

@rmartinc rmartinc left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @justin-tay! For me it's OK now. Approved!

@tnorimat tnorimat left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM
@justin-tay Thank you very much for your contribution.

@justin-tay
Copy link
Copy Markdown
Contributor Author

@rmartinc @tnorimat Thanks a lot for your time in doing the review! Let me know if I should squash and rebase the changes.

@mposolda mposolda left a comment •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@justin-tay @rmartinc @tnorimat Thanks everyone for the review!

I have only small concern that this test adds huge amount of new test classes - like 25 new classes of KcOidcBrokerJWEEcdh* . I appreciate the good test coverage, but at the same time, it can be quite an overhead... Is it maybe possible to keep around 5-6 most relevant combinations and delete the rest of those test classes from this PR? WDYT?

@mposolda
mposolda commented Aug 7, 2024
Copy link
Copy Markdown
Contributor

@justin-tay Also just an update, that you don't need to care about squashing commits for now. I can squash the commits during merging the PR.

@justin-tay
Copy link
Copy Markdown
Contributor Author

@mposolda Thanks for the update! Have left in 8 of the tests and removed the rest.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.BruteForceTest#testRaceAttackPermanentLockout

Keycloak CI - Forms IT (chrome)

java.lang.AssertionError: Invalid count should be less than or equal 2 but was: 3
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.forms.BruteForceTest.raceAttack(BruteForceTest.java:820)
	at org.keycloak.testsuite.forms.BruteForceTest.testRaceAttackPermanentLockout(BruteForceTest.java:790)
...

Report flaky test

org.keycloak.testsuite.actions.RequiredActionUpdateProfileTest#updateProfile

Keycloak CI - Forms IT (firefox)

org.openqa.selenium.TimeoutException: 
Navigation timed out after 10000 ms
Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.5.0-1025-azure', java.version: '21.0.4'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
...

Report flaky test

@mposolda
mposolda commented Aug 7, 2024 •
Copy link
Copy Markdown
Contributor

@justin-tay Thanks! The update is needed in fips-suite file as well. Besides that, I hope we can merge.

mposolda
mposolda previously approved these changes Aug 7, 2024
Closes keycloak#23596

Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
Closes keycloak#23597

Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
Signed-off-by: Justin Tay <49700559+justin-tay@users.noreply.github.com>
@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.javascript.JavascriptAdapterTest#testSilentCheckSso

Keycloak CI - Base IT (5)

java.lang.RuntimeException: Could not create statement
	at org.jboss.arquillian.junit.Arquillian.methodBlock(Arquillian.java:307)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@justin-tay @tnorimat @rmartinc Thanks again to everyone for the participation on this PR!

@mposolda
mposolda merged commit 966a454 into keycloak:main Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ECDH-ES JWE algorithms Support generated ECDH realm keys

5 participants

0