directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1035633 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/kdcReq/ main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/ main/java/org/apache/directory/shared/kerberos/com...
Date Tue, 16 Nov 2010 13:31:06 GMT
Author: elecharny
Date: Tue Nov 16 13:31:05 2010
New Revision: 1035633

URL: http://svn.apache.org/viewvc?rev=1035633&view=rev
Log:
o Modified the KdcReq decoder to deal with AS-REQ messages
o Added a test for AS-REQ message decoding

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/CheckMsgType.java
      - copied, changed from r1035112, directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreMsgType.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
Removed:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/KdcReqInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreMsgType.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java?rev=1035633&r1=1035632&r2=1035633&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqGrammar.java
Tue Nov 16 13:31:05 2010
@@ -27,9 +27,8 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.kerberos.KerberosConstants;
 import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.AddPaData;
-import org.apache.directory.shared.kerberos.codec.kdcReq.actions.KdcReqInit;
+import org.apache.directory.shared.kerberos.codec.kdcReq.actions.CheckMsgType;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StoreKdcReqBody;
-import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StoreMsgType;
 import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StorePvno;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -73,7 +72,7 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         super.transitions[KdcReqStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
             KdcReqStatesEnum.START_STATE, KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, UniversalTag.SEQUENCE.getValue(),
-            new KdcReqInit() );
+            new CheckNotNullLength() );
         
         // --------------------------------------------------------------------------------------------
         // Transition from KdcReq SEQ to pvno tag
@@ -111,7 +110,7 @@ public final class KdcReqGrammar extends
         //         msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),
         super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
             KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE, KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE,
UniversalTag.INTEGER.getValue(),
-            new StoreMsgType() );
+            new CheckMsgType() );
         
         // --------------------------------------------------------------------------------------------
         // Transition from msg-type value to padata tag

Copied: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/CheckMsgType.java
(from r1035112, directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreMsgType.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/CheckMsgType.java?p2=directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/CheckMsgType.java&p1=directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreMsgType.java&r1=1035112&r2=1035633&rev=1035633&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/StoreMsgType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/actions/CheckMsgType.java
Tue Nov 16 13:31:05 2010
@@ -41,10 +41,10 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreMsgType extends GrammarAction
+public class CheckMsgType extends GrammarAction
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( StoreMsgType.class );
+    private static final Logger LOG = LoggerFactory.getLogger( CheckMsgType.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
@@ -53,7 +53,7 @@ public class StoreMsgType extends Gramma
     /**
      * Instantiates a new StoreMsgType action.
      */
-    public StoreMsgType()
+    public CheckMsgType()
     {
         super( "KDC-REQ msg-type" );
     }
@@ -86,7 +86,8 @@ public class StoreMsgType extends Gramma
             int msgType = IntegerDecoder.parse( value );
             KerberosMessageType krbMsgType = KerberosMessageType.getTypeByOrdinal( msgType
);
             
-            if ( ( krbMsgType != KerberosMessageType.AS_REQ ) && ( krbMsgType !=
KerberosMessageType.TGS_REQ ) )
+            // The message type must be the expected one
+            if ( krbMsgType != kdcReq.getMsgType() )
             {
                 LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData()
), "The msg-type should be AS-REQ or TGS-REQ" ) );
 
@@ -94,8 +95,6 @@ public class StoreMsgType extends Gramma
                 throw new DecoderException( "The msg-type should be AS-REQ or TGS-REQ" );
             }
 
-            kdcReq.setMsgType( krbMsgType );
-
             if ( IS_DEBUG )
             {
                 LOG.debug( "msg-type : {}", krbMsgType );

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java?rev=1035633&r1=1035632&r2=1035633&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
Tue Nov 16 13:31:05 2010
@@ -48,7 +48,7 @@ import org.apache.directory.shared.kerbe
  * </pre>
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class KdcReq
+public abstract class KdcReq
 {
     /** The PVNO field */
     private int pvno;
@@ -75,8 +75,9 @@ public class KdcReq
     /**
      * Creates a new instance of KDC-REQ.
      */
-    public KdcReq()
+    public KdcReq( KerberosMessageType msgType )
     {
+        this.msgType = msgType;
         paData = new ArrayList<PaData>();
     }
 
@@ -109,15 +110,6 @@ public class KdcReq
 
 
     /**
-     * @param msgType the msgType to set
-     */
-    public void setMsgType( KerberosMessageType msgType )
-    {
-        this.msgType = msgType;
-    }
-
-
-    /**
      * @return the paData
      */
     public List<PaData> getPaData()
@@ -227,7 +219,7 @@ public class KdcReq
         {
             throw new EncoderException( I18n.err( I18n.ERR_148 ) );
         }
-        
+
         // The KDC-REQ SEQ Tag
         buffer.put( UniversalTag.SEQUENCE.getValue() );
         buffer.put( TLV.getBytes( kdcReqSeqLength ) );
@@ -282,10 +274,6 @@ public class KdcReq
     {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "pvno : " ).append( pvno ).append( '\n' );
-
-        sb.append( "msg-type : " );
-
         if ( msgType == KerberosMessageType.AS_REQ )
         {
             sb.append( "AS-REQ" ).append( '\n' );
@@ -299,6 +287,10 @@ public class KdcReq
             sb.append( "Unknown" ).append( '\n' );
         }
 
+        sb.append( "pvno : " ).append( pvno ).append( '\n' );
+
+        sb.append( "msg-type : " );
+
         for ( PaData paDataElem : paData )
         {
             sb.append( "padata : " ).append( paDataElem ).append( '\n' );

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java?rev=1035633&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
Tue Nov 16 13:31:05 2010
@@ -0,0 +1,256 @@
+/*
+ *  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.shared.kerberos.codec;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.asReq.AsReqContainer;
+import org.apache.directory.shared.kerberos.messages.AsReq;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a AsReq
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class AsReqDecoderTest
+{
+    /**
+     * Test the decoding of a AsReq message
+     */
+    @Test
+    public void testDecodeFullAsReq() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x193 );
+        
+        stream.put( new byte[]
+        {
+          0x6A, (byte)0x82, 0x01, (byte)0x8F,
+            0x30, (byte)0x82, 0x01, (byte)0x8B,
+              (byte)0xA1, 0x03,
+                0x02, 0x01, 0x05,
+              (byte)0xA2, 0x03,
+                0x02, 0x01, 0x0A,
+              (byte)0xA3, 0x20,
+                0x30, 0x1E,
+                  0x30, 0x0D,
+                    (byte)0xA1,0x03,
+                      0x02, 0x01, 01,
+                    (byte)0xA2, 0x06,
+                      0x04, 0x04, 'a', 'b', 'c', 'd',
+                  0x30, 0x0D,
+                    (byte)0xA1,0x03,
+                      0x02, 0x01, 01,
+                    (byte)0xA2, 0x06,
+                      0x04, 0x04, 'e', 'f', 'g', 'h',
+              (byte)0xA4, (byte)0x82, 0x01, 0x5B,
+                0x30, (byte)0x82, 0x01, 0x57, 
+                  (byte)0xA0, 0x07,
+                    0x03, 0x05, 
+                      0x00, 0x01, 0x04, 0x00, 0x32, 
+                  (byte)0xA1, 0x13, 
+                    0x30, 0x11, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x0A, 
+                      (byte)0xA1, 0x0A, 
+                        0x30, 0x08, 
+                          0x1B, 0x06, 
+                            'c', 'l', 'i', 'e', 'n', 't', 
+                  (byte)0xA2, 0x0D, 
+                    0x1B, 0x0B, 
+                      'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                  (byte)0xA3, 0x13, 
+                    0x30, 0x11, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x0A, 
+                      (byte)0xA1, 0x0A, 
+                        0x30, 0x08, 
+                          0x1B, 0x06, 
+                            's', 'e', 'r', 'v', 'e', 'r', 
+                  (byte)0xA4, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA5, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA6, 0x11, 
+                    0x18, 0x0F, 
+                      '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5',
'Z', 
+                  (byte)0xA7, 0x04, 
+                    0x02, 0x02, 
+                      0x30, 0x39, 
+                  (byte)0xA8, 0x0B, 
+                    0x30, 0x09, 
+                      0x02, 0x01, 0x06, 
+                      0x02, 0x01, 0x11, 
+                      0x02, 0x01, 0x12, 
+                  (byte)0xA9, 0x2E, 
+                    0x30, 0x2C, 
+                      0x30, 0x14, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x02, 
+                        (byte)0xA1, 0x0D, 
+                          0x04, 0x0B, 
+                            '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1', 
+                      0x30, 0x14, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x02, 
+                        (byte)0xA1, 0x0D, 
+                          0x04, 0x0B, 
+                            '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2', 
+                  (byte)0xAA, 0x11, 
+                    0x30, 0x0F, 
+                      (byte)0xA0, 0x03, 
+                        0x02, 0x01, 0x11, 
+                      (byte)0xA2, 0x08, 
+                        0x04, 0x06, 
+                          'a', 'b', 'c', 'd', 'e', 'f', 
+                  (byte)0xAB, (byte)0x81, (byte)0x83, 
+                    0x30, (byte)0x81, (byte)0x80, 
+                      0x61, 0x3E, 
+                        0x30, 0x3C, 
+                          (byte)0xA0, 0x03, 
+                            0x02, 0x01, 0x05, 
+                          (byte)0xA1, 0x0D, 
+                            0x1B, 0x0B, 
+                              'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+                          (byte)0xA2, 0x13, 
+                            0x30, 0x11, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x01, 
+                              (byte)0xA1, 0x0A, 
+                                0x30, 0x08, 
+                                  0x1B, 0x06, 
+                                    'c', 'l', 'i', 'e', 'n', 't', 
+                          (byte)0xA3, 0x11, 
+                            0x30, 0x0F, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x11, 
+                              (byte)0xA2, 0x08, 
+                                0x04, 0x06, 
+                                  'a', 'b', 'c', 'd', 'e', 'f', 
+                      0x61, 0x3E, 
+                        0x30, 0x3C, 
+                          (byte)0xA0, 0x03, 
+                            0x02, 0x01, 0x05, 
+                          (byte)0xA1, 0x0D, 
+                            0x1B, 0x0B, 
+                              'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                          (byte)0xA2, 0x13, 
+                            0x30, 0x11, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x01, 
+                              (byte)0xA1, 0x0A, 
+                                0x30, 0x08, 
+                                  0x1B, 0x06, 
+                                    's', 'e', 'r', 'v', 'e', 'r', 
+                          (byte)0xA3, 0x11, 
+                            0x30, 0x0F, 
+                              (byte)0xA0, 0x03, 
+                                0x02, 0x01, 0x11, 
+                              (byte)0xA2, 0x08, 
+                                0x04, 0x06, 
+                                  'a', 'b', 'c', 'd', 'e', 'f'
+        });
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a AsReq Container
+        AsReqContainer asReqContainer = new AsReqContainer();
+        asReqContainer.setStream( stream );
+        
+        // Decode the AsReq PDU
+        try
+        {
+            kerberosDecoder.decode( stream, asReqContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        AsReq asReq = asReqContainer.getAsReq();
+        
+        assertTrue( asReq instanceof AsReq );
+        
+        // Check the encoding
+        int length = asReq.computeLength();
+
+        // Check the length
+        assertEquals( 0x193, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = asReq.encode( encodedPdu );
+    
+            // Check the length
+            assertEquals( 0x193, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a AS-REQ with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testAsReqEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x6A, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a AS-REQ Container
+        Asn1Container asReqContainer = new AsReqContainer();
+
+        // Decode the AS-REQ PDU
+        kerberosDecoder.decode( stream, asReqContainer );
+        fail();
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java?rev=1035633&r1=1035632&r2=1035633&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
Tue Nov 16 13:31:05 2010
@@ -36,6 +36,7 @@ import org.apache.directory.shared.kerbe
 import org.apache.directory.shared.kerberos.codec.kdcReqBody.KdcReqBodyContainer;
 import org.apache.directory.shared.kerberos.components.KdcReq;
 import org.apache.directory.shared.kerberos.components.KdcReqBody;
+import org.apache.directory.shared.kerberos.messages.AsReq;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -194,6 +195,7 @@ public class KdcReqDecoderTest
         // Allocate a KdcReq Container
         KdcReqContainer kdcReqContainer = new KdcReqContainer();
         kdcReqContainer.setStream( stream );
+        kdcReqContainer.setKdcReq( new AsReq() );
         
         // Decode the KdcReq PDU
         try
@@ -211,7 +213,7 @@ public class KdcReqDecoderTest
         int length = kdcReq.computeLength();
 
         // Check the length
-        assertEquals( 0x18F, length );
+        assertEquals( 0x193, length );
         
         // Check the encoding
         ByteBuffer encodedPdu = ByteBuffer.allocate( length );
@@ -221,7 +223,7 @@ public class KdcReqDecoderTest
             encodedPdu = kdcReq.encode( encodedPdu );
     
             // Check the length
-            assertEquals( 0x18F, encodedPdu.limit() );
+            assertEquals( 0x193, encodedPdu.limit() );
         }
         catch ( EncoderException ee )
         {



Mime
View raw message