You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Christos Papoulas <pa...@gmail.com> on 2016/06/08 11:43:05 UTC
pass certificate to LdapConnectionConfig
Hello list,
Is it possible to pass a certificate file like ssl-cert.pem to the
LdapConnectionConfig? My sample code right now is:
public static LdapConnection createConnection(String host, int port,
String user, String pass, boolean useSSL, boolean useSSLv3)
throws IOException, LdapException {
LdapConnectionConfig connectionConfig = new
LdapConnectionConfig();
if (host == null || host.isEmpty()) {
throw new IllegalArgumentException("Hostname is not
specified");
}
if(port <= 0) {
throw new IllegalArgumentException("The ldap port is not
valid");
}
connectionConfig.setLdapHost(host);
connectionConfig.setLdapPort(port);
if(user!= null && user.length() > 0) {
connectionConfig.setName(user);
}
if(pass != null && pass.length() > 0) {
connectionConfig.setCredentials(pass);
}
if(useSSL == true) {
connectionConfig.setUseSsl(true);
}
if(useSSLv3 == true) {
connectionConfig.setSslProtocol("SSLv3");
}
LdapConnection connection = new
LdapNetworkConnection(connectionConfig);
connection.connect();
connection.bind();
return connection;
}
Re: pass certificate to LdapConnectionConfig
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 08/06/16 � 16:36, Christos Papoulas a �crit :
> After a lot of research, I didn't find out how can I change the
> X509KeyManager and tell LdapConnectionConfig to use this manager.
> Is any hint that you send me for this?
https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#OwnX509TM
Re: pass certificate to LdapConnectionConfig
Posted by Christos Papoulas <pa...@gmail.com>.
After a lot of research, I didn't find out how can I change the
X509KeyManager and tell LdapConnectionConfig to use this manager.
Is any hint that you send me for this?
On 08/06/16 15:32, Kiran Ayyagari wrote:
>
>
> On Wed, Jun 8, 2016 at 5:59 PM, Emmanuel L�charny <elecharny@gmail.com
> <ma...@gmail.com>> wrote:
>
> Le 08/06/16 � 14:21, Christos Papoulas a �crit :
> > On 08/06/16 15:16, Kiran Ayyagari wrote:
> >>
> >>
> >> On Wed, Jun 8, 2016 at 5:41 PM, Christos Papoulas
> >> <pachristos@gmail.com <ma...@gmail.com>
> <mailto:pachristos@gmail.com <ma...@gmail.com>>> wrote:
> >>
> >> I'm trying to connect to my own ldap server with the Apache
> >> Directory LDAP API for
> >> java(http://directory.apache.org/api/downloads.html) and I
> would
> >> like to pass a certificate to that connection. Is it possible?
> >>
> >> the only way to pass certificate is through X509KeyManager
> > Are any tutorials' links or sample code how to do that?
>
> You need to create a TrustManager, and pass it to the
>
> to send a certificate we need to setup KeyManager (TrustManager is to
> verify the server's
> certificate)
>
> LdapConnectionConfig instance :
>
>
> public void connectAndBind() throws Exception
> {
> config = new LdapConnectionConfig();
> config.setLdapHost( "localhost" );
> config.setLdapPort( 10389 );
> config.setName( bindusername );
> config.setCredentials( bindpassword );
>
> TrustManagerFactory tmf = TrustManagerFactory.getInstance(
> TrustManagerFactory.getDefaultAlgorithm() );
> tmf.init( ( KeyStore ) null );
>
> config.setTrustManagers( tmf.getTrustManagers() );
> config.setUseTls( true );
> config.setSslProtocol( "TLSv1" );
> ldapNetworkConnection = new LdapNetworkConnection( config );
>
> connectionStatus = ldapNetworkConnection.connect();
> System.out.println( ( connectionStatus ) ? "Connection
> Established" : "Connection ERROR" );
> ...
>
>
> This is just an example, you will have to tune it to use teh correct
> TrustManager accoringly to the algorithm you want to use, and teh
> KeyStore you want to use.
>
> Kiran Ayyagari
> http://keydap.com
Re: pass certificate to LdapConnectionConfig
Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Jun 8, 2016 at 5:59 PM, Emmanuel Lécharny <el...@gmail.com>
wrote:
> Le 08/06/16 à 14:21, Christos Papoulas a écrit :
> > On 08/06/16 15:16, Kiran Ayyagari wrote:
> >>
> >>
> >> On Wed, Jun 8, 2016 at 5:41 PM, Christos Papoulas
> >> <pachristos@gmail.com <ma...@gmail.com>> wrote:
> >>
> >> I'm trying to connect to my own ldap server with the Apache
> >> Directory LDAP API for
> >> java(http://directory.apache.org/api/downloads.html) and I would
> >> like to pass a certificate to that connection. Is it possible?
> >>
> >> the only way to pass certificate is through X509KeyManager
> > Are any tutorials' links or sample code how to do that?
>
> You need to create a TrustManager, and pass it to the
>
to send a certificate we need to setup KeyManager (TrustManager is to
verify the server's
certificate)
> LdapConnectionConfig instance :
>
>
> public void connectAndBind() throws Exception
> {
> config = new LdapConnectionConfig();
> config.setLdapHost( "localhost" );
> config.setLdapPort( 10389 );
> config.setName( bindusername );
> config.setCredentials( bindpassword );
>
> TrustManagerFactory tmf = TrustManagerFactory.getInstance(
> TrustManagerFactory.getDefaultAlgorithm() );
> tmf.init( ( KeyStore ) null );
>
> config.setTrustManagers( tmf.getTrustManagers() );
> config.setUseTls( true );
> config.setSslProtocol( "TLSv1" );
> ldapNetworkConnection = new LdapNetworkConnection( config );
>
> connectionStatus = ldapNetworkConnection.connect();
> System.out.println( ( connectionStatus ) ? "Connection
> Established" : "Connection ERROR" );
> ...
>
>
> This is just an example, you will have to tune it to use teh correct
> TrustManager accoringly to the algorithm you want to use, and teh
> KeyStore you want to use.
>
Kiran Ayyagari
http://keydap.com
Re: pass certificate to LdapConnectionConfig
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 08/06/16 � 14:21, Christos Papoulas a �crit :
> On 08/06/16 15:16, Kiran Ayyagari wrote:
>>
>>
>> On Wed, Jun 8, 2016 at 5:41 PM, Christos Papoulas
>> <pachristos@gmail.com <ma...@gmail.com>> wrote:
>>
>> I'm trying to connect to my own ldap server with the Apache
>> Directory LDAP API for
>> java(http://directory.apache.org/api/downloads.html) and I would
>> like to pass a certificate to that connection. Is it possible?
>>
>> the only way to pass certificate is through X509KeyManager
> Are any tutorials' links or sample code how to do that?
You need to create a TrustManager, and pass it to the
LdapConnectionConfig instance :
public void connectAndBind() throws Exception
{
config = new LdapConnectionConfig();
config.setLdapHost( "localhost" );
config.setLdapPort( 10389 );
config.setName( bindusername );
config.setCredentials( bindpassword );
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm() );
tmf.init( ( KeyStore ) null );
config.setTrustManagers( tmf.getTrustManagers() );
config.setUseTls( true );
config.setSslProtocol( "TLSv1" );
ldapNetworkConnection = new LdapNetworkConnection( config );
connectionStatus = ldapNetworkConnection.connect();
System.out.println( ( connectionStatus ) ? "Connection
Established" : "Connection ERROR" );
...
This is just an example, you will have to tune it to use teh correct
TrustManager accoringly to the algorithm you want to use, and teh
KeyStore you want to use.
Re: pass certificate to LdapConnectionConfig
Posted by Christos Papoulas <pa...@gmail.com>.
On 08/06/16 15:16, Kiran Ayyagari wrote:
>
>
> On Wed, Jun 8, 2016 at 5:41 PM, Christos Papoulas
> <pachristos@gmail.com <ma...@gmail.com>> wrote:
>
> I'm trying to connect to my own ldap server with the Apache
> Directory LDAP API for
> java(http://directory.apache.org/api/downloads.html) and I would
> like to pass a certificate to that connection. Is it possible?
>
> the only way to pass certificate is through X509KeyManager
Are any tutorials' links or sample code how to do that?
>
>
> Thanks,
>
>
> On 08/06/16 15:03, Kiran Ayyagari wrote:
>>
>>
>> On Wed, Jun 8, 2016 at 5:13 PM, Christos Papoulas
>> <pachristos@gmail.com <ma...@gmail.com>> wrote:
>>
>> Hello list,
>>
>> Is it possible to pass a certificate file like ssl-cert.pem
>> to the LdapConnectionConfig? My sample code right now is:
>>
>> are you connecting to Apache Directory Server? if yes, then
>> certificate based authentication is
>> not supported.
>>
>> If you are connecting to any other server that supports
>> certificate based authentication then
>> you need to set the TrustManager and KeyManager in
>> LdapConnectionConfig
>>
>> public static LdapConnection createConnection(String host,
>> int port,
>> String user, String pass, boolean useSSL, boolean
>> useSSLv3) throws IOException, LdapException {
>> LdapConnectionConfig connectionConfig = new
>> LdapConnectionConfig();
>>
>> if (host == null || host.isEmpty()) {
>> throw new IllegalArgumentException("Hostname is
>> not specified");
>> }
>> if(port <= 0) {
>> throw new IllegalArgumentException("The ldap port
>> is not valid");
>> }
>> connectionConfig.setLdapHost(host);
>> connectionConfig.setLdapPort(port);
>>
>> if(user!= null && user.length() > 0) {
>> connectionConfig.setName(user);
>> }
>> if(pass != null && pass.length() > 0) {
>> connectionConfig.setCredentials(pass);
>> }
>> if(useSSL == true) {
>> connectionConfig.setUseSsl(true);
>> }
>> if(useSSLv3 == true) {
>> connectionConfig.setSslProtocol("SSLv3");
>> }
>> LdapConnection connection = new
>> LdapNetworkConnection(connectionConfig);
>>
>> connection.connect();
>> connection.bind();
>>
>> return connection;
>> }
>>
>> Kiran Ayyagari
>> http://keydap.com
>
> Kiran Ayyagari
> http://keydap.com
Re: pass certificate to LdapConnectionConfig
Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Jun 8, 2016 at 5:41 PM, Christos Papoulas <pa...@gmail.com>
wrote:
> I'm trying to connect to my own ldap server with the Apache Directory LDAP
> API for java(http://directory.apache.org/api/downloads.html) and I would
> like to pass a certificate to that connection. Is it possible?
>
the only way to pass certificate is through X509KeyManager
>
> Thanks,
>
>
> On 08/06/16 15:03, Kiran Ayyagari wrote:
>
>
>
> On Wed, Jun 8, 2016 at 5:13 PM, Christos Papoulas < <pa...@gmail.com>
> pachristos@gmail.com> wrote:
>
>> Hello list,
>>
>> Is it possible to pass a certificate file like ssl-cert.pem to the
>> LdapConnectionConfig? My sample code right now is:
>>
>> are you connecting to Apache Directory Server? if yes, then certificate
> based authentication is
> not supported.
>
> If you are connecting to any other server that supports certificate based
> authentication then
> you need to set the TrustManager and KeyManager in LdapConnectionConfig
>
>> public static LdapConnection createConnection(String host, int port,
>> String user, String pass, boolean useSSL, boolean useSSLv3)
>> throws IOException, LdapException {
>> LdapConnectionConfig connectionConfig = new
>> LdapConnectionConfig();
>>
>> if (host == null || host.isEmpty()) {
>> throw new IllegalArgumentException("Hostname is not
>> specified");
>> }
>> if(port <= 0) {
>> throw new IllegalArgumentException("The ldap port is not
>> valid");
>> }
>> connectionConfig.setLdapHost(host);
>> connectionConfig.setLdapPort(port);
>>
>> if(user!= null && user.length() > 0) {
>> connectionConfig.setName(user);
>> }
>> if(pass != null && pass.length() > 0) {
>> connectionConfig.setCredentials(pass);
>> }
>> if(useSSL == true) {
>> connectionConfig.setUseSsl(true);
>> }
>> if(useSSLv3 == true) {
>> connectionConfig.setSslProtocol("SSLv3");
>> }
>> LdapConnection connection = new
>> LdapNetworkConnection(connectionConfig);
>>
>> connection.connect();
>> connection.bind();
>>
>> return connection;
>> }
>>
> Kiran Ayyagari
> http://keydap.com
>
>
> Kiran Ayyagari
http://keydap.com
Re: pass certificate to LdapConnectionConfig
Posted by Christos Papoulas <pa...@gmail.com>.
I'm trying to connect to my own ldap server with the Apache Directory
LDAP API for java(http://directory.apache.org/api/downloads.html) and I
would like to pass a certificate to that connection. Is it possible?
Thanks,
On 08/06/16 15:03, Kiran Ayyagari wrote:
>
>
> On Wed, Jun 8, 2016 at 5:13 PM, Christos Papoulas
> <pachristos@gmail.com <ma...@gmail.com>> wrote:
>
> Hello list,
>
> Is it possible to pass a certificate file like ssl-cert.pem to the
> LdapConnectionConfig? My sample code right now is:
>
> are you connecting to Apache Directory Server? if yes, then
> certificate based authentication is
> not supported.
>
> If you are connecting to any other server that supports certificate
> based authentication then
> you need to set the TrustManager and KeyManager in LdapConnectionConfig
>
> public static LdapConnection createConnection(String host, int port,
> String user, String pass, boolean useSSL, boolean
> useSSLv3) throws IOException, LdapException {
> LdapConnectionConfig connectionConfig = new
> LdapConnectionConfig();
>
> if (host == null || host.isEmpty()) {
> throw new IllegalArgumentException("Hostname is not
> specified");
> }
> if(port <= 0) {
> throw new IllegalArgumentException("The ldap port is
> not valid");
> }
> connectionConfig.setLdapHost(host);
> connectionConfig.setLdapPort(port);
>
> if(user!= null && user.length() > 0) {
> connectionConfig.setName(user);
> }
> if(pass != null && pass.length() > 0) {
> connectionConfig.setCredentials(pass);
> }
> if(useSSL == true) {
> connectionConfig.setUseSsl(true);
> }
> if(useSSLv3 == true) {
> connectionConfig.setSslProtocol("SSLv3");
> }
> LdapConnection connection = new
> LdapNetworkConnection(connectionConfig);
>
> connection.connect();
> connection.bind();
>
> return connection;
> }
>
> Kiran Ayyagari
> http://keydap.com
Re: pass certificate to LdapConnectionConfig
Posted by Kiran Ayyagari <ka...@apache.org>.
On Wed, Jun 8, 2016 at 5:13 PM, Christos Papoulas <pa...@gmail.com>
wrote:
> Hello list,
>
> Is it possible to pass a certificate file like ssl-cert.pem to the
> LdapConnectionConfig? My sample code right now is:
>
> are you connecting to Apache Directory Server? if yes, then certificate
based authentication is
not supported.
If you are connecting to any other server that supports certificate based
authentication then
you need to set the TrustManager and KeyManager in LdapConnectionConfig
> public static LdapConnection createConnection(String host, int port,
> String user, String pass, boolean useSSL, boolean useSSLv3)
> throws IOException, LdapException {
> LdapConnectionConfig connectionConfig = new
> LdapConnectionConfig();
>
> if (host == null || host.isEmpty()) {
> throw new IllegalArgumentException("Hostname is not
> specified");
> }
> if(port <= 0) {
> throw new IllegalArgumentException("The ldap port is not
> valid");
> }
> connectionConfig.setLdapHost(host);
> connectionConfig.setLdapPort(port);
>
> if(user!= null && user.length() > 0) {
> connectionConfig.setName(user);
> }
> if(pass != null && pass.length() > 0) {
> connectionConfig.setCredentials(pass);
> }
> if(useSSL == true) {
> connectionConfig.setUseSsl(true);
> }
> if(useSSLv3 == true) {
> connectionConfig.setSslProtocol("SSLv3");
> }
> LdapConnection connection = new
> LdapNetworkConnection(connectionConfig);
>
> connection.connect();
> connection.bind();
>
> return connection;
> }
>
Kiran Ayyagari
http://keydap.com