You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/11/25 17:50:40 UTC

svn commit: r1039094 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/ main/java/org/apache/directory/shared/kerberos/components/ main/java/org/apache/directory/shared/kerbero...

Author: elecharny
Date: Thu Nov 25 16:50:40 2010
New Revision: 1039094

URL: http://svn.apache.org/viewvc?rev=1039094&view=rev
Log:
Added tests for EncKdcRepPart, some minor fixes.

Added:
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPartDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/StoreSName.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/flags/AbstractKerberosFlags.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/StoreSName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/StoreSName.java?rev=1039094&r1=1039093&r2=1039094&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/StoreSName.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPart/actions/StoreSName.java Thu Nov 25 16:50:40 2010
@@ -105,5 +105,7 @@ public class StoreSName extends GrammarA
         {
             LOG.debug( "SName : {}", principalName );
         }
+        
+        encKdcRepPartContainer.setGrammarEndAllowed( true );
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java?rev=1039094&r1=1039093&r2=1039094&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKdcRepPart.java Thu Nov 25 16:50:40 2010
@@ -495,9 +495,12 @@ public class EncKdcRepPart extends Abstr
         snameLength = sname.computeLength();
         encKdcRepPartSeqLength += 1 + TLV.getNbBytes( snameLength ) + snameLength;
 
-        // The caddr
-        caddrLength = caddr.computeLength();
-        encKdcRepPartSeqLength += 1 + TLV.getNbBytes( caddrLength ) + caddrLength;
+        // The caddr if any
+        if ( caddr != null )
+        {
+            caddrLength = caddr.computeLength();
+            encKdcRepPartSeqLength += 1 + TLV.getNbBytes( caddrLength ) + caddrLength;
+        }
 
         return 1 + TLV.getNbBytes( encKdcRepPartSeqLength ) + encKdcRepPartSeqLength;
     }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/flags/AbstractKerberosFlags.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/flags/AbstractKerberosFlags.java?rev=1039094&r1=1039093&r2=1039094&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/flags/AbstractKerberosFlags.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/flags/AbstractKerberosFlags.java Thu Nov 25 16:50:40 2010
@@ -89,14 +89,14 @@ public abstract class AbstractKerberosFl
      */
     public AbstractKerberosFlags( byte[] flags )
     {
-        super( MAX_SIZE );
+        super( flags );
         
-        if ( ( flags == null ) || ( flags.length != 4 ) )
+        if ( ( flags == null ) || ( flags.length != 5 ) )
         {
             throw new IllegalArgumentException( "The given flags is not correct" );
         }
         
-        value = ( ( flags[0] & 0x00FF ) << 24 ) | ( ( flags[1] & 0x00FF ) << 16 ) | ( ( flags[2] & 0x00FF ) << 8 ) | ( 0x00FF & flags[3] );
+        value = ( ( flags[1] & 0x00FF ) << 24 ) | ( ( flags[2] & 0x00FF ) << 16 ) | ( ( flags[3] & 0x00FF ) << 8 ) | ( 0x00FF & flags[4] );
     }
     
     

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPartDecoderTest.java?rev=1039094&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPartDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKdcRepPartDecoderTest.java Thu Nov 25 16:50:40 2010
@@ -0,0 +1,447 @@
+/*
+ *   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.fail;
+
+import java.nio.ByteBuffer;
+
+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.EncKdcRepPart.EncKdcRepPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for EncKrbPrivPart codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKdcRepPartDecoderTest
+{
+    /**
+     * Test an empty EncKdcRepPart
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartEmpty() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x02;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x00
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an empty key
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartEmptyKey() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x04;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x02,
+              (byte)0xA0, 0x00
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with a missing key
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartMissingKey() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x04;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x02,
+              (byte)0xA1, 0x00 
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an empty last-req
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartEmptylastReq() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x17;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x15,
+              (byte)0xA0, 0x11,
+                0x30, 0x0F, 
+                  (byte)0xA0, 0x03, 
+                    0x02, 0x01, 0x11, 
+                  (byte)0xA1, 0x08, 
+                    0x04, 0x06, 
+                      0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+              (byte)0xA1, 0x00 
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an missing last-req
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartLastReqMissing() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x17;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x15,
+              (byte)0xA0, 0x11,
+                0x30, 0x0F, 
+                  (byte)0xA0, 0x03, 
+                    0x02, 0x01, 0x11, 
+                  (byte)0xA1, 0x08, 
+                    0x04, 0x06, 
+                      0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+              (byte)0xA2, 0x00 
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an empty nonce
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartEmptyNonce() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x4F;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x4D,
+              (byte)0xA0, 0x11,
+                0x30, 0x0F, 
+                  (byte)0xA0, 0x03, 
+                    0x02, 0x01, 0x11, 
+                  (byte)0xA1, 0x08, 
+                    0x04, 0x06, 
+                      0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+              (byte)0xA1, 0x36,
+                0x30, 0x34, 
+                  0x30, 0x18, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x02, 
+                    (byte)0xA1, 0x11, 
+                      0x18, 0x0F, 
+                        0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                  0x30, 0x18,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x02,
+                    (byte)0xA1, 0x11,
+                      0x18, 0x0F, 
+                        0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+              (byte)0xA2, 0x00
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an missing nonce
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartNonceMissing() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x4F;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+             {
+                 0x30, 0x4D,
+                   (byte)0xA0, 0x11,
+                     0x30, 0x0F, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x11, 
+                       (byte)0xA1, 0x08, 
+                         0x04, 0x06, 
+                           0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+                   (byte)0xA1, 0x36,
+                     0x30, 0x34, 
+                       0x30, 0x18, 
+                         (byte)0xA0, 0x03, 
+                           0x02, 0x01, 0x02, 
+                         (byte)0xA1, 0x11, 
+                           0x18, 0x0F, 
+                             0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                       0x30, 0x18,
+                         (byte)0xA0, 0x03,
+                           0x02, 0x01, 0x02,
+                         (byte)0xA1, 0x11,
+                           0x18, 0x0F, 
+                             0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                   (byte)0xA3, 0x00
+             });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with an empty key-expiration
+     * @throws Exception
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeEncKdcRepPartEmptyKeyExpiration() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x54;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x52,
+              (byte)0xA0, 0x11,
+                0x30, 0x0F, 
+                  (byte)0xA0, 0x03, 
+                    0x02, 0x01, 0x11, 
+                  (byte)0xA1, 0x08, 
+                    0x04, 0x06, 
+                      0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+              (byte)0xA1, 0x36,
+                0x30, 0x34, 
+                  0x30, 0x18, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x02, 
+                    (byte)0xA1, 0x11, 
+                      0x18, 0x0F, 
+                        0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                  0x30, 0x18,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x02,
+                    (byte)0xA1, 0x11,
+                      0x18, 0x0F, 
+                        0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+              (byte)0xA2, 0x03,
+                0x02, 0x01, 0x01,
+              (byte)0xA3, 0x00
+        });
+        
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        Asn1Container encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        decoder.decode( stream, encKdcRepPartContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test an EncKdcRepPart with no optional fields
+     * @throws Exception
+     */
+    @Test
+    public void testDecodeEncKdcRepPartNoOptionalFields() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x9F;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+             {
+                 0x30, (byte)0x81, (byte)0x9C,
+                   (byte)0xA0, 0x11,
+                     0x30, 0x0F, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x11, 
+                       (byte)0xA1, 0x08, 
+                         0x04, 0x06, 
+                           0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+                   (byte)0xA1, 0x36,
+                     0x30, 0x34, 
+                       0x30, 0x18, 
+                         (byte)0xA0, 0x03, 
+                           0x02, 0x01, 0x02, 
+                         (byte)0xA1, 0x11, 
+                           0x18, 0x0F, 
+                             0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                       0x30, 0x18,
+                         (byte)0xA0, 0x03,
+                           0x02, 0x01, 0x02,
+                         (byte)0xA1, 0x11,
+                           0x18, 0x0F, 
+                             0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                   (byte)0xA2, 0x03,
+                     0x02, 0x01, 0x01,
+                   (byte)0xA4, 0x07,
+                     0x03, 0x05, 0x00, 0x40, 0x00, 0x00, 0x00,
+                   (byte)0xA5, 0x11,
+                     0x18, 0x0F, 
+                       0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                   (byte)0xA7, 0x11, 
+                     0x18, 0x0F, 
+                       0x32, 0x30, 0x31, 0x30, 0x31, 0x31, 0x32, 0x35, 0x31, 0x36, 0x31, 0x32, 0x35, 0x39, 0x5A,
+                   (byte)0xA9, 0x06,
+                     0x1B, 0x04, 'a', 'b', 'c', 'd',
+                   (byte)0xAA, 0x13,
+                     0x30, 0x11, 
+                       (byte)0xA0, 0x03, 
+                         0x02, 0x01, 0x01, 
+                       (byte)0xA1, 0x0A, 
+                         0x30, 0x08,
+                           0x1B, 0x06, 
+                             0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+             });
+        
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a EncKdcRepPart Container
+        EncKdcRepPartContainer encKdcRepPartContainer = new EncKdcRepPartContainer();
+        encKdcRepPartContainer.setStream( stream );
+
+        // Decode the EncKdcRepPart PDU
+        try
+        {
+            decoder.decode( stream, encKdcRepPartContainer );
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        
+        EncKdcRepPart encKdcRepPart = encKdcRepPartContainer.getEncKdcRepPart();
+
+        int computedLen = encKdcRepPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKdcRepPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+}