Repository navigation
Conversation
d917629 to
c1d3cb3
Compare
A key store can hold more than one certificate for a host. For example, a Windows-MY store populated by AD CS autoenrollment may contain both a TLS server certificate and a client authentication certificate. When no key alias was configured, automatic selection used the first key entry regardless of its key usage and could pick a certificate that is not valid for TLS server authentication. When no certificateKeyAlias is configured, skip key entries whose certificate is not valid for TLS server authentication. A certificate qualifies if its Extended Key Usage includes serverAuth or anyExtendedKeyUsage, or if it has no Extended Key Usage extension. A malformed Extended Key Usage is treated as not valid and ignored. If no eligible key entry is found, connector initialization fails. A configured certificateKeyAlias is always used unchanged, even if its certificate is not valid for server authentication.
c1d3cb3 to
a87c327
Compare
markt-asf
left a comment
There was a problem hiding this comment.
This PR appears to be missing some key points.
The Java KeyStore API assumes that aliases are unique. The original problem was related to multiple keys of different types with the same alias.
It looks like for current versions of Java (including latest 8) those duplicate aliases get a number appended to the end:
- alias
- alias (1)
- alias (2)
We need to handle this when looking for alias and checking the EKU value.
@markt-asf I have been thinking on how to resolve this, but no idea seems concise enough to implement. I am considering the scenario where:
so treating aliases only by their number suffix is not an option. Running on debug I noticed that the original alias is available, but KeyStore.keyStoreSpi is private.
I've looked around openjdk source code and resulted in sending the following email. It's noteworthy that, per https://bugs.openjdk.org/browse/JDK-8187634, it seems there is a mismatch on what getCertificateAlias returns before and after java 23. |
|
Thanks for looking into this in more depth. I agree this needs to be fixed on the JRE side. The proper fix looks like it would need a breaking API change. As much as it pains me to hack a solution, we do have a user with a genuine issue. How about the following approach:
It isn't perfect. Aliases genuinely ending in (1) are going to conflict but is that very likely? And it does solve the problem reported on users@ (at least I think it does). WDYT? |
I implemented this behavior, but limited it only for SunMSCAPI provider. Documented also the reason behind this decision. |
|
Openjdk tracker for reference: https://bugs.openjdk.org/browse/JDK-8395755 |
fbf9f88 to
6f4accf
Compare
|
@markt-asf I've reworked the branch and I would appreciate your input on this. As discussed, for a SunMSCAPI Windows-MY store, when the configured I noticed that there were other places that this change affected, and tried to address them. |
When a Certificate is configured from a key store and no certificateKeyAlias
is set, ignore key entries whose certificate is not valid for TLS server
authentication when automatically selecting the key to use. A configured
certificateKeyAlias is used even if its certificate is not valid, except in a
Windows-MY key store accessed through the SunMSCAPI provider: there, if the
configured certificate is not valid but a numbered duplicate of the alias
("alias (1)", "alias (2)", ...) carries a valid one, the duplicate is used
instead - including when the configured alias is a keyless (trusted) entry,
and continuing past gaps in the numbering.
The configured certificateKeyAlias can differ from the certificate actually served once the SunMSCAPI Windows-MY numbered-duplicate resolution has selected a different alias. Consumers that looked the certificate up by the configured alias therefore reported or monitored the wrong certificate.
6f4accf to
11adba4
Compare
markt-asf
left a comment
There was a problem hiding this comment.
I think this is heading in the right direction. A couple of minor comments I'd recommend addressing before merging.
…09 certs are accepted.
…d, so Tomcat cannot reliably predict which alias a handshake will serve: the socket-based chooseServerAlias callback used elsewhere to probe the served alias may disagree with the chooseEngineServerAlias callback that an SSLEngine handshake actually uses. The alias the operator configured is therefore the only dependable answer for certificate monitoring.
|
@markt-asf I have addressed the issues raised and others discovered. I would appreciate your review on these again. If that looks good, I will also commit the test keys/certs to the svn repo. |

No description provided.