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/06 22:37:43 UTC

svn commit: r1032157 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/ main/java/org/apache/directory/shared/kerberos/codec/ main/java/org/apache/directory/shared/kerberos/codec/actions/ main/java/org/ap...

Author: elecharny
Date: Sat Nov  6 21:37:43 2010
New Revision: 1032157

URL: http://svn.apache.org/viewvc?rev=1032157&view=rev
Log:
o Added decoder for EncryptedData
o Moved the checkNotNullLength action to a common place

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java
    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/
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDecoderTest.java
Removed:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/CheckNotNullLength.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/CheckNotNullLength.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
    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/principalName/PrincipalNameGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1032157&r1=1032156&r2=1032157&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java Sat Nov  6 21:37:43 2010
@@ -36,7 +36,12 @@ public class KerberosConstants
     public static final int TICKET_SNAME_TAG = 0xA2;
     public static final int TICKET_ENC_PART_TAG = 0xA3;
     
-    /** PrincipalName's tag */
+    /** PrincipalName's tags */
     public static final int PRINCIPAL_NAME_NAME_TYPE_TAG = 0xA0;
     public static final int PRINCIPAL_NAME_NAME_STRING_TAG = 0xA1;
+    
+    /** Encrypteddata's tags */
+    public static final int ENCRYPTED_DATA_ETYPE_TAG = 0xA0;
+    public static final int ENCRYPTED_DATA_KVNO_TAG = 0xA1;
+    public static final int ENCRYPTED_DATA_CIPHER_TAG = 0xA2;
 }

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=1032157&r1=1032156&r2=1032157&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 Sat Nov  6 21:37:43 2010
@@ -34,10 +34,10 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.util.IntegerDecoderException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
 import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameString;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameType;
-import org.apache.directory.shared.kerberos.codec.ticket.actions.CheckNotNullLength;
 import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.kerberos.messages.Ticket;
 import org.apache.directory.shared.ldap.util.StringTools;

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java?rev=1032157&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/actions/CheckNotNullLength.java Sat Nov  6 21:37:43 2010
@@ -0,0 +1,68 @@
+/*
+ *  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.actions;
+
+
+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.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An action that checks the length is not null
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CheckNotNullLength extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class );
+
+    /**
+     * Instantiates the action.
+     */
+    public CheckNotNullLength()
+    {
+        super( "Check that the lebgth is not null" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        TLV tlv = container.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 ) );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataContainer.java?rev=1032157&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataContainer.java Sat Nov  6 21:37:43 2010
@@ -0,0 +1,67 @@
+/*
+ *  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.encryptedData;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+
+
+/**
+ * The EncryptedData container stores the EncryptedData decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptedDataContainer extends AbstractContainer
+{
+    /** An EncryptedData container */
+    private EncryptedData encryptedData;
+
+    /**
+     * Creates a new EncryptedDataContainer object.
+     */
+    public EncryptedDataContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = EncryptedDataGrammar.getInstance();
+        setTransition( EncryptedDataStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the EncryptedData.
+     */
+    public EncryptedData getEncryptedData()
+    {
+        return encryptedData;
+    }
+
+    
+    /**
+     * Set a EncryptedData Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param encryptedData The EncryptedData to set.
+     */
+    public void setEncryptedData( EncryptedData encryptedData )
+    {
+        this.encryptedData = encryptedData;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java?rev=1032157&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java Sat Nov  6 21:37:43 2010
@@ -0,0 +1,318 @@
+/*
+ *  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.encryptedData;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+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.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.kerberos.components.EncryptionType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncryptedData structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class EncryptedDataGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( EncryptedDataGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. EncryptedDataGrammar is a singleton */
+    private static Grammar instance = new EncryptedDataGrammar();
+
+
+    /**
+     * Creates a new PrincipalNameGrammar object.
+     */
+    private EncryptedDataGrammar()
+    {
+        setName( EncryptedDataGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[EncryptedDataStatesEnum.LAST_ENCRYPTED_DATA_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // EncryptedData 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncryptedData init to EncryptedData SEQ
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE
+        super.transitions[EncryptedDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+            EncryptedDataStatesEnum.START_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new GrammarAction( "EncryptedData SEQUENCE" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    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 ) );
+                    }
+                    
+                    EncryptedData encryptedData = new EncryptedData();
+                    encryptedDataContainer.setEncryptedData( encryptedData );
+                    
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "EncryptedData created" );
+                    }
+                }
+            } );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncryptedData SEQ to etype tag
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         etype       [0]
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_SEQ_STATE.ordinal()][KerberosConstants.ENCRYPTED_DATA_ETYPE_TAG] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_SEQ_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_TAG_STATE, KerberosConstants.ENCRYPTED_DATA_ETYPE_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from etype tag to etype value
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         etype       [0] Int32,
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE, UniversalTag.INTEGER.getValue(),
+            new GrammarAction( "EncryptedData SEQUENCE" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    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 = null;
+                    EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+                    
+                    try
+                    {
+                        int eType = IntegerDecoder.parse( value );
+                        encryptionType = EncryptionType.getTypeByOrdinal( 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() );
+                    }
+                    
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "EncryptionType : {}", encryptionType );
+                    }
+                }
+            } );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from etype value to kvno tag
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         ...
+        //         kvno     [1]
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE.ordinal()][KerberosConstants.ENCRYPTED_DATA_KVNO_TAG] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_TAG_STATE, KerberosConstants.ENCRYPTED_DATA_KVNO_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from etype value to cipher tag (kvno is missing)
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         ...
+        //         cipher     [2]
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE.ordinal()][KerberosConstants.ENCRYPTED_DATA_CIPHER_TAG] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE, KerberosConstants.ENCRYPTED_DATA_CIPHER_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from kvno tag to kvno value
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         ...
+        //         kvno     [1] UInt32
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_STATE, UniversalTag.INTEGER.getValue(),
+            new GrammarAction( "EncryptedData kvno" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    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() );
+                    }
+                }
+            });
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from kvno value value to cipher tag
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         ...
+        //         cipher     [2]
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_STATE.ordinal()][KerberosConstants.ENCRYPTED_DATA_CIPHER_TAG] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE, KerberosConstants.ENCRYPTED_DATA_CIPHER_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from cipher tag to cipher value
+        // --------------------------------------------------------------------------------------------
+        // EncryptedData   ::= SEQUENCE {
+        //         ...
+        //         cipher     [2] OCTET STRING
+        super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+            EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_STATE, UniversalTag.OCTET_STRING.getValue(),
+            new GrammarAction( "EncryptedData SEQUENCE" )
+            {
+                public void action( Asn1Container container ) throws DecoderException
+                {
+                    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();
+                    
+                    // The encrypted data should not be null
+                    if ( value.getData() == null ) 
+                    {
+                        LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+                        // This will generate a PROTOCOL_ERROR
+                        throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+                    }
+                    
+                    EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+                    encryptedData.setCipher( value.getData() );
+                    
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "cipher : {}", StringTools.dumpBytes( value.getData() ) );
+                    }
+                    
+                    encryptedDataContainer.setGrammarEndAllowed( true );
+                }
+            } );
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the PrincipalName Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: 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=1032157&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataStatesEnum.java Sat Nov  6 21:37:43 2010
@@ -0,0 +1,117 @@
+/*
+ *  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.encryptedData;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class store the EncryptedData grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncryptedDataStatesEnum implements States
+{
+    // ~ Static fields/initializers
+    // -----------------------------------------------------------------
+
+    // Start
+    START_STATE,                            // 0
+    
+    // ----- PrincipalName message --------------------------------------
+    ENCRYPTED_DATA_SEQ_STATE,               // 1
+    
+    ENCRYPTED_DATA_ETYPE_TAG_STATE,         // 2
+    ENCRYPTED_DATA_ETYPE_STATE,             // 3
+    
+    ENCRYPTED_DATA_KVNO_TAG_STATE,          // 4
+    ENCRYPTED_DATA_KVNO_STATE,              // 5
+    
+    ENCRYPTED_DATA_CIPHER_TAG_STATE,        // 6
+    ENCRYPTED_DATA_CIPHER_STATE,            // 7
+    
+    // End
+    LAST_ENCRYPTED_DATA_STATE;              // 8
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ENCRYPTED_DATA_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "ENCRYPTED_DATA_GRAMMAR";
+        }
+        else
+        {
+            return "UNKNOWN GRAMMAR";
+        }
+    }
+
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int state )
+    {
+        return ( ( state == LAST_ENCRYPTED_DATA_STATE.ordinal() ) ? "ENCRYPTED_DATA_END_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ENCRYPTED_DATA_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public EncryptedDataStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java?rev=1032157&r1=1032156&r2=1032157&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java Sat Nov  6 21:37:43 2010
@@ -30,7 +30,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.kerberos.KerberosConstants;
-import org.apache.directory.shared.kerberos.codec.principalName.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameString;
 import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameType;
 import org.apache.directory.shared.kerberos.components.PrincipalName;

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java?rev=1032157&r1=1032156&r2=1032157&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java Sat Nov  6 21:37:43 2010
@@ -151,6 +151,7 @@ public class EncryptedData extends Abstr
     public void setKvno( int kvno )
     {
         this.kvno = kvno;
+        hasKvno = true;
     }
 
     /**

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDecoderTest.java?rev=1032157&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptedDecoderTest.java Sat Nov  6 21:37:43 2010
@@ -0,0 +1,374 @@
+/*
+ *  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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+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.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.kerberos.components.EncryptionType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the EncryptedData decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class EncryptedDecoderTest
+{
+    /**
+     * Test the decoding of a EncryptedData
+     */
+    @Test
+    public void testEncryptedData()
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x14,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x12,               //
+                (byte)0xA1, 0x03,                 // kvno
+                  0x02, 0x01, 0x05,               //
+                (byte)0xA2, 0x08,                 // cipher
+                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a EncryptedData Container
+        Asn1Container encryptedDataContainer = new EncryptedDataContainer();
+
+        // Decode the EncryptedData PDU
+        try
+        {
+            kerberosDecoder.decode( stream, encryptedDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded EncryptedData
+        EncryptedData encryptedData = ( ( EncryptedDataContainer ) encryptedDataContainer ).getEncryptedData();
+
+        assertEquals( EncryptionType.AES256_CTS_HMAC_SHA1_96, encryptedData.getEType() );
+        assertEquals( 5, encryptedData.getKvno() );
+        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "abcdef" ), encryptedData.getCipher() ) );
+
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( encryptedData.computeLength() );
+        
+        try
+        {
+            bb = encryptedData.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x16, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a EncryptedData with no kvno
+     */
+    @Test
+    public void testEncryptedDataNoKvno()
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x0F,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x12,               //
+                (byte)0xA2, 0x08,                 // cipher
+                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a EncryptedData Container
+        Asn1Container encryptedDataContainer = new EncryptedDataContainer();
+
+        // Decode the EncryptedData PDU
+        try
+        {
+            kerberosDecoder.decode( stream, encryptedDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded EncryptedData
+        EncryptedData encryptedData = ( ( EncryptedDataContainer ) encryptedDataContainer ).getEncryptedData();
+
+        assertEquals( EncryptionType.AES256_CTS_HMAC_SHA1_96, encryptedData.getEType() );
+        assertFalse( encryptedData.hasKvno() );
+        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "abcdef" ), encryptedData.getCipher() ) );
+
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( encryptedData.computeLength() );
+        
+        try
+        {
+            bb = encryptedData.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x11, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a EncryptedData with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncryptedDataEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x00 } );
+
+        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 no type
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncryptedDataNoEType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x02,
+                (byte)0xA0, 0x00                  // etype
+            } );
+
+        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)
+    public void testEncryptedDataEmptyType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0B );
+        
+        stream.put( new byte[]
+            { 0x30, 0x04,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x00                      // 
+            } );
+
+        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 kvno
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncryptedDataEmptyKvno() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x07,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x01,               // 
+                (byte)0xA1, 0x00                  // kvno
+            } );
+
+        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 no cipher
+     */
+    @Test( expected = DecoderException.class)
+    public void testEncryptedDataNoCipher() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0C );
+        
+        stream.put( new byte[]
+            { 0x30, 0x0A,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x01,               // 
+                (byte)0xA1, 0x02,                 // kvno
+                  0x02, 0x01, 0x05                //
+            } );
+
+        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 empty cipher
+     */
+    @Test( expected = DecoderException.class )
+    public void testEncryptedDataEmptyCipher() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0E );
+        
+        stream.put( new byte[]
+            { 0x30, 0x0C,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x01,               // 
+                (byte)0xA1, 0x03,                 // kvno
+                  0x02, 0x01, 0x01,               //
+                (byte)0xA2, 0x00                  // cipher
+            } );
+
+        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 a null cipher
+     */
+    @Test( expected = DecoderException.class )
+    public void testEncryptedDataNullCipher() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x10 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x0E,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x01,               // 
+                (byte)0xA1, 0x03,                 // kvno
+                  0x02, 0x01, 0x01,               //
+                (byte)0xA2, 0x02,                 // cipher
+                  0x04, 0x00
+        } );
+
+        stream.flip();
+
+        // Allocate a EncryptedData Container
+        Asn1Container encryptedDataContainer = new EncryptedDataContainer();
+
+        // Decode the EncryptedData PDU
+        kerberosDecoder.decode( stream, encryptedDataContainer );
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java?rev=1032157&r1=1032156&r2=1032157&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PrincipalNameDecoderTest.java Sat Nov  6 21:37:43 2010
@@ -85,7 +85,7 @@ public class PrincipalNameDecoderTest
             fail( de.getMessage() );
         }
 
-        // Check the decoded BindRequest
+        // Check the decoded PrincipalName
         PrincipalName principalName = ( ( PrincipalNameContainer ) principalNameContainer ).getPrincipalName();
 
         assertEquals( PrincipalNameType.KRB_NT_PRINCIPAL, principalName.getNameType() );