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

Support certs with separate Extended Key Usage #493

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

lavacat
Copy link
Contributor

@lavacat lavacat commented Jun 4, 2020

Problem: Right now certs that specify extended key usage must set
both clientAuth and serverAuth.

Solution: Add settings to path additional server cert and use it when
creating ssl server

*Issue #474 *

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@lavacat lavacat requested a review from a team as a code owner June 4, 2020 19:24
@lavacat lavacat changed the title Support certs with separate Extended Key Usage WIP: Support certs with separate Extended Key Usage Jun 4, 2020
@vrozov
Copy link
Contributor

vrozov commented Jun 5, 2020

@lavacat Please check why CI build failed

@@ -17,6 +17,7 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently the changes made are only for PEM certs. Since we support jks certs as well, we will probably need to extend these changes to include JKS certs (link)

SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT);
// certificate allows clientAuth and serverAuth, use same cert
SSLCertificateProps sslServerCertProps = sslCertProps;
if (!mixedKeyUsageEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight confused by mixedKeyUsageEnabled. Does that mean the cert has both clientAuth and serverAuth?

@@ -258,7 +258,7 @@ protected NodeSettingsSupplier minimumSecuritySettingsSslOnly(Settings other) {
return new NodeSettingsSupplier() {
@Override
public Settings get(int i) {
return minimumSecuritySettingsBuilder(i, true, false).put(other).build();
return minimumSecuritySettingsBuilder(i, true, true).put(other).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why update this from true to false? It is set to false by default so that custom transport settings are used.

@@ -329,6 +329,12 @@ public Object run() {
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PEMKEY_PASSWORD, Property.NodeScope, Property.Filtered));
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PEMTRUSTEDCAS_FILEPATH, Property.NodeScope, Property.Filtered));

settings.add(Setting.boolSetting(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT, Property.NodeScope, Property.Filtered));
Copy link
Contributor

Choose a reason for hiding this comment

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

it may be good to disable these settings if mixedKeyUsage is false. Eg -

Suggested change
settings.add(Setting.boolSetting(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED_DEFAULT, Property.NodeScope, Property.Filtered));
if (!isMixedKeyUsageAllowed(settings)) {
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMCERT_FILEPATH, Property.NodeScope, Property.Filtered));
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMKEY_FILEPATH, Property.NodeScope, Property.Filtered));
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMKEY_PASSWORD, Property.NodeScope, Property.Filtered));
settings.add(Setting.simpleString(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_SERVER_PEMTRUSTEDCAS_FILEPATH, Property.NodeScope, Property.Filtered));
}

You can create a helper function like -

    private static boolean isMixedKeyUsageAllowed(final Settings settings) {
        return settings.getAsBoolean(SSLConfigConstants. OPENDISTRO_SECURITY_SSL_TRANSPORT_MIXED_KEY_USAGE_ENABLED, false);
    }

@lavacat
Copy link
Contributor Author

lavacat commented Aug 31, 2020

@debjanibnrj Thanks for comments. I'll resume working on this.

  • will add JKS cert support
  • mixedKeyUsageEnabled means both clientAuth and serverAuth, if it's confusing, happy to use some other name
  • agree with having .server. and .client. and defaulting to old way. Will refactor

@codecov
Copy link

codecov bot commented Oct 12, 2020

Codecov Report

Merging #493 (0c1aefb) into master (8419ab5) will increase coverage by 0.36%.
The diff coverage is 90.43%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #493      +/-   ##
============================================
+ Coverage     63.91%   64.27%   +0.36%     
- Complexity     3169     3210      +41     
============================================
  Files           239      244       +5     
  Lines         16882    17040     +158     
  Branches       3036     3034       -2     
============================================
+ Hits          10790    10953     +163     
+ Misses         4543     4541       -2     
+ Partials       1549     1546       -3     
Impacted Files Coverage Δ Complexity Δ
...icsearch/security/ssl/util/SSLConfigConstants.java 77.77% <ø> (ø) 7.00 <0.00> (ø)
...istroforelasticsearch/security/ssl/util/Utils.java 63.63% <0.00%> (-6.37%) 5.00 <1.00> (+1.00) ⬇️
...elasticsearch/security/ssl/util/KeystoreProps.java 72.72% <72.72%> (ø) 2.00 <2.00> (?)
...sticsearch/security/ssl/util/CertFromKeystore.java 73.91% <73.91%> (ø) 8.00 <8.00> (?)
...icsearch/security/ssl/util/CertFromTruststore.java 90.90% <90.90%> (ø) 8.00 <8.00> (?)
...ecurity/ssl/DefaultOpenDistroSecurityKeyStore.java 69.10% <94.38%> (+3.20%) 71.00 <10.00> (+3.00)
...arch/security/ssl/OpenDistroSecuritySSLPlugin.java 84.44% <100.00%> (+1.83%) 25.00 <0.00> (+1.00)
...elasticsearch/security/ssl/util/CertFileProps.java 100.00% <100.00%> (ø) 5.00 <5.00> (?)
...relasticsearch/security/ssl/util/CertFromFile.java 100.00% <100.00%> (ø) 13.00 <13.00> (?)
...relasticsearch/security/auditlog/NullAuditLog.java 33.33% <0.00%> (-4.77%) 7.00% <0.00%> (-1.00%)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8419ab5...3e54769. Read the comment docs.

@lavacat lavacat requested a review from debjanibnrj October 12, 2020 19:24
nicot
nicot previously approved these changes Oct 12, 2020
Copy link
Contributor

@nicot nicot left a comment

Choose a reason for hiding this comment

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

Looks great to me! Thanks for making these changes.

@@ -0,0 +1,22 @@
# Commands to generate certs in this folder
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this!

@lavacat lavacat changed the title WIP: Support certs with separate Extended Key Usage Support certs with separate Extended Key Usage Oct 21, 2020

} else if (rawPemCertFilePath != null || extendedKeyUsageEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add || extendedKeyUsageEnabled here?

KeystoreProps truststoreProps = new KeystoreProps(
truststoreFilePath, truststoreType, truststorePassword);
try {
CertFromKeystore certFromKeystore;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for refactoring these into classes. Much cleaner approach. 👍

@lavacat
Copy link
Contributor Author

lavacat commented Nov 20, 2020

@nicot @debjanibnrj

  • added keystore, truststore files and integration test in SSLTest.java
  • added unit tests for all new CertFrom* classes
  • cleaned up imports

@debjanibnrj based on your question "Why add || extendedKeyUsageEnabled here?"
did a small refactor and added cleaner useKeyStore and useRawFiles variables

Nothing else changed

debjanibnrj
debjanibnrj previously approved these changes Nov 20, 2020
Copy link
Contributor

@debjanibnrj debjanibnrj left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. Added a minor comment but overall looks great!

nicot
nicot previously approved these changes Nov 20, 2020
@debjanibnrj
Copy link
Contributor

@hardik-k-shah can you have a look as well

@lavacat
Copy link
Contributor Author

lavacat commented Nov 23, 2020

Thanks for your contribution. Added a minor comment but overall looks great!

@debjanibnrj FYI, don't see the new comments. I think I've addressed all older ones.

Copy link
Member

@hardik-k-shah hardik-k-shah left a comment

Choose a reason for hiding this comment

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

Thanks @lavacat and @nicot for your contribution.
Overall it looks good. Few minor comments.

null);
final String keyPassword = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_KEYSTORE_KEYPASSWORD,
keystorePassword);

Copy link
Member

Choose a reason for hiding this comment

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

should we also check truststoreAlias and keystoreAlias for non-null and throw exception if anyone of it was set to null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the alias isn't provided SSLCertificateHelper.exportServerCertChain will take the first one. I've made it required for extended key usage because server/client alias should be different at least for keystore.
Made a comment and added a test

@lavacat
Copy link
Contributor Author

lavacat commented Nov 25, 2020

@debjanibnrj @hardik-k-shah thanks for comments and noticing those mistakes, made all changes as you've suggested.

Problem: Right now certs that specify extended key usage must set
both clientAuth and serverAuth.

Solution: Add settings to path additional server cert and use it when
creating ssl server
@hardik-k-shah hardik-k-shah merged commit 721e7e2 into opensearch-project:master Dec 1, 2020
@vrozov vrozov added the enhancement New feature or request label Dec 1, 2020
lbreinig pushed a commit to lbreinig/security that referenced this pull request Dec 23, 2021
Problem: Right now certs that specify extended key usage must set
both clientAuth and serverAuth.

Solution: Add settings to path additional server cert and use it when
creating ssl server

Co-authored-by: Bogdan Kanivets <bkanivets@twitter.com>
wuychn pushed a commit to ochprince/security that referenced this pull request Mar 16, 2023
Problem: Right now certs that specify extended key usage must set
both clientAuth and serverAuth.

Solution: Add settings to path additional server cert and use it when
creating ssl server

Co-authored-by: Bogdan Kanivets <bkanivets@twitter.com>
gaobinlong pushed a commit to gaobinlong/security that referenced this pull request Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants