Skip to content

Add a certificateSelectByKeyUsage attribute for JSSE - #1089

Open
dsoumis wants to merge 5 commits into
apache:mainfrom
dsoumis:cert-select-by-key-usage
Open

dsoumis wants to merge 5 commits into
apache:mainfrom
dsoumis:cert-select-by-key-usage

Conversation

@dsoumis

@dsoumis dsoumis commented Oct 16, 2026

Copy link
Copy Markdown
Member

No description provided.

@fabian-hahn

Copy link
Copy Markdown

Shouldn't certificateSelectByKeyUsage="true" be the default behavior?

@ChristopherSchultz

Copy link
Copy Markdown
Contributor

Shouldn't certificateSelectByKeyUsage="true" be the default behavior?

No: we do not want to change the default behavior at the moment. We may change the default behavior in Tomcat 12 but we do not want to change it in older versions.

@ChristopherSchultz

Copy link
Copy Markdown
Contributor

@dsoumis I think maybe this would be better if it were:

  1. Always ignoring incompatible key usages
  2. Only failing after all certificates matching aliases (from a PEM file, where alias == DN) fail

@dsoumis
dsoumis marked this pull request as draft October 17, 2026 16:01
@markt-asf

Copy link
Copy Markdown
Contributor

I'd be happy ignoring any certificate we know (e.g. because of key usage) we can't use. Other than that, I'm not sure any changes are required here.

@christophvw

Copy link
Copy Markdown

Can you check for outdated certificates as well here? Perhaps choose the one with the longest remaining validity, or at least avoid any that have expired

@ChristopherSchultz

Copy link
Copy Markdown
Contributor

Can you check for outdated certificates as well here? Perhaps choose the one with the longest remaining validity, or at least avoid any that have expired

I think we should not skip expired certificates unless there is an equivalent one with the same DN. We should not be preventing the server from starting if there is only an expired certificate to serve. It's the client's responsibility to decide whether or not to trust an expired certificate.

@dsoumis

dsoumis commented Oct 19, 2026

Copy link
Copy Markdown
Member Author
  1. Only failing after all certificates matching aliases (from a PEM file, where alias == DN) fail

@ChristopherSchultz I have some second thoughts on the above before committing an implementation.

Considering the following example:

Keystore with entries:

  1. app.example.com CN=app.example.com serverAuth | key not readable
  2. app.example.com (1) CN=app.example.com serverAuth | key readable

Both are valid candidates, the first is tried, it fails, so selection falls through to the second entry and TLS stays up.

However, the above may mask a misconfiguration from my point of view. It keeps a client up on a possibly soon-to-expire cert instead of failing loudly so the client can fix the key.

@dsoumis

dsoumis commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

Can you check for outdated certificates as well here? Perhaps choose the one with the longest remaining validity, or at least avoid any that have expired

I also don't think we should skip expired certs.
Client may use https://tomcat.apache.org/tomcat-11.0-doc/api/org/apache/catalina/security/TLSCertificateReloadListener.html to monitor the expiration dates of TLS certificates and trigger automatic reloading of the TLS configuration.

@christophvw

Copy link
Copy Markdown

Can you check for outdated certificates as well here? Perhaps choose the one with the longest remaining validity, or at least avoid any that have expired

I think we should not skip expired certificates unless there is an equivalent one with the same DN. We should not be preventing the server from starting if there is only an expired certificate to serve. It's the client's responsibility to decide whether or not to trust an expired certificate.

good point. But choosing the one with the longest remaining validity would be good. Certs skipped because of missing read permissions for the private key should be logged otherwise people will change the tomcat service to Local System again instead of setting proper key permissions.

@christophvw

Copy link
Copy Markdown

Client may use https://tomcat.apache.org/tomcat-11.0-doc/api/org/apache/catalina/security/TLSCertificateReloadListener.html to monitor the expiration dates of TLS certificates and trigger automatic reloading of the TLS configuration.

Oh, nice - didn't know that.
Looks like the https://tomcat.apache.org/tomcat-11.0-doc/ssl-howto.html should get an update how to use the windows keystore and this listener to fully automate certificate handling on windows.

@dsoumis
dsoumis marked this pull request as ready for review October 19, 2026 22:33
Comment thread webapps/docs/ssl-howto.xml Outdated

@christophvw christophvw 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.

Java versions before 17.017 and 21.0.9 cannot open the Windows local computer keystore without elevated permissions.

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.

5 participants