You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/11/13 11:54:23 UTC

svn commit: r1034727 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/ main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/ test/java/org/apache/directory/share...

Author: kayyagari
Date: Sat Nov 13 10:54:22 2010
New Revision: 1034727

URL: http://svn.apache.org/viewvc?rev=1034727&view=rev
Log:
o implementation of EncryptionKey codec

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyValue.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptionKeyDecoderTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyContainer.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyContainer.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,66 @@
+/*
+ *  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.encryptionKey;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+
+
+/**
+ * The EncryptionKey container stores the EncryptionKey decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptionKeyContainer extends AbstractContainer
+{
+    /** holds EncryptionKey */
+    private EncryptionKey encKey;
+
+    /**
+     * Creates a new EncryptionKeyContainer object.
+     */
+    public EncryptionKeyContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = EncryptionKeyGrammar.getInstance();
+        setTransition( EncryptionKeyStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the EncryptionKey.
+     */
+    public EncryptionKey getEncryptionKey()
+    {
+        return encKey;
+    }
+
+    
+    /**
+     * Set a EncryptionKey Object into the container
+     * 
+     * @param encKey The EncryptionKey to set.
+     */
+    public void setEncryptionKey( EncryptionKey encKey )
+    {
+        this.encKey = encKey;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyGrammar.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyGrammar.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,126 @@
+/*
+ *  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.encryptionKey;
+
+
+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.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.encryptionKey.actions.EncryptionKeyInit;
+import org.apache.directory.shared.kerberos.codec.encryptionKey.actions.EncryptionKeyKeyType;
+import org.apache.directory.shared.kerberos.codec.encryptionKey.actions.EncryptionKeyKeyValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncryptionKey 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 EncryptionKeyGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( EncryptionKeyGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. EncryptionKeyGrammar is a singleton */
+    private static Grammar instance = new EncryptionKeyGrammar();
+
+
+    /**
+     * Creates a new EncryptionKeyGrammar object.
+     */
+    private EncryptionKeyGrammar()
+    {
+        setName( EncryptionKeyGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[EncryptionKeyStatesEnum.LAST_ENCKEY_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // PaData 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncryptionKey init to EncryptionKey SEQ OF
+        // --------------------------------------------------------------------------------------------
+        // EncryptionKey         ::= SEQUENCE {
+        super.transitions[EncryptionKeyStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+            EncryptionKeyStatesEnum.START_STATE, EncryptionKeyStatesEnum.ENCKEY_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new EncryptionKeyInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncryptionKey SEQ to padata-type tag
+        // --------------------------------------------------------------------------------------------
+        // EncryptionKey         ::= SEQUENCE {
+        //       keytype     [0]
+        super.transitions[EncryptionKeyStatesEnum.ENCKEY_SEQ_STATE.ordinal()][KerberosConstants.ENCRYPTION_KEY_TYPE_TAG] = new GrammarTransition(
+            EncryptionKeyStatesEnum.ENCKEY_SEQ_STATE, EncryptionKeyStatesEnum.ENCKEY_TYPE_TAG_STATE, KerberosConstants.ENCRYPTION_KEY_TYPE_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncryptionKey type tag to padata-type
+        // --------------------------------------------------------------------------------------------
+        // EncryptionKey         ::= SEQUENCE {
+        //       keytype     [1] Int32
+        super.transitions[EncryptionKeyStatesEnum.ENCKEY_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            EncryptionKeyStatesEnum.ENCKEY_TYPE_TAG_STATE, EncryptionKeyStatesEnum.ENCKEY_TYPE_STATE, UniversalTag.INTEGER.getValue(),
+            new EncryptionKeyKeyType() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from padata-type to padata-value tag
+        // --------------------------------------------------------------------------------------------
+        // EncryptionKey         ::= SEQUENCE {
+        //          keyvalue    [2]
+        super.transitions[EncryptionKeyStatesEnum.ENCKEY_TYPE_STATE.ordinal()][KerberosConstants.ENCRYPTION_KEY_VALUE_TAG] = new GrammarTransition(
+            EncryptionKeyStatesEnum.ENCKEY_TYPE_STATE, EncryptionKeyStatesEnum.ENCKEY_VALUE_TAG_STATE, KerberosConstants.ENCRYPTION_KEY_VALUE_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from padata-value tag to padata-value
+        // --------------------------------------------------------------------------------------------
+        // EncryptionKey         ::= SEQUENCE {
+        //          keyvalue    [2] OCTET STRING
+        super.transitions[EncryptionKeyStatesEnum.ENCKEY_VALUE_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+            EncryptionKeyStatesEnum.ENCKEY_VALUE_TAG_STATE, EncryptionKeyStatesEnum.ENCKEY_VALUE_STATE, UniversalTag.OCTET_STRING.getValue(),
+            new EncryptionKeyKeyValue() );
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the EncryptionKey Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyStatesEnum.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/EncryptionKeyStatesEnum.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,112 @@
+/*
+ *  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.encryptionKey;
+
+
+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 EncryptionKey grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncryptionKeyStatesEnum implements States
+{
+    // Start
+    START_STATE,                  // 0
+    
+    ENCKEY_SEQ_STATE,           // 1
+    
+    ENCKEY_TYPE_TAG_STATE,      // 2
+    
+    ENCKEY_TYPE_STATE,          // 3
+    
+    ENCKEY_VALUE_TAG_STATE,  // 4
+    
+    ENCKEY_VALUE_STATE,      // 5
+    
+    // End
+    LAST_ENCKEY_STATE; // 6
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ENCRYPTIONKEY_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "ENCRYPTIONKEY_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_ENCKEY_STATE.ordinal() ) ? "LAST_ENCKEY_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ENCKEY_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public EncryptionKeyStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyInit.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyInit.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,83 @@
+/*
+ *  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.encryptionKey.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.encryptionKey.EncryptionKeyContainer;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the EncryptionKey object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptionKeyInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncryptionKeyInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncryptionKeyInit action.
+     */
+    public EncryptionKeyInit()
+    {
+        super( "Creates a EncryptionKey instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncryptionKeyContainer encKeyContainer = ( EncryptionKeyContainer ) container;
+
+        TLV tlv = encKeyContainer.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 ) );
+        }
+        
+        EncryptionKey encKey = new EncryptionKey();
+        encKeyContainer.setEncryptionKey( encKey );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncryptionKey created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyType.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyType.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,105 @@
+/*
+ *   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.encryptionKey.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.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.codec.encryptionKey.EncryptionKeyContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Sets the EncryptionKey's type.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptionKeyKeyType extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncryptionKeyKeyType.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Creates a new instance of EncryptionKeyKeyType.
+     */
+    public EncryptionKeyKeyType()
+    {
+        super( "EncryptionKey's keytype" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncryptionKeyContainer encKeyContainer = ( EncryptionKeyContainer ) container;
+
+        TLV tlv = encKeyContainer.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 ) );
+        }
+
+        EncryptionKey encKey = encKeyContainer.getEncryptionKey();
+        // The PaData's type is an integer
+        Value value = tlv.getValue();
+
+        try
+        {
+            int encKeyType = IntegerDecoder.parse( value );
+
+            encKey.setKeyType( EncryptionType.getTypeByValue( encKeyType ) );
+
+            if ( IS_DEBUG )
+            {
+                LOG.debug( "keytype : " + encKeyType );
+            }
+        }
+        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() );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyValue.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyValue.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptionKey/actions/EncryptionKeyKeyValue.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,98 @@
+/*
+ *  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.encryptionKey.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.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.encryptionKey.EncryptionKeyContainer;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the EncryptionKey's keyvalue
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptionKeyKeyValue extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncryptionKeyKeyValue.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncryptionKeyKeyValue action.
+     */
+    public EncryptionKeyKeyValue()
+    {
+        super( "EncryptionKey's keyvalue" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncryptionKeyContainer encKeyContainer = ( EncryptionKeyContainer ) container;
+
+        TLV tlv = encKeyContainer.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 ) );
+        }
+        
+        EncryptionKey encKey = encKeyContainer.getEncryptionKey();
+        encKey.setKeyValue( value.getData() );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "keyvalue : {}", StringTools.dumpBytes( value.getData() ) );
+        }
+        
+        encKeyContainer.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptionKeyDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptionKeyDecoderTest.java?rev=1034727&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptionKeyDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncryptionKeyDecoderTest.java Sat Nov 13 10:54:22 2010
@@ -0,0 +1,169 @@
+/*
+ *   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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+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.encryptionKey.EncryptionKeyContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.EncryptionKey;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for EncryptionKey codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncryptionKeyDecoderTest
+{
+    @Test
+    public void testDecodeEncryptionKey()
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x0F,
+                  (byte)0xA0, 0x03,                 // keytype
+                    0x02, 0x01, 0x02,
+                  (byte)0xA1, 0x08,                 // keyvalue
+                    0x04, 0x06, 'k', 'e', 'y', 'v', 'a', 'l'
+            } );
+        
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        EncryptionKeyContainer container = new EncryptionKeyContainer();
+        
+        try
+        {
+            krbDecoder.decode( stream, container );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            
+            fail( de.getMessage() );
+        }
+
+        EncryptionKey encKey = container.getEncryptionKey();
+        
+        assertEquals( EncryptionType.getTypeByValue( 2 ), encKey.getKeyType() );
+        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "keyval" ), encKey.getKeyValue() ) );
+        
+        ByteBuffer bb = ByteBuffer.allocate( encKey.computeLength() );
+        
+        try
+        {
+            bb = encKey.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x11, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeEncryptionKeyWithoutType() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0xC );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0xA,
+                  (byte)0xA1, 0x08,                 // keyvalue
+                      0x04, 0x06, 'k', 'e', 'y', 'v', 'a', 'l'
+            } );
+        
+        stream.flip();
+
+        EncryptionKeyContainer chkContainer = new EncryptionKeyContainer();
+        
+        krbDecoder.decode( stream, chkContainer );
+        fail();
+    }
+    
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeChecksumWithoutEncryptionKeyValue() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x05,
+                  (byte)0xA0, 0x03,                 // keytype
+                    0x02, 0x01, 0x02
+            } );
+        
+        stream.flip();
+
+        EncryptionKeyContainer container = new EncryptionKeyContainer();
+        
+        krbDecoder.decode( stream, container );
+        fail();
+    }
+    
+    
+    @Test( expected = DecoderException.class )
+    public void testDecodeEncryptionKeyWithEmptySeq() throws DecoderException
+    {
+        Asn1Decoder krbDecoder = new Asn1Decoder();
+        
+        ByteBuffer stream = ByteBuffer.allocate( 2 );
+
+        stream.put( new byte[]
+            { 
+                0x30, 0x0
+            } );
+        
+        stream.flip();
+
+        EncryptionKeyContainer container = new EncryptionKeyContainer();
+        
+        krbDecoder.decode( stream, container );
+        fail();
+    }
+
+}