directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1037843 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/krbPriv/ main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/ main/java/org/apache/directory/shared/kerberos/m...
Date Mon, 22 Nov 2010 19:17:56 GMT
Author: kayyagari
Date: Mon Nov 22 19:17:55 2010
New Revision: 1037843

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

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/CheckMsgType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/KrbPrivInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StoreEncPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StorePvno.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbPriv.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbPrivDecoderTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivContainer.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivContainer.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,69 @@
+/*
+ *  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.krbPriv;
+
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.messages.KrbPriv;
+
+
+/**
+ * The KrbPriv container stores the KRB-PRIV decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbPrivContainer extends AbstractContainer
+{
+    /** An KRB-PRIV container */
+    private KrbPriv krbPriv;
+
+
+    /**
+     * Creates a new KrbSafeContainer object.
+     */
+    public KrbPrivContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = KrbPrivGrammar.getInstance();
+        setTransition( KrbPrivStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the KrbPriv.
+     */
+    public KrbPriv getKrbPriv()
+    {
+        return krbPriv;
+    }
+
+
+    /**
+     * Set a KrbPriv Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param krbPriv The KrbPriv to set.
+     */
+    public void setKrbPriv( KrbPriv krbPriv )
+    {
+        this.krbPriv = krbPriv;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivGrammar.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivGrammar.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,137 @@
+/*
+ *  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.krbPriv;
+
+
+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.krbPriv.actions.CheckMsgType;
+import org.apache.directory.shared.kerberos.codec.krbPriv.actions.KrbPrivInit;
+import org.apache.directory.shared.kerberos.codec.krbPriv.actions.StoreEncPart;
+import org.apache.directory.shared.kerberos.codec.krbPriv.actions.StorePvno;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the KRB-PRIV 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 KrbPrivGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( KrbPrivGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. KrbPrivGrammar is a singleton */
+    private static Grammar instance = new KrbPrivGrammar();
+
+
+    /**
+     * Creates a new KrbPrivGrammar object.
+     */
+    private KrbPrivGrammar()
+    {
+        setName( KrbPrivGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[KrbPrivStatesEnum.LAST_KRB_PRIV_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // KRB_PRIV 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbPriv init to KrbPriv tag
+        // --------------------------------------------------------------------------------------------
+        // KRB_PRIV       ::= [APPLICATION 21]
+        super.transitions[KrbPrivStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_PRIV_TAG]
= new GrammarTransition(
+            KrbPrivStatesEnum.START_STATE, KrbPrivStatesEnum.KRB_PRIV_TAG_STATE, KerberosConstants.KRB_PRIV_TAG,
+            new KrbPrivInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbPriv tag to KrbPriv SEQ
+        // --------------------------------------------------------------------------------------------
+        // KRB_PRIV       ::= [APPLICATION 21] SEQUENCE {
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_TAG_STATE, KrbPrivStatesEnum.KRB_PRIV_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbPriv SEQ to pvno tag
+        // --------------------------------------------------------------------------------------------
+        // KRB_PRIV         ::= SEQUENCE {
+        //         pvno            [0]
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_SEQ_STATE.ordinal()][KerberosConstants.KRB_PRIV_PVNO_TAG]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_SEQ_STATE, KrbPrivStatesEnum.KRB_PRIV_PVNO_TAG_STATE,
KerberosConstants.KRB_PRIV_PVNO_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno tag to pvno value
+        // --------------------------------------------------------------------------------------------
+        // KRB_PRIV         ::= SEQUENCE {
+        //         pvno            [0] INTEGER (5) ,
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_PVNO_TAG_STATE, KrbPrivStatesEnum.KRB_PRIV_PVNO_STATE,
UniversalTag.INTEGER.getValue(),
+            new StorePvno() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno to msg-type tag
+        // --------------------------------------------------------------------------------------------
+        // msg-type        [1]
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_PVNO_STATE.ordinal()][KerberosConstants.KRB_PRIV_MSGTYPE_TAG]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_PVNO_STATE, KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_TAG_STATE,
KerberosConstants.KRB_PRIV_MSGTYPE_TAG, 
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type tag to msg-type value
+        // --------------------------------------------------------------------------------------------
+        // msg-type        [1] INTEGER (30)
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_TAG_STATE, KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_STATE,
UniversalTag.INTEGER.getValue(), 
+            new CheckMsgType() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type value to enc-part tag
+        // --------------------------------------------------------------------------------------------
+        // enc-part       [3] [3] EncryptedData -- EncKrbPrivPart
+        super.transitions[KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_STATE.ordinal()][KerberosConstants.KRB_PRIV_ENC_PART_TAG]
= new GrammarTransition(
+            KrbPrivStatesEnum.KRB_PRIV_MSGTYPE_STATE, KrbPrivStatesEnum.KRB_PRIV_EN_PART_TAG_STATE,
KerberosConstants.KRB_PRIV_ENC_PART_TAG, 
+            new StoreEncPart() );
+    }
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the KRB_PRIV Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivStatesEnum.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/KrbPrivStatesEnum.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,115 @@
+/*
+ *  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.krbPriv;
+
+
+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 stores the KRB-PRIV grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum KrbPrivStatesEnum implements States
+{
+    // Start
+    START_STATE,                       // 0
+    
+    // ----- KRB-SAFE component --------------------------------------
+    KRB_PRIV_TAG_STATE,               // 1
+    
+    KRB_PRIV_SEQ_STATE,               // 2
+    
+    KRB_PRIV_PVNO_TAG_STATE,          // 3
+    KRB_PRIV_PVNO_STATE,              // 4
+    
+    KRB_PRIV_MSGTYPE_TAG_STATE,       // 5
+    KRB_PRIV_MSGTYPE_STATE,           // 6
+    
+    KRB_PRIV_EN_PART_TAG_STATE,       // 7
+    
+    // End
+    LAST_KRB_PRIV_STATE;              // 8
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "KRB_PRIV_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "KRB_PRIV_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_KRB_PRIV_STATE.ordinal() ) ? "LAST_KRB_PRIV_STATE" : name()
);
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_KRB_PRIV_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public KrbPrivStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/CheckMsgType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/CheckMsgType.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/CheckMsgType.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/CheckMsgType.java
Mon Nov 22 19:17:55 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.krbPriv.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadMsgType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the msg-type
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CheckMsgType extends AbstractReadMsgType
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( CheckMsgType.class );
+
+
+    /**
+     * Instantiates a new CheckMsgType action.
+     */
+    public CheckMsgType()
+    {
+        super( "KRB-PRIV msg-type" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void verifyMsgType( KerberosMessageType krbMsgType, Asn1Container container
) throws DecoderException
+    {
+        // The message type must be the expected one
+        if ( krbMsgType != KerberosMessageType.KRB_PRIV )
+        {
+            String msg = "The msg-type should be KRB-PRIV";
+            LOG.error( I18n.err( I18n.ERR_04070, krbMsgType, msg ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( msg );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/KrbPrivInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/KrbPrivInit.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/KrbPrivInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/KrbPrivInit.java
Mon Nov 22 19:17:55 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.krbPriv.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.krbPriv.KrbPrivContainer;
+import org.apache.directory.shared.kerberos.messages.KrbPriv;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the KrbPriv object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbPrivInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KrbPrivInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new KrbPrivInit action.
+     */
+    public KrbPrivInit()
+    {
+        super( "Creates a KrbPriv instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KrbPrivContainer krbPrivContainer = ( KrbPrivContainer ) container;
+
+        TLV tlv = krbPrivContainer.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 ) );
+        }
+        
+        KrbPriv krbPriv = new KrbPriv();
+        krbPrivContainer.setKrbPriv( krbPriv );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KrbPriv created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StoreEncPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StoreEncPart.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StoreEncPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StoreEncPart.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,57 @@
+/*
+ *  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.krbPriv.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadEncryptedPart;
+import org.apache.directory.shared.kerberos.codec.krbPriv.KrbPrivContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+
+
+/**
+ * The action used to read the EncryptedData
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEncPart extends AbstractReadEncryptedPart
+{
+
+    /**
+     * Instantiates a new StoreEncPart action.
+     */
+    public StoreEncPart()
+    {
+        super( "KRB-PRIV enc-part" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setEncryptedData( EncryptedData encryptedData, Asn1Container container
)
+    {
+        KrbPrivContainer krbPrivContainer = ( KrbPrivContainer ) container;
+        krbPrivContainer.getKrbPriv().setEncPart( encryptedData );
+
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StorePvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StorePvno.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StorePvno.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbPriv/actions/StorePvno.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,55 @@
+/*
+ *  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.krbPriv.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadPvno;
+import org.apache.directory.shared.kerberos.codec.krbPriv.KrbPrivContainer;
+
+
+/**
+ * The action used to store the PVNO
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StorePvno extends AbstractReadPvno
+{
+
+    /**
+     * Instantiates a new StorePvno action.
+     */
+    public StorePvno()
+    {
+        super( "KRB-PRIV pvno" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setPvno( int pvno, Asn1Container container )
+    {
+        KrbPrivContainer krbPrivContainer = ( KrbPrivContainer ) container;
+        krbPrivContainer.getKrbPriv().setProtocolVersionNumber( pvno );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbPriv.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbPriv.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbPriv.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbPriv.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,198 @@
+/*
+ *   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.messages;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+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.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * KRB-PRIV        ::= [APPLICATION 21] SEQUENCE {
+ *      pvno            [0] INTEGER (5),
+ *      msg-type        [1] INTEGER (21),
+ *                      -- NOTE: there is no [2] tag
+ *      enc-part        [3] EncryptedData -- EncKrbPrivPart
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbPriv extends KerberosMessage
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( KrbError.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** the encrypted EncKrbPrivPart component */
+    private EncryptedData encPart;
+
+    // Storage for computed lengths
+    private transient int pvnoLen;
+    private transient int msgTypeLength;
+    private transient int encPartLen;
+    private transient int krbPrivSeqLen;
+    private transient int krbPrivLen;
+
+
+    public KrbPriv()
+    {
+        super( 5, KerberosMessageType.KRB_PRIV );
+    }
+
+
+    /**
+     * Compute the KRB-PRIV length
+     * <pre>
+     * KRB-PRIV :
+     * 
+     * 0x75 L1 KRB-PRIV APPLICATION[21]
+     *  |
+     *  +--> 0x30 L2 KRB-PRIV sequence
+     *        |
+     *        +--> 0xA0 0x03 pvno tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x05 pvno (5)
+     *        |
+     *        +--> 0xA1 0x03 msg-type tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x15 msg-type (21)
+     *        |     
+     *        +--> 0xA3 L3 enc-part (EncryptedData -- EncKrbPrivPart)
+     */
+    @Override
+    public int computeLength()
+    {
+        pvnoLen = 1 + 1 + 1;
+        krbPrivSeqLen = 1 + TLV.getNbBytes( pvnoLen ) + pvnoLen;
+
+        msgTypeLength = 1 + 1 + Value.getNbBytes( getMessageType().getValue() );
+        krbPrivSeqLen += 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength;
+
+        encPartLen = encPart.computeLength();
+        krbPrivSeqLen += 1 + TLV.getNbBytes( encPartLen ) + encPartLen;
+
+        krbPrivLen += 1 + TLV.getNbBytes( krbPrivSeqLen ) + krbPrivSeqLen;
+
+        return 1 + TLV.getNbBytes( krbPrivLen ) + krbPrivLen;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            // The KRB-SAFE APPLICATION tag
+            buffer.put( ( byte ) KerberosConstants.KRB_PRIV_TAG );
+            buffer.put( TLV.getBytes( krbPrivLen ) );
+
+            // The KRB-SAFE sequence
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( krbPrivSeqLen ) );
+
+            // pvno tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_PRIV_PVNO_TAG );
+            buffer.put( TLV.getBytes( pvnoLen ) );
+            Value.encode( buffer, getProtocolVersionNumber() );
+
+            // msg-type tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_PRIV_MSGTYPE_TAG );
+            buffer.put( TLV.getBytes( msgTypeLength ) );
+            Value.encode( buffer, getMessageType().getValue() );
+
+            // enc-part
+            buffer.put( ( byte ) KerberosConstants.KRB_PRIV_ENC_PART_TAG );
+            buffer.put( TLV.getBytes( encPartLen ) );
+            encPart.encode( buffer );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( I18n.err( I18n.ERR_738_CANNOT_ENCODE_KRB_PRIV, 1 + TLV.getNbBytes(
krbPrivLen )
+                + krbPrivLen, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "KrbPriv encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            log.debug( "KrbPriv initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @return the encPart
+     */
+    public EncryptedData getEncPart()
+    {
+        return encPart;
+    }
+
+
+    /**
+     * @param encPart the encPart to set
+     */
+    public void setEncPart( EncryptedData encPart )
+    {
+        this.encPart = encPart;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "KRB-PRIV : {\n" );
+        sb.append( "    pvno: " ).append( getProtocolVersionNumber() ).append( '\n' );
+        sb.append( "    msgType: " ).append( getMessageType() ).append( '\n' );
+        sb.append( "    msgType: " ).append( getEncPart() ).append( '\n' );
+        sb.append( "}\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbPrivDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbPrivDecoderTest.java?rev=1037843&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbPrivDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbPrivDecoderTest.java
Mon Nov 22 19:17:55 2010
@@ -0,0 +1,104 @@
+/*
+ *   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.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+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.KerberosMessageType;
+import org.apache.directory.shared.kerberos.codec.krbPriv.KrbPrivContainer;
+import org.apache.directory.shared.kerberos.messages.KrbPriv;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for KrbPriv codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbPrivDecoderTest
+{
+    @Test
+    public void testKrbPrivDecoderTest() throws Exception
+    {
+        byte[] data = new byte[]{
+            0x75, 0x1B,
+              0x30, 0x19,
+               (byte)0xA0, 0x03,        // pvno
+                      0x02, 0x01, 0x05,
+               (byte)0xA1, 0x03,        // msg-type
+                      0x02, 0x01, 0x15,
+               (byte)0xA3, 0x0D,
+                      0x30, 0x0B,
+                       (byte)0xA0, 0x03,
+                              0x02, 0x01, 0x03,
+                       (byte)0xA2, 0x04,
+                              0x04, 0x02, 0x00, 0x01 
+        };
+
+        int streamLen = data.length;
+        ByteBuffer stream = ByteBuffer.wrap( data );
+        
+        String decoded = StringTools.dumpBytes( stream.array() );
+        
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        KrbPrivContainer container = new  KrbPrivContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        KrbPriv krbPriv = container.getKrbPriv();
+        
+        assertEquals( 5, krbPriv.getProtocolVersionNumber() );
+        assertEquals( KerberosMessageType.KRB_PRIV, krbPriv.getMessageType() );
+        assertNotNull( krbPriv.getEncPart() );
+        
+        int encodedLen = krbPriv.computeLength();
+        assertEquals( streamLen, encodedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( encodedLen );
+            krbPriv.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+}



Mime
View raw message