directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1040941 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/ main/java/org/apache/directory/shared/kerberos/codec/kdcReq/ main/java/org/apache/directory/shared/kerberos/components/ main/j...
Date Wed, 01 Dec 2010 10:49:44 GMT
Author: elecharny
Date: Wed Dec  1 10:49:43 2010
New Revision: 1040941

URL: http://svn.apache.org/viewvc?rev=1040941&view=rev
Log:
Fixed a bug in the KDC-REQ codec : when no PA-DATA were present, the decoding and the encoding
were wrong.

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
    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/codec/kdcReq/KdcReqStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsReq.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java?rev=1040941&r1=1040940&r2=1040941&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
Wed Dec  1 10:49:43 2010
@@ -42,6 +42,7 @@ import org.apache.directory.shared.kerbe
 import org.apache.directory.shared.kerberos.codec.tgsRep.TgsRepContainer;
 import org.apache.directory.shared.kerberos.codec.tgsReq.TgsReqContainer;
 import org.apache.directory.shared.kerberos.messages.KerberosMessage;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -85,6 +86,8 @@ public final class KerberosMessageGramma
                     AsReqContainer asReqContainer = new AsReqContainer();
                     asReqContainer.setStream( stream );
                     
+                    System.out.println( StringTools.dumpBytes( stream.array() ) );
+                    
                     // Decode the AS_REQ PDU
                     try
                     {

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=1040941&r1=1040940&r2=1040941&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
Wed Dec  1 10:49:43 2010
@@ -80,7 +80,7 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         //         pvno            [1]
         super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE.ordinal()][KerberosConstants.KDC_REQ_PVNO_TAG]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE,
KerberosConstants.KDC_REQ_PVNO_TAG,
+            KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, KdcReqStatesEnum.KDC_REQ_PVNO_STATE,
KerberosConstants.KDC_REQ_PVNO_TAG,
             new CheckNotNullLength() );
         
         // --------------------------------------------------------------------------------------------
@@ -88,8 +88,8 @@ public final class KdcReqGrammar extends
         // --------------------------------------------------------------------------------------------
         // KDC-REQ         ::= SEQUENCE {
         //         pvno            [1] INTEGER (5) ,
-        super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, KdcReqStatesEnum.KDC_REQ_PVNO_STATE,
UniversalTag.INTEGER.getValue(),
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PVNO_STATE, KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE,
UniversalTag.INTEGER.getValue(),
             new StorePvno() );
         
         // --------------------------------------------------------------------------------------------
@@ -98,8 +98,8 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         //         ...
         //         msg-type        [2]
-        super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_STATE.ordinal()][KerberosConstants.KDC_REQ_MSG_TYPE_TAG]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_PVNO_STATE, KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE,
KerberosConstants.KDC_REQ_MSG_TYPE_TAG,
+        super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE.ordinal()][KerberosConstants.KDC_REQ_MSG_TYPE_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE, KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE,
KerberosConstants.KDC_REQ_MSG_TYPE_TAG,
             new CheckNotNullLength() );
         
         // --------------------------------------------------------------------------------------------
@@ -108,8 +108,8 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         //         ...
         //         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(),
+        super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE,
UniversalTag.INTEGER.getValue(),
             new CheckMsgType() );
         
         // --------------------------------------------------------------------------------------------
@@ -118,8 +118,8 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         //         ...
         //         padata          [3]
-        super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REQ_PA_DATA_TAG]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE,
KerberosConstants.KDC_REQ_PA_DATA_TAG,
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE.ordinal()][KerberosConstants.KDC_REQ_PA_DATA_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE,
KerberosConstants.KDC_REQ_PA_DATA_TAG,
             new CheckNotNullLength() );
         
         // --------------------------------------------------------------------------------------------
@@ -128,9 +128,9 @@ public final class KdcReqGrammar extends
         // KDC-REQ         ::= SEQUENCE {
         //         ...
         //         req-body        [4]
-        super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
-            new CheckNotNullLength() );
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
+            new StoreKdcReqBody() );
         
         // --------------------------------------------------------------------------------------------
         // Transition from padata tag to pa-data SEQ
@@ -149,27 +149,27 @@ public final class KdcReqGrammar extends
         //         ...
         //         padata          [3] SEQUENCE OF <PA-DATA>
         super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE,
UniversalTag.SEQUENCE.getValue(),
             new AddPaData() );
         
         // --------------------------------------------------------------------------------------------
-        // Transition from pa-data to KDC-REQ-BODY tag
+        // Transition from pa-data to pa-data
         // --------------------------------------------------------------------------------------------
         // KDC-REQ         ::= SEQUENCE {
         //         ...
-        //         req-body        [4]
-        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
-            new StoreKdcReqBody() );
+        //         padata          [3] SEQUENCE OF <PA-DATA>
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new AddPaData() );
         
         // --------------------------------------------------------------------------------------------
-        // Transition from KDC-REQ-BODY tag to KDC-REQ-BODY value
+        // Transition from pa-data to KDC-REQ-BODY tag
         // --------------------------------------------------------------------------------------------
         // KDC-REQ         ::= SEQUENCE {
         //         ...
-        //         req-body        [4] KDC-REQ-BODY
-        super.transitions[KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
-            KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE, KdcReqStatesEnum.LAST_KDC_REQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+        //         req-body        [4]
+        super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG]
= new GrammarTransition(
+            KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE,
KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG,
             new StoreKdcReqBody() );
     }
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqStatesEnum.java?rev=1040941&r1=1040940&r2=1040941&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcReq/KdcReqStatesEnum.java
Wed Dec  1 10:49:43 2010
@@ -43,15 +43,17 @@ public enum KdcReqStatesEnum implements 
     
     KDC_REQ_MSG_TYPE_TAG_STATE,            // 4
     KDC_REQ_MSG_TYPE_STATE,                // 5
+    
+    KDC_REQ_PA_DATA_OR_REQ_BODY_STATE,     // 6
 
-    KDC_REQ_PA_DATA_TAG_STATE,             // 6
-    KDC_REQ_PA_DATA_SEQ_STATE,             // 7
-    KDC_REQ_PA_DATA_STATE,                 // 8
+    KDC_REQ_PA_DATA_TAG_STATE,             // 7
+    KDC_REQ_PA_DATA_SEQ_STATE,             // 8
+    KDC_REQ_PA_DATA_STATE,                 // 9
 
-    KDC_REQ_KDC_REQ_BODY_STATE,            // 9
+    KDC_REQ_KDC_REQ_BODY_STATE,            // 10
 
     // End
-    LAST_KDC_REQ_STATE;                    // 10
+    LAST_KDC_REQ_STATE;                    // 11
 
     
     /**

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=1040941&r1=1040940&r2=1040941&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
Wed Dec  1 10:49:43 2010
@@ -164,30 +164,31 @@ public abstract class KdcReq extends Ker
     {
         // The pvno length
         pvnoLength = 1 + 1 + 1;
+        kdcReqSeqLength = 1 + TLV.getNbBytes( pvnoLength ) + pvnoLength; 
         
         // The msg-type length
         msgTypeLength = 1 + 1 + 1;
+        kdcReqSeqLength += 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength; 
 
         // Compute the pa-data length.
-        paDataLengths = new int[paData.size()];
-        int pos = 0;
-        
-        for ( PaData paDataElem : paData )
+        if ( paData.size() > 0 )
         {
-            paDataLengths[pos] = paDataElem.computeLength();
-            paDataSeqLength += paDataLengths[pos];
-            pos++;
+            paDataLengths = new int[paData.size()];
+            int pos = 0;
+            
+            for ( PaData paDataElem : paData )
+            {
+                paDataLengths[pos] = paDataElem.computeLength();
+                paDataSeqLength += paDataLengths[pos];
+                pos++;
+            }
+            
+            paDataLength = 1 + TLV.getNbBytes( paDataSeqLength ) + paDataSeqLength;
+            kdcReqSeqLength += 1 + TLV.getNbBytes( paDataLength ) + paDataLength; 
         }
         
-        paDataLength = 1 + TLV.getNbBytes( paDataSeqLength ) + paDataSeqLength;
-        
         // The KDC-REQ-BODY length
         kdcReqBodyLength = kdcReqBody.computeLength();
-
-        // Compute the sequence size.
-        kdcReqSeqLength = 1 + TLV.getNbBytes( pvnoLength ) + pvnoLength; 
-        kdcReqSeqLength += 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength; 
-        kdcReqSeqLength += 1 + TLV.getNbBytes( paDataLength ) + paDataLength; 
         kdcReqSeqLength += 1 + TLV.getNbBytes( kdcReqBodyLength ) + kdcReqBodyLength; 
         
         // compute the global size
@@ -231,19 +232,22 @@ public abstract class KdcReq extends Ker
         // The value
         Value.encode( buffer, getMessageType().getValue() );
         
-        // The PD-DATA --------------------------------------------------------
-        // The tag
-        buffer.put( (byte)KerberosConstants.KDC_REQ_PA_DATA_TAG );
-        buffer.put( TLV.getBytes( paDataLength ) );
-        
-        // The sequence
-        buffer.put( UniversalTag.SEQUENCE.getValue() );
-        buffer.put( TLV.getBytes( paDataSeqLength ) );
-        
-        // The values
-        for ( PaData paDataElem : paData )
+        // The PD-DATA if any -------------------------------------------------
+        if ( paData.size() > 0 )
         {
-            paDataElem.encode( buffer );
+            // The tag
+            buffer.put( (byte)KerberosConstants.KDC_REQ_PA_DATA_TAG );
+            buffer.put( TLV.getBytes( paDataLength ) );
+            
+            // The sequence
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( paDataSeqLength ) );
+            
+            // The values
+            for ( PaData paDataElem : paData )
+            {
+                paDataElem.encode( buffer );
+            }
         }
 
         // The KDC-REQ-BODY ---------------------------------------------------

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsReq.java?rev=1040941&r1=1040940&r2=1040941&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsReq.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsReq.java
Wed Dec  1 10:49:43 2010
@@ -41,7 +41,6 @@ public class AsReq extends KdcReq
 {
     // Storage for computed lengths
     private transient int kdcReqLength;
-    private transient int asReqLength;
 
     /**
      * Creates a new instance of AS-REQ.
@@ -65,9 +64,7 @@ public class AsReq extends KdcReq
     public int computeLength()
     {
         kdcReqLength = super.computeLength();
-        asReqLength = 1 + TLV.getNbBytes( kdcReqLength ) + kdcReqLength;
-        
-        return asReqLength;
+        return 1 + TLV.getNbBytes( kdcReqLength ) + kdcReqLength;
     }
     
     
@@ -87,7 +84,7 @@ public class AsReq extends KdcReq
         
         // The AS-REQ SEQ Tag
         buffer.put( (byte)KerberosConstants.AS_REQ_TAG );
-        buffer.put( TLV.getBytes( asReqLength ) );
+        buffer.put( TLV.getBytes( kdcReqLength ) );
         
         // The KDC-REQ --------------------------------------------------------
         super.encode( buffer );

Modified: 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=1040941&r1=1040940&r2=1040941&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
Wed Dec  1 10:49:43 2010
@@ -34,6 +34,7 @@ import org.apache.directory.shared.asn1.
 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;
 
@@ -403,4 +404,177 @@ public class AsReqDecoderTest
         kerberosDecoder.decode( stream, asReqContainer );
         fail();
     }
+
+
+    /**
+     * Test the decoding of a AsReq message without PA-DATA
+     */
+    @Test
+    public void testDecodeAsReqNoPaData() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x171 );
+        
+        stream.put( new byte[]
+        {
+          0x6A, (byte)0x82, 0x01, (byte)0x6D,
+            0x30, (byte)0x82, 0x01, (byte)0x69,
+              (byte)0xA1, 0x03,
+                0x02, 0x01, 0x05,
+              (byte)0xA2, 0x03,
+                0x02, 0x01, 0x0A,
+              (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( 0x171, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = asReq.encode( encodedPdu );
+
+            // Check the length
+            assertEquals( 0x171, encodedPdu.limit() );
+
+            assertEquals( decodedPdu, StringTools.dumpBytes( encodedPdu.array() ) );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java?rev=1040941&r1=1040940&r2=1040941&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
Wed Dec  1 10:49:43 2010
@@ -31,8 +31,10 @@ import org.apache.directory.junit.tools.
 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.codec.tgsReq.TgsReqContainer;
 import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.apache.directory.shared.kerberos.messages.AsReq;
 import org.apache.directory.shared.kerberos.messages.TgsReq;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -50,7 +52,7 @@ public class KerberosMessageDecoderTest
      * Test the decoding of a AP-REP message and a TGS-REQ message
      */
     @Test
-    public void testDecodeApRep() throws Exception
+    public void testDecodeKerberosMessages() throws Exception
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
@@ -285,5 +287,271 @@ public class KerberosMessageDecoderTest
         {
             fail();
         }
+
+        // Now decode AS-REQ
+        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'
+        });
+        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
+        length = asReq.computeLength();
+
+        // Check the length
+        assertEquals( 0x193, length );
+        
+        // Check the encoding
+        encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = asReq.encode( encodedPdu );
+    
+            // Check the length
+            assertEquals( 0x193, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+        
+        // Now decode AS-REQ
+        stream = ByteBuffer.allocate( 0x97 );
+        
+        stream.put( new byte[]
+        {
+            0x6A, (byte)0x81, (byte)0x94, 
+              0x30, (byte)0x81, (byte)0x91, 
+                (byte)0xA1, 0x03, 
+                  0x02, 0x01, 0x05, 
+                (byte)0xA2, 0x03, 
+                  0x02, 0x01, 0x0A, 
+                (byte)0xA4, (byte)0x81, (byte)0x84, 
+                  0x30, (byte)0x81, (byte)0x81, 
+                    (byte)0xA0, 0x07, 
+                      0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                    (byte)0xA1, 0x14, 
+                      0x30, 0x12, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x01, 
+                        (byte)0xA1, 0x0B, 
+                          0x30, 0x09, 
+                            0x1B, 0x07, 
+                              0x68, 0x6E, 0x65, 0x6C, 0x73, 0x6F, 0x6E, 
+                    (byte)0xA2, 0x0D, 
+                      0x1B, 0x0B, 
+                        0x45, 0x58, 0x41, 0x4D, 0x50, 0x4C, 0x45, 0x2E, 0x43, 0x4F, 0x4D,

+                    (byte)0xA3, 0x20, 
+                      0x30, 0x1E, 
+                        (byte)0xA0, 0x03, 
+                          0x02, 0x01, 0x02, 
+                        (byte)0xA1, 0x17, 
+                          0x30, 0x15, 
+                            0x1B, 0x06, 
+                              0x6B, 0x72, 0x62, 0x74, 0x67, 0x74, 
+                            0x1B, 0x0B, 
+                              0x45, 0x58, 0x41, 0x4D, 0x50, 0x4C, 0x45, 0x2E, 0x43, 0x4F,
0x4D, 
+                    (byte)0xA5, 0x11, 
+                      0x18, 0x0F, 
+                        0x31, 0x39, 0x37, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
0x30, 0x30, 0x30, 0x5A, 
+                    (byte)0xA7, 0x06, 
+                      0x02, 0x04, 
+                        0x4C, (byte)0xF5, (byte)0x8E, (byte)0xCA, 
+                    (byte)0xA8, 0x14, 
+                      0x30, 0x12, 
+                        0x02, 0x01, 0x03, 
+                        0x02, 0x01, 0x01, 
+                        0x02, 0x01, 0x17, 
+                        0x02, 0x01, 0x10, 
+                        0x02, 0x01, 0x11, 
+                        0x02, 0x01, 0x12 
+        } );
+
+        stream.flip();
+
+        // Allocate a AsReq Container
+        asReqContainer = new AsReqContainer();
+        asReqContainer.setStream( stream );
+        
+        // Decode the AsReq PDU
+        try
+        {
+            kerberosDecoder.decode( stream, asReqContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        asReq = asReqContainer.getAsReq();
+        
+        assertTrue( asReq instanceof AsReq );
+        
+        // Check the encoding
+        length = asReq.computeLength();
+
+        // Check the length
+        assertEquals( 0x97, length );
+        
+        // Check the encoding
+        encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = asReq.encode( encodedPdu );
+    
+            // Check the length
+            assertEquals( 0x97, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
     }
 }



Mime
View raw message