无法使用任何 TLS 版本的 splunk-java sdk 连接到 splunk
我已按照 这些 示例来连接 splunk使用java-sdk。但我无法使用 此示例。在我的情况下,禁用安全性(提供的连接选项之一)不是一个可行的选择。如果有人成功使用这些选项,我真的很感谢您的帮助。到目前为止我尝试过的Java版本是openjdk 8,11 &17。
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("username");
loginArgs.setPassword("password");
loginArgs.setScheme("https");
loginArgs.setHost("network-splunk-hostname");
loginArgs.setPort(443);
// Create a Service instance and log in with the argument map
//Service service = Service.connect(loginArgs);
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.SSLv3);
Service serviceSSLv3 = Service.connect(loginArgs);
serviceSSLv3.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1 is available by default in every modern version of Java
System.out.println("Now trying to connect to Splunk using TLSv1");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1);
Service serviceTLSv1 = Service.connect(loginArgs);
serviceTLSv1.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1.1 is available by default in Java 7 and up
System.out.println("Now trying to connect to Splunk using TLSv1.1");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_1);
Service serviceTLSv1_1 = Service.connect(loginArgs);
serviceTLSv1_1.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1.2 is available by default in Java 7 and up
System.out.println("Now trying to connect to Splunk using TLSv1.2");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
Service serviceTLSv1_2 = Service.connect(loginArgs);
serviceTLSv1_2.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// You can also specify your own SSLSocketFactory, in this case any version of SSL
System.out.println("Now trying to connect to Splunk using a custom SSL only SSLSocketFactory");
try {
// Create an SSLSocketFactory configured to use SSL only
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManager[] byPassTrustManagers = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
};
sslContext.init(null, byPassTrustManagers, new SecureRandom());
SSLSocketFactory SSLOnlySSLFactory = sslContext.getSocketFactory();
Service.setSSLSocketFactory(SSLOnlySSLFactory);
Service serviceCustomSSLFactory = Service.connect(loginArgs);
serviceCustomSSLFactory.login();
System.out.println("\t Success!");
} catch (Exception e) {
System.out.println("\t Failure!");
}
// You can also specify your own SSLSocketFactory, in this case any version of TLS
System.out.println("Now trying to connect to Splunk using a custom TLS only SSLSocketFactory");
try {
// Create an SSLSocketFactory configured to use TLS only
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManager[] byPassTrustManagers = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
};
sslContext.init(null, byPassTrustManagers, new SecureRandom());
SSLSocketFactory TLSOnlySSLFactory = sslContext.getSocketFactory();
Service.setSSLSocketFactory(TLSOnlySSLFactory);
Service serviceCustomSSLFactory = Service.connect(loginArgs);
serviceCustomSSLFactory.login();
System.out.println("\t Success!");
} catch (Exception e) {
System.out.println("\t Failure!");
}
输出是:
失败!
现在尝试使用 TLSv1 连接到 Splunk 失败!
现在尝试使用 TLSv1.1 连接到 Splunk 失败!
现在尝试使用 TLSv1.2 连接到 Splunk 失败!
现在尝试使用仅自定义 SSL SSLSocketFactory 连接到 Splunk 失败!
现在尝试使用仅自定义 TLS SSLSocketFactory 连接到 Splunk 失败!
I have followed these examples to connect splunk using java-sdk. But I am unable to connect using any of TLS versions shown in this example. Disabling the security (one of the option provided to connect) is not a viable option in my case. I really appreciate help with this if someone succeeded using these options. Java versions I have tried so far are openjdk 8,11 &17.
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("username");
loginArgs.setPassword("password");
loginArgs.setScheme("https");
loginArgs.setHost("network-splunk-hostname");
loginArgs.setPort(443);
// Create a Service instance and log in with the argument map
//Service service = Service.connect(loginArgs);
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.SSLv3);
Service serviceSSLv3 = Service.connect(loginArgs);
serviceSSLv3.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1 is available by default in every modern version of Java
System.out.println("Now trying to connect to Splunk using TLSv1");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1);
Service serviceTLSv1 = Service.connect(loginArgs);
serviceTLSv1.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1.1 is available by default in Java 7 and up
System.out.println("Now trying to connect to Splunk using TLSv1.1");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_1);
Service serviceTLSv1_1 = Service.connect(loginArgs);
serviceTLSv1_1.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// TLSv1.2 is available by default in Java 7 and up
System.out.println("Now trying to connect to Splunk using TLSv1.2");
try {
Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
Service serviceTLSv1_2 = Service.connect(loginArgs);
serviceTLSv1_2.login();
System.out.println("\t Success!");
} catch (RuntimeException e) {
System.out.println("\t Failure! ");
}
// You can also specify your own SSLSocketFactory, in this case any version of SSL
System.out.println("Now trying to connect to Splunk using a custom SSL only SSLSocketFactory");
try {
// Create an SSLSocketFactory configured to use SSL only
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManager[] byPassTrustManagers = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
};
sslContext.init(null, byPassTrustManagers, new SecureRandom());
SSLSocketFactory SSLOnlySSLFactory = sslContext.getSocketFactory();
Service.setSSLSocketFactory(SSLOnlySSLFactory);
Service serviceCustomSSLFactory = Service.connect(loginArgs);
serviceCustomSSLFactory.login();
System.out.println("\t Success!");
} catch (Exception e) {
System.out.println("\t Failure!");
}
// You can also specify your own SSLSocketFactory, in this case any version of TLS
System.out.println("Now trying to connect to Splunk using a custom TLS only SSLSocketFactory");
try {
// Create an SSLSocketFactory configured to use TLS only
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManager[] byPassTrustManagers = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
};
sslContext.init(null, byPassTrustManagers, new SecureRandom());
SSLSocketFactory TLSOnlySSLFactory = sslContext.getSocketFactory();
Service.setSSLSocketFactory(TLSOnlySSLFactory);
Service serviceCustomSSLFactory = Service.connect(loginArgs);
serviceCustomSSLFactory.login();
System.out.println("\t Success!");
} catch (Exception e) {
System.out.println("\t Failure!");
}
And the output is:
Failure!
Now trying to connect to Splunk using TLSv1
Failure!
Now trying to connect to Splunk using TLSv1.1
Failure!
Now trying to connect to Splunk using TLSv1.2
Failure!
Now trying to connect to Splunk using a custom SSL only SSLSocketFactory
Failure!
Now trying to connect to Splunk using a custom TLS only SSLSocketFactory
Failure!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论