You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by GitBox <gi...@apache.org> on 2020/06/25 18:51:45 UTC

[GitHub] [directory-server] kwart opened a new pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

kwart opened a new pull request #38:
URL: https://github.com/apache/directory-server/pull/38


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] coheigea commented on pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
coheigea commented on pull request #38:
URL: https://github.com/apache/directory-server/pull/38#issuecomment-688673719


   Can you change the commit message instead to reference DIRSERVER-2327? I moved the JIRA to the correct project (DIRKRB is just for Apache Kerby)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] coheigea commented on a change in pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
coheigea commented on a change in pull request #38:
URL: https://github.com/apache/directory-server/pull/38#discussion_r446040492



##########
File path: protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/KdcServer.java
##########
@@ -255,4 +252,36 @@ public String toString()
 
         return sb.toString();
     }
+
+    private void initReplayCache()
+    {
+        LOG.debug( "initializing the kerberos replay cache" );
+
+        Class<? extends ReplayCache> clazz = config.getReplayCacheType();
+        if ( clazz == null )
+        {
+            LOG.trace( "Kerberos replay cache is disabled" );
+            return;
+        }
+
+        LOG.debug( "Creating ReplayCache of type {}", clazz.getName() );
+        ReplayCache instance = null;
+        try
+        {
+            try
+            {
+                instance = clazz.getConstructor( Long.TYPE ).newInstance( config.getAllowableClockSkew() );
+            }
+            catch ( NoSuchMethodException e )
+            {
+                instance = clazz.newInstance();
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed creating ReplayCache of type {}. Replay cache will not be used.", clazz.getName() );

Review comment:
       Shouldn't we log the exception message at least here?

##########
File path: protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/TGSReplayCacheTest.java
##########
@@ -0,0 +1,193 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ * 
+ */
+package org.apache.directory.server.kerberos.protocol;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.text.ParseException;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.KerberosConfig;
+import org.apache.directory.server.kerberos.kdc.KdcServer;
+import org.apache.directory.server.kerberos.protocol.AbstractAuthenticationServiceTest.KrbDummySession;
+import org.apache.directory.server.kerberos.shared.crypto.encryption.CipherTextHandler;
+import org.apache.directory.server.kerberos.shared.replay.ReplayCache;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.options.KdcOptions;
+import org.apache.directory.shared.kerberos.components.EncTicketPart;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.kerberos.components.KdcReq;
+import org.apache.directory.shared.kerberos.components.KdcReqBody;
+import org.apache.directory.shared.kerberos.exceptions.ErrorType;
+import org.apache.directory.shared.kerberos.exceptions.KerberosException;
+import org.apache.directory.shared.kerberos.messages.KrbError;
+import org.apache.directory.shared.kerberos.messages.TgsRep;
+import org.apache.directory.shared.kerberos.messages.Ticket;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests for configurable {@link ReplayCache}.
+ */
+public class TGSReplayCacheTest extends AbstractTicketGrantingServiceTest
+{
+    private KdcServer kdcServer;
+    private KerberosProtocolHandler handler;
+
+    /**
+     * Shutdown the Kerberos server
+     */
+    @After
+    public void shutDown()
+    {
+        kdcServer.stop();
+    }
+
+    /**
+     * Tests the replay cache is used by default.
+     */
+    @Test
+    public void testDefaultReplayCache() throws Exception
+    {
+        initKdcServer( new KerberosConfig() );
+
+        KdcReq message = createTgsRequest();
+
+        KrbDummySession session = new KrbDummySession();
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+
+        handler.messageReceived( session, message );
+        Object msg = session.getMessage();
+        assertEquals( "session.getMessage() instanceOf", KrbError.class, msg.getClass() );
+        KrbError error = (KrbError) msg;
+        assertEquals( "Replay not detected", ErrorType.KRB_AP_ERR_REPEAT, error.getErrorCode() );
+    }
+
+    /**
+     * Tests the replay cache is not used if the type is explicitly set to null.
+     */
+    @Test
+    public void testNullReplayCacheType() throws Exception
+    {
+        KerberosConfig config = new KerberosConfig();
+        config.setReplayCacheType( null );
+        initKdcServer( config );
+
+        KdcReq message = createTgsRequest();
+
+        KrbDummySession session = new KrbDummySession();
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+    }
+
+    /**
+     * Tests that custom replay cache can be .

Review comment:
       can be set/configured




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] kwart commented on pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
kwart commented on pull request #38:
URL: https://github.com/apache/directory-server/pull/38#issuecomment-688720945


   Sure, it's updated now. I also rebased to the latest `master` and squashed the commits.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] kwart commented on a change in pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
kwart commented on a change in pull request #38:
URL: https://github.com/apache/directory-server/pull/38#discussion_r446050525



##########
File path: protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/kdc/KdcServer.java
##########
@@ -255,4 +252,36 @@ public String toString()
 
         return sb.toString();
     }
+
+    private void initReplayCache()
+    {
+        LOG.debug( "initializing the kerberos replay cache" );
+
+        Class<? extends ReplayCache> clazz = config.getReplayCacheType();
+        if ( clazz == null )
+        {
+            LOG.trace( "Kerberos replay cache is disabled" );
+            return;
+        }
+
+        LOG.debug( "Creating ReplayCache of type {}", clazz.getName() );
+        ReplayCache instance = null;
+        try
+        {
+            try
+            {
+                instance = clazz.getConstructor( Long.TYPE ).newInstance( config.getAllowableClockSkew() );
+            }
+            catch ( NoSuchMethodException e )
+            {
+                instance = clazz.newInstance();
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed creating ReplayCache of type {}. Replay cache will not be used.", clazz.getName() );

Review comment:
       Good point. Will do.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] coheigea merged pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
coheigea merged pull request #38:
URL: https://github.com/apache/directory-server/pull/38


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] kwart commented on pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
kwart commented on pull request #38:
URL: https://github.com/apache/directory-server/pull/38#issuecomment-667144598


   Any progress here? Thank you.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] kwart commented on pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
kwart commented on pull request #38:
URL: https://github.com/apache/directory-server/pull/38#issuecomment-688363669


   @coheigea @elecharny Is there anything missing in the PR?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org


[GitHub] [directory-server] kwart commented on a change in pull request #38: [DIRKRB-744] Make the ReplayCache implementation configurable

Posted by GitBox <gi...@apache.org>.
kwart commented on a change in pull request #38:
URL: https://github.com/apache/directory-server/pull/38#discussion_r446050627



##########
File path: protocol-kerberos/src/test/java/org/apache/directory/server/kerberos/protocol/TGSReplayCacheTest.java
##########
@@ -0,0 +1,193 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ * 
+ */
+package org.apache.directory.server.kerberos.protocol;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.text.ParseException;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.KerberosConfig;
+import org.apache.directory.server.kerberos.kdc.KdcServer;
+import org.apache.directory.server.kerberos.protocol.AbstractAuthenticationServiceTest.KrbDummySession;
+import org.apache.directory.server.kerberos.shared.crypto.encryption.CipherTextHandler;
+import org.apache.directory.server.kerberos.shared.replay.ReplayCache;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.options.KdcOptions;
+import org.apache.directory.shared.kerberos.components.EncTicketPart;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.kerberos.components.KdcReq;
+import org.apache.directory.shared.kerberos.components.KdcReqBody;
+import org.apache.directory.shared.kerberos.exceptions.ErrorType;
+import org.apache.directory.shared.kerberos.exceptions.KerberosException;
+import org.apache.directory.shared.kerberos.messages.KrbError;
+import org.apache.directory.shared.kerberos.messages.TgsRep;
+import org.apache.directory.shared.kerberos.messages.Ticket;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests for configurable {@link ReplayCache}.
+ */
+public class TGSReplayCacheTest extends AbstractTicketGrantingServiceTest
+{
+    private KdcServer kdcServer;
+    private KerberosProtocolHandler handler;
+
+    /**
+     * Shutdown the Kerberos server
+     */
+    @After
+    public void shutDown()
+    {
+        kdcServer.stop();
+    }
+
+    /**
+     * Tests the replay cache is used by default.
+     */
+    @Test
+    public void testDefaultReplayCache() throws Exception
+    {
+        initKdcServer( new KerberosConfig() );
+
+        KdcReq message = createTgsRequest();
+
+        KrbDummySession session = new KrbDummySession();
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+
+        handler.messageReceived( session, message );
+        Object msg = session.getMessage();
+        assertEquals( "session.getMessage() instanceOf", KrbError.class, msg.getClass() );
+        KrbError error = (KrbError) msg;
+        assertEquals( "Replay not detected", ErrorType.KRB_AP_ERR_REPEAT, error.getErrorCode() );
+    }
+
+    /**
+     * Tests the replay cache is not used if the type is explicitly set to null.
+     */
+    @Test
+    public void testNullReplayCacheType() throws Exception
+    {
+        KerberosConfig config = new KerberosConfig();
+        config.setReplayCacheType( null );
+        initKdcServer( config );
+
+        KdcReq message = createTgsRequest();
+
+        KrbDummySession session = new KrbDummySession();
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+
+        handler.messageReceived( session, message );
+        assertEquals( "session.getMessage() instanceOf", TgsRep.class, session.getMessage().getClass() );
+    }
+
+    /**
+     * Tests that custom replay cache can be .

Review comment:
       :+1:




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org