【问题标题】:Java 7 does not connect to LDAPS server using TLS 1.2Java 7 不使用 TLS 1.2 连接到 LDAPS 服务器
【发布时间】:2021-11-25 18:19:05
【问题描述】:

尝试使用 Java 7u25 连接到使用 TLSv1.2 的 LDAPS 服务器。到目前为止,所有连接都是使用 TLSv1 启动的。在这个确切的时刻,我什至不关心身份验证或运行搜索。我只想在正确的级别完成握手。

我几乎可以引入我可能需要的任何其他库,但我无法迁移到更新版本的 Java。

我已经看到了很多关于确保入站连接与 TLSv1.2 一起工作的问题,而且工作正常。我见过其他关于确保 Java OUTBOUND 连接使用 TLSv1.2 的问题,但它们似乎都与 URL 类有关。

编辑 1 Djdk.tls.client.protocols=TLSv1.2 在我必须使用的版本中不可用。

-Dhttps.protocols=TLSv1.2 已设置

-Djavax.net.debug=ssl 已设置

-如果我使用 LDAPS Uri 并使用 URL 类进行连接,它确实会显示 TLSv1.2 协商。

部分片段

// set the LDAP connection properties
        String dsLocation = httpRequest.getParameter("location");
        String userId = httpRequest.getParameter("userId");
        String pwd = httpRequest.getParameter("pwd");
        String encrypted = httpRequest.getParameter("encrypted");
        Properties LDAPOptions = new Properties();

            LDAPOptions.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
            LDAPOptions.put(Context.SECURITY_PROTOCOL, "ssl");
            

            // check for anonymous binds
            if (userId == null || userId.isEmpty()) {
                LDAPOptions.put(Context.SECURITY_AUTHENTICATION, "none");
            }
            else {
                LDAPOptions.put(Context.SECURITY_AUTHENTICATION, "simple");
                LDAPOptions.put(Context.SECURITY_PRINCIPAL, userId);
                LDAPOptions.put(Context.SECURITY_CREDENTIALS, pwd);
            }
                       
            LDAPOptions.put(Context.PROVIDER_URL, dsLocation);

            LdapContext ctx = null;

            try {
                // try to connect
                ctx = new InitialLdapContext(LDAPOptions, null);                
                connected = true;
                result = "success";
                ctx.reconnect(null);
                
            }
            catch (AuthenticationException aex) {
                result = "invalid credentials";
            }
            finally {
                if (ctx != null) {
                    ctx.close();
                }
            }

SSL 调试输出

<ignore a bunch of cipher suites>
[Oct 4, 2021 8:44:54 PM ]: Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
[Oct 4, 2021 8:44:54 PM ]: %% No cached client session
[Oct 4, 2021 8:44:54 PM ]: *** ClientHello, TLSv1
<redacted>
[Oct 4, 2021 8:44:54 PM ]: ajp-bio-8009-exec-2, WRITE: TLSv1 Handshake, length = 169
[Oct 4, 2021 8:44:54 PM ]: ajp-bio-8009-exec-2, READ: TLSv1 Handshake, length = 1970

【问题讨论】:

    标签: java ldap tls1.2


    【解决方案1】:

    根据https://www.baeldung.com/java-7-tls-v12,需要Java 1.7.0_95或更高版本才能使用-Djdk.tls.client.protocols=TLSv1.2

    还有一些关于如何创建 TLS1.2 套接字的信息。这不是你会做的,但这就是在com.sun.jndi.ldap.Connection.createSocket()内部完成的方式@

    您会在此处看到,您可以提供 LdapCtx.SOCKET_FACTORY 以及实现 javax.net.SocketFactory 的类的完整限定名。

    对于 SSL,不妨试试sun.security.ssl.SSLSocketFactoryImpl

    如果这还不够,那么值得在 DEBUG 中尝试,在 createSocket() 中设置一些断点(我没有 Java 7 来进行测试)。

    【讨论】:

    • 正确,除非我更新到 u95,否则无法使用该客户端设置,这不是入门。我正在查看您使用替代套接字工厂的建议(假设我能弄清楚如何)
    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2015-12-04
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    相关资源
    最近更新 更多