无法使用任何 TLS 版本的 splunk-java sdk 连接到 splunk

发布于 2025-01-14 13:39:15 字数 5175 浏览 0 评论 0原文

我已按照 这些 示例来连接 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文