directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1035018 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java
Date Sun, 14 Nov 2010 16:25:32 GMT
Author: elecharny
Date: Sun Nov 14 16:25:32 2010
New Revision: 1035018

URL: http://svn.apache.org/viewvc?rev=1035018&view=rev
Log:
o Fixed a bug in the KdcReqBody encoder
o Added some more tests for corner cases

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java?rev=1035018&r1=1035017&r2=1035018&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReqBody.java
Sun Nov 14 16:25:32 2010
@@ -22,9 +22,7 @@ package org.apache.directory.shared.kerb
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
@@ -95,7 +93,7 @@ public class KdcReqBody
     private int nonce;
     
     /** Set of desired encryption types */
-    private Set<EncryptionType> eType;
+    private List<EncryptionType> eType;
     
     /** Addresses valid for the requested ticket */
     private HostAddresses addresses;
@@ -133,7 +131,7 @@ public class KdcReqBody
     public KdcReqBody()
     {
         additionalTickets = new ArrayList<Ticket>();
-        eType = new HashSet<EncryptionType>();
+        eType = new ArrayList<EncryptionType>();
     }
 
 
@@ -231,7 +229,7 @@ public class KdcReqBody
      *
      * @return The requested {@link EncryptionType}s.
      */
-    public Set<EncryptionType> getEType()
+    public List<EncryptionType> getEType()
     {
         return eType;
     }
@@ -240,7 +238,7 @@ public class KdcReqBody
     /**
      * @param eType the eType to set
      */
-    public void setEType( Set<EncryptionType> eType )
+    public void setEType( List<EncryptionType> eType )
     {
         this.eType = eType;
     }
@@ -699,7 +697,7 @@ public class KdcReqBody
         // The values
         for ( EncryptionType encryptionType : eType )
         {
-            Value.encode( buffer, encryptionType.ordinal() );
+            Value.encode( buffer, encryptionType.getValue() );
         }
         
         // The addresses if any -----------------------------------------------

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java?rev=1035018&r1=1035017&r2=1035018&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqBodyDecoderTest.java
Sun Nov 14 16:25:32 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.kerb
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
@@ -174,8 +175,7 @@ public class KdcReqBodyDecoderTest
                             0x02, 0x01, 0x11, 
                           (byte)0xA2, 0x08, 
                             0x04, 0x06, 
-                              'a', 'b', 'c', 'd', 'e', 'f', 
-
+                              'a', 'b', 'c', 'd', 'e', 'f'
         });
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -256,4 +256,289 @@ public class KdcReqBodyDecoderTest
             fail();
         }
     }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with empty options tag
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmptyOptionTag() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+                0x30, 0x02,
+                  (byte)0xA0, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with empty options value
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyEmptyOptionValue() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x06 );
+        
+        stream.put( new byte[]
+            { 
+                0x30, 0x04,
+                  (byte)0xA0, 0x02,
+                    0x02, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a KDC-REQ-BODY with no options
+     */
+    @Test( expected = DecoderException.class)
+    public void testKdcReqBodyNoOptions() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x152 );
+        
+        stream.put( new byte[]
+             {
+                 0x30, (byte)0x82, 0x01, 0x4E, 
+                   (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 KDC-REQ-BODY Container
+        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+
+        // Decode the KDC-REQ-BODY PDU
+        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        fail();
+    }
+
+
+    /**
+     * Test the decoding of a KdcReqBody message with no optional value
+     * ( we only have options, realm, till, nonce and etype )
+     */
+    @Test
+    public void testDecodeKdcReqBodyNoOptionalValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x40 );
+        
+        stream.put( new byte[]
+        {
+            0x30, (byte)0x3E, 
+              (byte)0xA0, 0x07,
+                0x03, 0x05, 
+                  0x00, 0x01, 0x04, 0x00, 0x32, 
+              (byte)0xA2, 0x0D, 
+                0x1B, 0x0B, 
+                  'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
+              (byte)0xA5, 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
+        });
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a KdcReqBody Container
+        KdcReqBodyContainer kdcReqBodyContainer = new KdcReqBodyContainer();
+        kdcReqBodyContainer.setStream( stream );
+        
+        // Decode the KdcReqBody PDU
+        try
+        {
+            kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        KdcReqBody body = kdcReqBodyContainer.getKdcReqBody();
+        
+        assertNotNull( body );
+        
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( body.computeLength() );
+
+        try
+        {
+            bb = body.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x40, bb.limit() );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+            
+            System.out.println( decodedPdu );
+            System.out.println( encodedPdu );
+            assertEquals( decodedPdu, encodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
 }



Mime
View raw message