You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2018/04/19 07:40:58 UTC
[directory-ldap-api] 01/02: Using MINA 2.0.17,
fixed a HandShake timeout error
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch 1.0.1
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit 3926eec8df3d4b72f677238891a68b0871664269
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Thu Apr 19 09:40:32 2018 +0200
Using MINA 2.0.17, fixed a HandShake timeout error
---
.../java/org/apache/directory/api/i18n/I18n.java | 5 +++-
.../apache/directory/api/i18n/errors.properties | 2 ++
.../ldap/client/api/LdapNetworkConnection.java | 35 +++++++++++++++++++++-
pom.xml | 8 ++---
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
index daf89b5..0275864 100644
--- a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
+++ b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
@@ -627,7 +627,10 @@ public enum I18n
ERR_04486_VALUE_ALREADY_EXISTS("ERR_04486_VALUE_ALREADY_EXISTS"),
ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED("ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED"),
ERR_04488_SYNTAX_INVALID("ERR_04488_SYNTAX_INVALID"),
-
+
+ // ldap-client-api 4100-
+ ERR_4100_TLS_HANDSHAKE_ERROR( "ERR_4100_TLS_HANDSHAKE_ERROR" ),
+
// ldap-constants
ERR_05001_UNKNOWN_AUTHENT_LEVEL("ERR_05001_UNKNOWN_AUTHENT_LEVEL"),
diff --git a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
index b1c25a6..0d6e620 100644
--- a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
+++ b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
@@ -615,6 +615,8 @@ ERR_04486_VALUE_ALREADY_EXISTS=The value ''{0}'' already exists in the attribute
ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED=The attribute ''{0}'' is single valued, we can't add no more values into it
ERR_04488_SYNTAX_INVALID=Syntax invalid for ''{0}''
+ERR_4100_TLS_HANDSHAKE_ERROR=The TLS handshake failed
+
# ldap-constants
ERR_05001_UNKNOWN_AUTHENT_LEVEL=Unknown AuthenticationLevel {0}
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index 07dfe35..422d121 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -54,6 +54,7 @@ import javax.security.sasl.SaslClient;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.util.Oid;
+import org.apache.directory.api.i18n.I18n;
import org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector;
import org.apache.directory.api.ldap.codec.api.DefaultConfigurableBinaryAttributeDetector;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
@@ -151,6 +152,7 @@ import org.apache.directory.ldap.client.api.future.BindFuture;
import org.apache.directory.ldap.client.api.future.CompareFuture;
import org.apache.directory.ldap.client.api.future.DeleteFuture;
import org.apache.directory.ldap.client.api.future.ExtendedFuture;
+import org.apache.directory.ldap.client.api.future.HandshakeFuture;
import org.apache.directory.ldap.client.api.future.ModifyDnFuture;
import org.apache.directory.ldap.client.api.future.ModifyFuture;
import org.apache.directory.ldap.client.api.future.ResponseFuture;
@@ -2022,6 +2024,26 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
public void messageReceived( IoSession session, Object message ) throws Exception
{
// Feed the response and store it into the session
+ if ( message instanceof SslFilter.SslFilterMessage )
+ {
+ // This is a SSL message telling if the session has been secured or not
+ HandshakeFuture handshakeFuture = ( HandshakeFuture ) ldapSession.getAttribute( "HANDSHAKE_FUTURE" );
+
+ if ( message == SslFilter.SESSION_SECURED )
+ {
+ // SECURED
+ handshakeFuture.secured();
+ }
+ else
+ {
+ // UNSECURED
+ handshakeFuture.cancel();
+ }
+
+ ldapSession.removeAttribute( "HANDSHAKE_FUTURE" );
+ return;
+ }
+
Message response = ( Message ) message;
LOG.debug( "-------> {} Message received <-------", response );
int messageId = response.getMessageId();
@@ -4014,7 +4036,7 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
sslContext.init( config.getKeyManagers(), trustManagers, config.getSecureRandom() );
- SslFilter sslFilter = new SslFilter( sslContext, true );
+ SslFilter sslFilter = new SslFilter( sslContext );
sslFilter.setUseClientMode( true );
// Configure the enabled cipher lists
@@ -4047,7 +4069,18 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
else
// for StartTLS
{
+ HandshakeFuture handshakeFuture = new HandshakeFuture();
+
+ ldapSession.setAttribute( SslFilter.USE_NOTIFICATION, Boolean.TRUE );
+ ldapSession.setAttribute( "HANDSHAKE_FUTURE", handshakeFuture );
ldapSession.getFilterChain().addFirst( SSL_FILTER_KEY, sslFilter );
+
+ boolean isSecured = handshakeFuture.get( timeout, TimeUnit.MILLISECONDS );
+
+ if ( !isSecured )
+ {
+ throw new LdapOperationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_4100_TLS_HANDSHAKE_ERROR ) );
+ }
}
}
catch ( Exception e )
diff --git a/pom.xml b/pom.xml
index 24e169a..851ca81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,7 +56,7 @@
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<logback.version>1.2.3</logback.version>
- <mina.core.version>2.0.16</mina.core.version>
+ <mina.core.version>2.0.17</mina.core.version>
<org.osgi.core.version>6.0.0</org.osgi.core.version>
<org.apache.felix.version>5.6.4</org.apache.felix.version>
<pax-exam.version>4.11.0</pax-exam.version>
@@ -609,9 +609,9 @@
</dependencyManagement>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/directory/shared/tags/1.0.0</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/directory/shared/tags/1.0.0</developerConnection>
- <url>http://svn.apache.org/viewvc/directory/shared/tags/1.0.0</url>
+ <connection>scm:git:https://gitbox.apache.org/repos/asf/directory-ldap-api.git</connection>
+ <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/directory-ldap-api.git</developerConnection>
+ <url>https://gitbox.apache.org/repos/asf?p=directory-ldap-api.git;a=shortlog;h=refs/remotes/tags/${project.scm.tag}</url>
</scm>
<reporting>
--
To stop receiving notification emails like this one, please contact
elecharny@apache.org.