I am trying to connect to an LDAP server in my Android application and using the UnboundID SDK. Recently, changes have been made with unprotected access to secure LDAP, and I must modify the application accordingly. I was given an SSL certificate file for verification. I already used the file to create the keystore, as described here . I have this keystore file in the folder with the resources of my application, and I was torn from it. The code below does not work and throws an exception:
LDAPException (resultCode = 01 (connection error), errorMessage = ('An error occurred while trying to connect to the server place.myserver.com:636: javax.net.ssl.SSLHandShakeException: java.security.cert.CertPathValidatorException: Chain anchor for the certification path not found.
// code from above link AssetManager assetManager = getApplicationContext().getAssets(); InputStream keyStoreInputStream = assetManager.open("yourapp.store"); KeyStore trustStore = KeyStore.getInstance("BKS"); trustStore.load(keyStoreInputStream, "myPassword".toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); tmf.init(trustStore); // my code SSLUtil sslUtil = new SSLUtil(tmf.getTrustManagers()); LDAPConnection connection = new LDAPConnection(sslUtil.createSSLSocketFactory()); connection.connect("place.myserver.com", 636);
However, the code segment:
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager()); LDAPConnection connection = new LDAPConnection(sslUtil.createSSLSocketFactory()); connection.connect("place.myserver.com", 636);
works (although I was informed above that it would be unsafe). I'm not quite sure what I am doing wrong here, so any help will be appreciated. Also, if there is a better way to do this than what I'm trying to do above, feel free to let me know :) I would like to stick with the UnboundID library, since since the rest of the code is already written using this as well, and everything works if I use TrustAllTrustManager.
source share