繁体   English   中英

Java 7 未使用 TLS 1.2 连接到 LDAPS 服务器

[英]Java 7 does not connect to LDAPS server using TLS 1.2

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

我可以引入几乎任何我可能需要的附加库,但我不能移动到更新版本的 Java。

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

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

-Dhttps.protocols=TLSv1.2 已设置

-Djavax.net.debug=ssl 已设置

-如果我使用 LDAPS Uri 并使用 URL class 进行连接,它会显示 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

根据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 ,其完整限定名称为 class 实现javax.net.SocketFactory

对于 SSL,也许试试sun.security.ssl.SSLSocketFactoryImpl

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM