LDAP连接在SSL上表现得很奇怪

时间:2017-04-13 10:48:51

标签: java ssl ldap

我正在尝试使用JAVA连接到我的组织的LDAP服务器。我正在使用以下SSLPoke代码来测试连接。

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;

/** Establish a SSL connection to a host and port, writes a byte and
 * prints the response. See
 * http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
 */
public class SSLPoke {
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
            System.exit(1);
        }
        try {
            SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));

            InputStream in = sslsocket.getInputStream();
            OutputStream out = sslsocket.getOutputStream();

            // Write a test byte to get a reaction :)
            out.write(1);

            while (in.available() > 0) {
                System.out.print(in.read());
            }
            System.out.println("Successfully connected");

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

我在我的信任库中导入了LDAP证书。我有时能连接,而在大多数情况下我得到 -

sun.security.validator.ValidatorException: PKIX path building failed: sun.securi
ty.provider.certpath.SunCertPathBuilderException: unable to find valid certifica
tion path to requested target

我尝试在启用SSL调试的情况下运行代码,但我无法识别出错了什么。如果它是证书问题,它根本就没有连接。但是我有时可以在后续尝试后连接。任何帮助将不胜感激。

0 个答案:

没有答案