-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add KeyUsage, ExtendedKeyUsage, CipherSuite & Protocol to SSL diagnos… #65634
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
Changes from 2 commits
88ecbd0
f6af049
a7c6be0
3752caf
e23a504
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,8 @@ | |||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||
| import java.util.Optional; | ||||||||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||
| import java.util.stream.IntStream; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public class SslDiagnostics { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -151,6 +153,30 @@ boolean isSameCertificate() { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public enum ExtendedKeyUsage { | ||||||||||||||||||||||||||
| serverAuth ("1.3.6.1.5.5.7.3.1"), | ||||||||||||||||||||||||||
| clientAuth ("1.3.6.1.5.5.7.3.2"), | ||||||||||||||||||||||||||
| codeSigning ("1.3.6.1.5.5.7.3.3"), | ||||||||||||||||||||||||||
| emailProtection ("1.3.6.1.5.5.7.3.4"), | ||||||||||||||||||||||||||
| timeStamping ("1.3.6.1.5.5.7.3.8"), | ||||||||||||||||||||||||||
| ocspSigning ("1.3.6.1.5.5.7.3.9"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private String oid; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private ExtendedKeyUsage(String oid) { | ||||||||||||||||||||||||||
| this.oid = oid; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public static String decodeOid(String oid) { | ||||||||||||||||||||||||||
| for (ExtendedKeyUsage e : values()) { | ||||||||||||||||||||||||||
| if (e.oid != null && e.oid.equals(oid)) { | ||||||||||||||||||||||||||
| return e.name(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return oid; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * @param contextName The descriptive name of this SSL context (e.g. "xpack.security.transport.ssl") | ||||||||||||||||||||||||||
| * @param trustedIssuers A Map of DN to Certificate, for the issuers that were trusted in the context in which this failure occurred | ||||||||||||||||||||||||||
|
|
@@ -177,8 +203,14 @@ public static String getTrustDiagnosticFailure(X509Certificate[] chain, PeerType | |||||||||||||||||||||||||
| .append(peerType.name().toLowerCase(Locale.ROOT)) | ||||||||||||||||||||||||||
| .append(" provided a certificate with subject name [") | ||||||||||||||||||||||||||
| .append(peerCert.getSubjectX500Principal().getName()) | ||||||||||||||||||||||||||
| .append("] and ") | ||||||||||||||||||||||||||
| .append(fingerprintDescription(peerCert)); | ||||||||||||||||||||||||||
| .append("], ") | ||||||||||||||||||||||||||
| .append(fingerprintDescription(peerCert)) | ||||||||||||||||||||||||||
| .append(", ") | ||||||||||||||||||||||||||
| .append(keyUsageDescription(peerCert)) | ||||||||||||||||||||||||||
| .append(" and ") | ||||||||||||||||||||||||||
| .append(extendedKeyUsageDescription(peerCert)); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| addSessionDescription(session, message); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (peerType == PeerType.SERVER) { | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
|
|
@@ -406,4 +438,58 @@ private static boolean checkIssuer(X509Certificate certificate, X509Certificate | |||||||||||||||||||||||||
| private static boolean isSelfIssued(X509Certificate certificate) { | ||||||||||||||||||||||||||
| return certificate.getIssuerX500Principal().equals(certificate.getSubjectX500Principal()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private static String keyUsageDescription(X509Certificate certificate) { | ||||||||||||||||||||||||||
| boolean[] keyUsage = certificate.getKeyUsage(); | ||||||||||||||||||||||||||
| if (keyUsage == null || keyUsage.length == 0) { | ||||||||||||||||||||||||||
| return "no keyUsage"; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| final String[] keyUsageGlossary = {"digitalSignature", "nonRepudiation", "keyEncipherment", | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| "dataEncipherment", "keyAgreement", "keyCertSign", "cRLSign", "encipherOnly", | ||||||||||||||||||||||||||
| "decipherOnly"}; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| List<String> keyUsageDescription = new ArrayList<>(); | ||||||||||||||||||||||||||
| IntStream.range(0, keyUsage.length).forEach(i -> { | ||||||||||||||||||||||||||
| if (keyUsage[i]) { | ||||||||||||||||||||||||||
| keyUsageDescription.add(keyUsageGlossary[i]); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| return keyUsageDescription.stream() | ||||||||||||||||||||||||||
| .reduce((a, b) -> a + ", " + b) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| List<String> keyUsageDescription = new ArrayList<>(); | |
| IntStream.range(0, keyUsage.length).forEach(i -> { | |
| if (keyUsage[i]) { | |
| keyUsageDescription.add(keyUsageGlossary[i]); | |
| } | |
| }); | |
| return keyUsageDescription.stream() | |
| .reduce((a, b) -> a + ", " + b) | |
| String keyUsageDescription = IntStream.range(0, keyUsage.length) | |
| .filter(i -> keyUsage[i]) | |
| .map(i -> i < keyUsageGlossary.length ? keyUsageGlossary[i] : "#" + i) | |
| .collect(Collectors.joining(", ")); |
And then tested whether that was empty or not.
tvernum marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| message.append("; the session supports cipher suite [") | |
| message.append("; the session uses cipher suite [") |
Strictly, by the time we get to a session being established it's not really "supports", it's "has selected for use"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.oidcan never be null, because this is an enum with fixed (non-null) values.I think it's fine to skip the null check here.
If you'd prefer to be safe, you could use
this.oid = Objects.requireNonNull(oid);in the constructor.