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

Updates dummyTrustManager to use more supported security protocol #436

Merged
merged 5 commits into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/org/datadog/jmxfetch/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
Expand All @@ -21,6 +22,11 @@ public class HttpClient {
private int port;

private static final String USER_AGENT = "Datadog/JMXFetch";
// Per javadocs, this is the only version that all compliant JVMs are required to support
// I found 'TLS' was the appropriate protocol (will use the latest support TLSv? version)
// rather than specifically 'TLSv1' as the docs recommend
// https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLContext.html
private static final String sslProtocol = System.getProperty("jmxfetch.min_tls_version", "TLS");

public static class HttpResponse {
private int responseCode;
Expand Down Expand Up @@ -76,7 +82,7 @@ public HttpClient(String host, int port, boolean verify) {
new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
return new X509Certificate[0];
}

public void checkClientTrusted(
Expand All @@ -88,10 +94,14 @@ public void checkServerTrusted(
String authType) {}
}
};
sc = SSLContext.getInstance("SSL");
sc = SSLContext.getInstance(sslProtocol);
sc.init(null, this.dummyTrustManager, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
log.info("Successfully installed dummyTrustManager with {}", sslProtocol);
} catch (Exception e) {
log.error("Error installing dummyTrustManager. Communications with the Agent will "
+ "be affected. Agent Status will be unreliable and AutoDiscovery of new "
+ "JMX checks will fail. error: ", e);
log.debug("session token unavailable - not setting");
this.token = "";
}
Expand Down