directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1039981 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encryptedData/ main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/ test/java/org/apache/directory/share...
Date Sun, 28 Nov 2010 23:49:18 GMT
Author: elecharny
Date: Sun Nov 28 23:49:17 2010
New Revision: 1039981

URL: http://svn.apache.org/viewvc?rev=1039981&view=rev
Log:
o Reviewed the EncryptedData code
o Added some tests
o Used the AbstractReadInteger for this class

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreEType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreKvno.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDataDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java?rev=1039981&r1=1039980&r2=1039981&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java
Sun Nov 28 23:49:17 2010
@@ -36,7 +36,7 @@ public enum EncryptedDataStatesEnum impl
     // Start
     START_STATE,                            // 0
     
-    // ----- PrincipalName message --------------------------------------
+    // ----- EncryptedData message --------------------------------------
     ENCRYPTED_DATA_SEQ_STATE,               // 1
     
     ENCRYPTED_DATA_ETYPE_TAG_STATE,         // 2

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreEType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreEType.java?rev=1039981&r1=1039980&r2=1039981&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreEType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreEType.java
Sun Nov 28 23:49:17 2010
@@ -21,19 +21,10 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.IntegerDecoder;
-import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.asn1.codec.actions.AbstractReadInteger;
 import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer;
 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
 import org.apache.directory.shared.kerberos.components.EncryptedData;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -41,15 +32,8 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreEType extends GrammarAction
+public class StoreEType extends AbstractReadInteger
 {
-    /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( StoreEType.class );
-
-    /** Speedup for logs */
-    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
-
     /**
      * Instantiates a new EncryptedPartEType action.
      */
@@ -62,46 +46,14 @@ public class StoreEType extends GrammarA
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
     {
         EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container;
-
-        TLV tlv = encryptedDataContainer.getCurrentTLV();
-
-        // The Length should not be null
-        if ( tlv.getLength() == 0 )
-        {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
-        }
         
-        // The encyptionType is an integer
-        Value value = tlv.getValue();
+        EncryptionType encryptionType = EncryptionType.getTypeByValue( value );
         
-        EncryptionType encryptionType = null;
         EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
-        
-        try
-        {
-            int eType = IntegerDecoder.parse( value );
-            encryptionType = EncryptionType.getTypeByValue( eType );
-
-            encryptedData.setEType( encryptionType );
-
-            if ( IS_DEBUG )
-            {
-                LOG.debug( "etype : " + encryptionType );
-            }
-        }
-        catch ( IntegerDecoderException ide )
-        {
-            LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ),
ide
-                .getLocalizedMessage() ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( ide.getMessage() );
-        }
+        encryptedData.setEType( encryptionType );
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreKvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreKvno.java?rev=1039981&r1=1039980&r2=1039981&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreKvno.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/StoreKvno.java
Sun Nov 28 23:49:17 2010
@@ -21,18 +21,9 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.IntegerDecoder;
-import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.asn1.codec.actions.AbstractReadInteger;
 import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer;
 import org.apache.directory.shared.kerberos.components.EncryptedData;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -40,63 +31,26 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreKvno extends GrammarAction
+public class StoreKvno extends AbstractReadInteger
 {
-    /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( StoreKvno.class );
-
-    /** Speedup for logs */
-    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
-
-
     /**
      * Instantiates a new EncryptedPartKvno action.
      */
     public StoreKvno()
     {
-        super( "EncryptedPart kvno" );
+        super( "EncryptedPart kvno", 0, Integer.MAX_VALUE );
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
     {
         EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container;
-
-        TLV tlv = encryptedDataContainer.getCurrentTLV();
-
-        // The Length should not be null
-        if ( tlv.getLength() == 0 )
-        {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
-        }
-        
-        Value value = tlv.getValue();
         
-        try
-        {
-            int kvno = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
-
-            EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
-            encryptedData.setKvno( kvno );
-
-            if ( IS_DEBUG )
-            {
-                LOG.debug( "kvno : {}", kvno );
-            }
-        }
-        catch ( IntegerDecoderException ide )
-        {
-            LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ),
ide
-                .getLocalizedMessage() ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( ide.getMessage() );
-        }
+        EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+        encryptedData.setKvno( value );
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDataDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDataDecoderTest.java?rev=1039981&r1=1039980&r2=1039981&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDataDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDataDecoderTest.java
Sun Nov 28 23:49:17 2010
@@ -62,7 +62,8 @@ public class EncryptedDataDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x16 );
         
         stream.put( new byte[]
-            { 0x30, 0x14,
+            { 
+              0x30, 0x14,
                 (byte)0xA0, 0x03,                 // etype
                   0x02, 0x01, 0x12,               //
                 (byte)0xA1, 0x03,                 // kvno
@@ -126,7 +127,8 @@ public class EncryptedDataDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x11 );
         
         stream.put( new byte[]
-            { 0x30, 0x0F,
+            { 
+              0x30, 0x0F,
                 (byte)0xA0, 0x03,                 // etype
                   0x02, 0x01, 0x12,               //
                 (byte)0xA2, 0x08,                 // cipher
@@ -228,6 +230,36 @@ public class EncryptedDataDecoderTest
     
     
     /**
+     * Test the decoding of a EncryptedData with a missing type
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncryptedDataMissingEType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+        
+        stream.put( new byte[]
+            { 
+              0x30, 0x0F,
+                (byte)0xA1, 0x03,                 // kvno
+                  0x02, 0x01, 0x05,               //
+                (byte)0xA2, 0x08,                 // cipher
+                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
+            } );
+
+        stream.flip();
+
+        // Allocate a EncryptedData Container
+        Asn1Container encryptedDataContainer = new EncryptedDataContainer();
+
+        // Decode the EncryptedData PDU
+        kerberosDecoder.decode( stream, encryptedDataContainer );
+        fail();
+    }
+    
+    
+    /**
      * Test the decoding of a EncryptedData with an empty type
      */
     @Test( expected = DecoderException.class)
@@ -239,7 +271,7 @@ public class EncryptedDataDecoderTest
         
         stream.put( new byte[]
             { 0x30, 0x04,
-                (byte)0xA0, 0x03,                 // etype
+                (byte)0xA0, 0x02,                 // etype
                   0x02, 0x00                      // 
             } );
 



Mime
View raw message