1

I am trying to establish an LDAPS connection just like explained in the unboundid documentation here

Setting up the server

val config = new InMemoryDirectoryServerConfig("dc=org")
val sslUtilServer = new SSLUtil(new KeyStoreKeyManager("/path/mycert.pfx", "foo".toCharArray, "PKCS12", "server-cert"), null )
val listenerConfig = InMemoryListenerConfig.createLDAPSConfig("test", InetAddress.getByName("localhost"), 12345, sslUtilServer.createSSLServerSocketFactory(), null)
config.setListenerConfigs(listenerConfig)

config.addAdditionalBindCredentials("dn=foo", "bar")

val server = new InMemoryDirectoryServer(config)
server.startListening()

Establishing the connection:

val c = server.getConnection("test")
c.connect("localhost", 12345)
c.bind("dn=foo", "bar")

After the bind method I get this exception:

com.unboundid.ldap.sdk.LDAPException: An error occurred while attempting to send the LDAP message to server localhost:12345:  javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
  at com.unboundid.ldap.sdk.LDAPConnectionInternals.sendMessage(LDAPConnectionInternals.java:556)
  at com.unboundid.ldap.sdk.LDAPConnection.sendMessage(LDAPConnection.java:4254)
  at com.unboundid.ldap.sdk.SimpleBindRequest.process(SimpleBindRequest.java:547)
  at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:2150)
  at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:2095)
...

 Cause: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
  at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1959)
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
  at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
  at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
  at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
  at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
  at com.unboundid.ldap.sdk.LDAPConnectionInternals.sendMessage(LDAPConnectionInternals.java:525)

Using TrustAllTrustManager didn't solve the issue neither:

val sslUtil = new SSLUtil(new TrustAllTrustManager())
val socketFactory = sslUtil.createSSLSocketFactory()
val ldap = new LDAPConnection(socketFactory)
ldap.connect("localhost", 12345)
ldap.bind("dn=foo", "bar")

Can anyone help please ?

EDIT found the answer here

user1395775
  • 11
  • 1
  • 3
  • This should help: http://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate-with-a-java-httpsurlconnection/859271#859271 – Rado Buransky Jan 04 '15 at 18:10

0 Answers0