【发布时间】: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
【问题讨论】: