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

Customizable algorithm suite defaulting to FIPS compliance #1174

Conversation

JiriOndrusek
Copy link
Contributor

fixes #1173

@JiriOndrusek
Copy link
Contributor Author

The ws-trust native failure is a a bug in my code and I'll take care of it.

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from 21fcf38 to 7347b8e Compare January 11, 2024 14:22
@JiriOndrusek

This comment was marked as outdated.

@JiriOndrusek

This comment was marked as outdated.

@JiriOndrusek

This comment was marked as outdated.

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from 7347b8e to a72cad9 Compare January 12, 2024 13:12

BusFactory.setThreadDefaultBus(bus);

//programmatic registration of customizedAlgorithmSuite
Copy link
Contributor Author

@JiriOndrusek JiriOndrusek Jan 12, 2024

Choose a reason for hiding this comment

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

@ffang I had to register custom algorithm in this test. I suppose that in case of programmatic STS programmatic registration of alg suite makes sense, what do you think?

*/
public class CustomAlgSuiteLoader implements AlgorithmSuiteLoader {

public static final String DIGEST_ALGORITHM = "http://www.w3.org/2001/04/xmlenc#sha256";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppalaga I'd like to access default values of CxfBuilTimeConfig class here to avoid duplicated constant creation. Do you see any other way of avoiding duplicates? (I don't see any buildTimeConfig for ws-security, where it would be probably avoidlable. (core-deployment does not see ws-secuurity/runtime and vice versa)

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch 2 times, most recently from 18e6bb0 to 16afa4a Compare January 15, 2024 13:27
Comment on lines 204 to 206
//programmatic registration of customizedAlgorithmSuite
final Config config = ConfigProvider.getConfig();
new CustomAlgSuiteLoader(((JaxWsClientProxy) Proxy.getInvocationHandler(client)).getClient().getBus(), config);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ffang The same issue as is in ws-security-server tests. I have to register custom algorithm in this test. My code does not seem like a user preferred solution. Is it possible to achieve the same via some nicer configuration?

Copy link
Contributor

@ffang ffang Jan 16, 2024

Choose a reason for hiding this comment

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

Hi @JiriOndrusek ,

I think this is OK for now.

Though the ideal way is that we set this CustomAlgSuiteLoader in io.quarkiverse.cxf.QuarkusBusFactory as a bus extension when we have

quarkus.cxf.customizedAlgorithmSuite.enabled = true

and configurable algoSuite values.

Freeman

Copy link
Contributor Author

@JiriOndrusek JiriOndrusek Jan 17, 2024

Choose a reason for hiding this comment

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

Hi @ffang

I debugged this part of the test and there is a difference between natie and JVM mode. I'm setting the customAlgSuite via quarkus.cxf.customizedAlgorithmSuite.enabled = true

  • in JVM - bus created via QuarkusBusFactory is customized and the plain client get the same bus -> works without this line
  • in native - bus created via QuarkusBusFactory is customized, but plain client is creating its own bus, which is not affected by the QuarkusBusFactory. My understanding is that the client is created in the test resource (part of test folder, non-native, different JVM) part of executions. Therefore I had to customize the client's bus to make scenario work.

I think that in JVM code works without this configuration, because both plain client (test resource) and app part (from the main source folder) share the customAlgSuite registered into a static variable

Copy link
Contributor

Choose a reason for hiding this comment

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

@JiriOndrusek, this kind of differences is caused by the fact that in native mode, the tests run in a JVM, but the application under test is a fully different (native) process. Hence of you register something on the Bus in the application, it is not visible for the JVM running the tests.

In JVM mode, the tests and the application under test are a part of the same JVM.

So you either have to configure the stuff twice, or you have to move the SOAP client to the application and wrap it in REST. I think the second option is better, because it allows to cover also the client in native.

Copy link
Contributor Author

@JiriOndrusek JiriOndrusek Jan 17, 2024

Choose a reason for hiding this comment

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

I agree with the cause of the issue. I'll move the client creation into the application, where the customization configuration should take care of proper configuration.

@JiriOndrusek JiriOndrusek marked this pull request as ready for review January 15, 2024 13:44
@@ -445,4 +445,116 @@ default void validate(String prefix) {
}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we please move this to a new class in the security extension?

I'd vote for it being a Runtime fixed setting (should go to Security runtime module), so that users can query the values at runtime from their apps.

Something like

@ConfigMapping(prefix = "quarkus.cxf")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
@ConfigDocFilename("quarkus-cxf-rt-ws-security.adoc")
public interface CxfSecurityFixedConfig {
...

Copy link
Contributor

@ppalaga ppalaga left a comment

Choose a reason for hiding this comment

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

A quick review from a train. Will cont in a couple of hours

@ConfigGroup
public interface CustAlgSuite {

public static final String CUSTOMIZED_ALGORITHM_SUITE_NAME = "CustomizedAlgorithmSuite";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static final String CUSTOMIZED_ALGORITHM_SUITE_NAME = "CustomizedAlgorithmSuite";
public static final String CUSTOMIZED_ALGORITHM_SUITE_NAME = "QuarkusCxfFipsAlgorithmSuite";

... so that users have a chance to see where it comes from when they see it in policy files or in some sort of a debug output.

/**
* Parameters for fully customizable algorithm suite.
*/
@WithName("customizedAlgorithmSuite")
Copy link
Contributor

Choose a reason for hiding this comment

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

So this whole alg suite config should be used mostly for fips compliance, right? Then I'd be for the following structure of the configuration:

quarkus.cxf.security.fips.enabled = [true/false] # enables the custome alg. suite
quarkus.cxf.security.fips.algorithm-suite.digest-algorithm = ...
quarkus.cxf.security.fips.algorithm-suite.encryption-algorithm = ...
...

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally created it with fips property, but then I asked @ffang about his opinion. I might have understood or asked wrongly.

The advice was:

I'd use some name like customerizedPolicy and make all parameters configurable, it should be a general solution, so let the end users control everything

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'm thinking of more general than just FIPS context. The underlying specification may stop evolving, but if users can configure all parameters of the AlgorithmSuite to avoid using some cracked/out-dated security algo, this would be awesome. And this flexibility could not only fit FIPS scenairo.

public String digestAlgorithm();

/**
* Encryption Algorithm.
Copy link
Contributor

Choose a reason for hiding this comment

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

Some hint about the possibly values would be nice, e.g. where they are defined?

/**
* Symmetric Key Encryption Algorithm.
*/
@WithDefault("http://www.w3.org/2001/04/xmlenc#kw-aes256")
Copy link
Contributor

Choose a reason for hiding this comment

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

Some hint about the possibly values would be nice, e.g. where they are defined?

public String symmetricKeyEncryptionAlgorithm();

/**
* Asymmetric Key Encryption Algorithm.
Copy link
Contributor

Choose a reason for hiding this comment

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

Some hint about the possibly values would be nice, e.g. where they are defined?

public Integer encryptionDerivedKeyLength();

/**
* Signature Derived Key Length.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Signature Derived Key Length.
* Signature Derived Key Length in <what units?>

public Integer signatureDerivedKeyLength();

/**
* Minimum Symmetric Key Length.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Minimum Symmetric Key Length.
* Minimum Symmetric Key Length in <what units?>

public Integer minimumSymmetricKeyLength();

/**
* Maximum Symmetric Key Length.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Maximum Symmetric Key Length.
* Maximum Symmetric Key Length in <what units?>

public Integer maximumSymmetricKeyLength();

/**
* Minimum Symmetric Key Length.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Minimum Symmetric Key Length.
* Minimum Symmetric Key Length in <what units?>

public Integer minimumAsymmetricKeyLength();

/**
* Maximum Symmetric Key Length.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Maximum Symmetric Key Length.
* Maximum Symmetric Key Length in <what units?>

@JiriOndrusek
Copy link
Contributor Author

@ppalaga thanks for the review, I'll fix all items.

I understand that using Fips in the name of the customAlgSuite would make sense. On the other hand, if user changes attributes for its own purpose, so it won't work on fips (and there will be no FIPS in user's environment), the word FIPS would be misleading

@JiriOndrusek
Copy link
Contributor Author

What about the name QuarkusCxfCustomAlgorithmSuite (instead of suggested QuarkusCxfFipsAlgorithmSuite)?

@ppalaga
Copy link
Contributor

ppalaga commented Jan 18, 2024

Those are all valid proposals, however, after studying the PR in more depth, I am not sure it is a good idea to make it like this. Here is why:

The set of AlgSuites is defined in version 1.2 of the XML Schema for the policy files: http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/ws-securitypolicy-1.2.xsd If you CTRL-F for "7.1 AlgorithmSuite Assertion", you'll see all suites defined in https://github.com/apache/ws-wss4j/blob/master/policy/src/main/java/org/apache/wss4j/policy/model/AlgorithmSuite.java#L41-L200

The policies are used on both server and client side to configure the security and those standardized AlgSuites guarrantee that clients and servers will encrypt/sign the messages in an expected, mutually comprehensible way, across all vendors.

Introducing an AlgSuite that is configurable through an intransparent config of the client or server would break that interoperability. Actually only Quarkus CXF clients and servers could communicate and only those ones whose custom-algorithm-suite is configured in the same way.

Saying that introducing any new AlgSuite would make the policy files non-compliant with the schema would be true, but there is already a precedent that CXF introduced new AlgSuites in response to a CVE: https://coheigea.blogspot.com/2012/04/note-on-cve-2011-1096.html I wonder wheter we should not try the same: Introduce one or more FIPS-compliant AlgSuites to https://github.com/apache/cxf/blob/main/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/custom/DefaultAlgorithmSuiteLoader.java#L74-L114 In that way, the new suites would be at least comprehensible for clients and servers based on CXF.

WDYT?

@ffang
Copy link
Contributor

ffang commented Jan 18, 2024

Those are all valid proposals, however, after studying the PR in more depth, I am not sure it is a good idea to make it like this. Here is why:

The set of AlgSuites is defined in version 1.2 of the XML Schema for the policy files: http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/ws-securitypolicy-1.2.xsd If you CTRL-F for "7.1 AlgorithmSuite Assertion", you'll see all suites defined in https://github.com/apache/ws-wss4j/blob/master/policy/src/main/java/org/apache/wss4j/policy/model/AlgorithmSuite.java#L41-L200

The policies are used on both server and client side to configure the security and those standardized AlgSuites guarrantee that clients and servers will encrypt/sign the messages in an expected, mutually comprehensible way, across all vendors.

Introducing an AlgSuite that is configurable through an intransparent config of the client or server would break that interoperability. Actually only Quarkus CXF clients and servers could communicate and only those ones whose custom-algorithm-suite is configured in the same way.

Saying that introducing any new AlgSuite would make the policy files non-compliant with the schema would be true, but there is already a precedent that CXF introduced new AlgSuites in response to a CVE: https://coheigea.blogspot.com/2012/04/note-on-cve-2011-1096.html I wonder wheter we should not try the same: Introduce one or more FIPS-compliant AlgSuites to https://github.com/apache/cxf/blob/main/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/custom/DefaultAlgorithmSuiteLoader.java#L74-L114 In that way, the new suites would be at least comprehensible for clients and servers based on CXF.

WDYT?

Hi @ppalaga ,

This is a good proposal and I'm actually thinking about the same thing.

Created https://issues.apache.org/jira/browse/CXF-8971 to track this enhancement.

@JiriOndrusek , please feel free to send a PR there!

But probably this PR for quarkus-cxf still stands as don't need to wait for CXF side fix and release, and the quarkus style configuration part could be still reused even with CXF side enhancement.

Thanks!
Freeman

@JiriOndrusek
Copy link
Contributor Author

Hi @ppalaga ,

thanks for the proposal.
To clarify some details. Suggested solution is to move "customization" mechanism into cxf.
If so, we can keep alg suite config parameters (after refactor to fixed ones) to configure such algSuirta via cxf parameters.

@ffang I try to prepare a draft for cxf to fix issue https://issues.apache.org/jira/browse/CXF-8971.

@JiriOndrusek
Copy link
Contributor Author

As I'm thinking about the customizationAlgSuite in Cxf, what about addition of a FIPS approved algSuite among https://github.com/apache/cxf/blob/main/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/custom/DefaultAlgorithmSuiteLoader.java#L74-L114

That would make usage of the suite much easier for the users. I can imagine, that in the future there can servers customized with ALG1 or ALG2 (both works for FIPS). It might be inconvenient for the clients (because every server requires different custom alg). If there is a default fips suite, the usage can be much easier (the customization would still exist, but might not be needed in so many cases)

@ffang
Copy link
Contributor

ffang commented Jan 19, 2024

As I'm thinking about the customizationAlgSuite in Cxf, what about addition of a FIPS approved algSuite among https://github.com/apache/cxf/blob/main/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/custom/DefaultAlgorithmSuiteLoader.java#L74-L114

That would make usage of the suite much easier for the users. I can imagine, that in the future there can servers customized with ALG1 or ALG2 (both works for FIPS). It might be inconvenient for the clients (because every server requires different custom alg). If there is a default fips suite, the usage can be much easier (the customization would still exist, but might not be needed in so many cases)

Hi Jiri,

Yes, the current CXF DefaultAlgorithmSuiteLoader is a good place. You can add a new policy with name "CustomerizedAlgorithmSuite" which has default FIPS compliant paramenters so it can work OOTB with zero configuration, but these parameters should be configurable/overridable from CXF bus properties. I believe you can define new added necessary properties name in org.apache.cxf.ws.security.SecurityConstants class with prefix like "ws-security.policy".

Cheers
Freeman

@ppalaga
Copy link
Contributor

ppalaga commented Jan 19, 2024

Created https://issues.apache.org/jira/browse/CXF-8971 to track this enhancement.

I commented there

@JiriOndrusek
Copy link
Contributor Author

PR for CXF is prepared (apache/cxf#1660). I plan to refactor this PR to leverage this change (only minimum of this PR will stay as is)

@JiriOndrusek
Copy link
Contributor Author

This PR has to be reworked, because the customizableAlgSuite is proposed on the CXF source instead here. See apache/cxf#1660

@JiriOndrusek JiriOndrusek marked this pull request as draft February 6, 2024 15:23
@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch 2 times, most recently from 2ca0337 to 8ed7da7 Compare February 15, 2024 15:33
@JiriOndrusek
Copy link
Contributor Author

@ppalaga I refactored this PR to use a new CXF feature https://issues.apache.org/jira/browse/CXF-8971.

The change brought by this PR is quite small. The custom algorithm suite is created by cxf, therefore I added some configuration properties to make customization easier.

Then I added 4 tests:

  1. server & client uses custom alg suite with default values - works
  2. server & client uses modifies custom alg suite in proper way - works
  3. server modifies alg suite as in previous case & client uses default values - fails
  4. server uses default values & client customizes alg suite in the same way as case 2 - fails

This PR requires new CXF 4.0.4 (whiich upgrades wss4j and santuario-xmlsec)
therefore the CI has to fail (with older cxf)

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from 8ed7da7 to ff2c85e Compare February 15, 2024 15:41
@ppalaga
Copy link
Contributor

ppalaga commented Mar 6, 2024

@JiriOndrusek this PR builds against the staging repo of CXF 4.0.4 that is under vote right now.
Would you like to rebase this PR on top of it?
I'd like to release Quarkus CXF 3.8.1 on Friday once the CXF 4.0.4 artifacts are available on Central.

@JiriOndrusek
Copy link
Contributor Author

@JiriOndrusek this PR builds against the staging repo of CXF 4.0.4 that is under vote right now. Would you like to rebase this PR on top of it? I'd like to release Quarkus CXF 3.8.1 on Friday once the CXF 4.0.4 artifacts are available on Central.

Thanks for he upgrading PR, I'll look at that and rebase this PR.

@JiriOndrusek
Copy link
Contributor Author

@ppalaga @ffang Is the staging repo working now? I can not download any artifact from it and the url does not work in the browser: https://repository.apache.org/content/repositories/orgapachecxf-1196

@JiriOndrusek
Copy link
Contributor Author

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from ff2c85e to ad7b9d1 Compare March 7, 2024 09:03
@JiriOndrusek
Copy link
Contributor Author

PR is rebased, locally works with staging repo https://repository.apache.org/content/repositories/orgapachecxf-1197/

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from ad7b9d1 to 06eed03 Compare March 7, 2024 13:16
@JiriOndrusek
Copy link
Contributor Author

I switch staging repo to https://repository.apache.org/content/repositories/orgapachecxf-1197/ to make the CI pass (new repo is part of the second voting)

@JiriOndrusek JiriOndrusek force-pushed the customized-alg-suite-defaults-to-fips branch from 06eed03 to 01e327c Compare March 7, 2024 13:28
@ppalaga
Copy link
Contributor

ppalaga commented Mar 8, 2024

Thanks for rabasing, @JiriOndrusek !
I took over you commit to #1274
and added some fixups 78e12a8 - could you please review there?
I'd also add a bit more docs text to the new options.

@ppalaga
Copy link
Contributor

ppalaga commented Mar 11, 2024

Replaced by #1274

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.

Make algorithm suites configurable through application.properties thus allowing FIPS compliant suites
3 participants