directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1037454 - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos: codec/krbSafe/ codec/krbSafe/actions/ messages/
Date Sun, 21 Nov 2010 14:07:55 GMT
Author: kayyagari
Date: Sun Nov 21 14:07:54 2010
New Revision: 1037454

URL: http://svn.apache.org/viewvc?rev=1037454&view=rev
Log:
o codec of KRB-SAFE message

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/CheckMsgType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/KrbSafeInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreChecksum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StorePvno.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreSafeBody.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbSafe.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeContainer.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeContainer.java
Sun Nov 21 14:07:54 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.krbSafe;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.messages.KrbSafe;
+
+
+/**
+ * The KrbSafe container stores the KRB-SAFE decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeContainer extends AbstractContainer
+{
+    /** An KRB-SAFE container */
+    private KrbSafe krbSafe;
+    
+    /**
+     * Creates a new KrbSafeContainer object.
+     */
+    public KrbSafeContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = KrbSafeGrammar.getInstance();
+        setTransition( KrbSafeStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the KrbSafe.
+     */
+    public KrbSafe getKrbSafe()
+    {
+        return krbSafe;
+    }
+
+    
+    /**
+     * Set a KrbSafe Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param krbSafe The KrbSafe to set.
+     */
+    public void setKrbSafe( KrbSafe krbSafe )
+    {
+        this.krbSafe = krbSafe;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeGrammar.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeGrammar.java
Sun Nov 21 14:07:54 2010
@@ -0,0 +1,146 @@
+/*
+ *  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.krbSafe;
+
+
+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.krbSafe.actions.CheckMsgType;
+import org.apache.directory.shared.kerberos.codec.krbSafe.actions.KrbSafeInit;
+import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StoreChecksum;
+import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StorePvno;
+import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StoreSafeBody;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the KrbSafe 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 KrbSafeGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( KrbSafeGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. KrbSafeGrammar is a singleton */
+    private static Grammar instance = new KrbSafeGrammar();
+
+
+    /**
+     * Creates a new KrbSafeGrammar object.
+     */
+    private KrbSafeGrammar()
+    {
+        setName( KrbSafeGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[KrbSafeStatesEnum.LAST_KRB_SAFE_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // KrbSafe 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbSafe init to KrbSafe tag
+        // --------------------------------------------------------------------------------------------
+        // KRB-SAFE       ::= [APPLICATION 20]
+        super.transitions[KrbSafeStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_SAFE_TAG]
= new GrammarTransition(
+            KrbSafeStatesEnum.START_STATE, KrbSafeStatesEnum.KRB_SAFE_TAG_STATE, KerberosConstants.KRB_SAFE_TAG,
+            new KrbSafeInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbSafe tag to KrbSafe SEQ
+        // --------------------------------------------------------------------------------------------
+        // KRB-SAFE       ::= [APPLICATION 20] SEQUENCE {
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_TAG_STATE, KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from KrbSafe SEQ to pvno tag
+        // --------------------------------------------------------------------------------------------
+        // KRB-SAFE         ::= SEQUENCE {
+        //         pvno            [0]
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE.ordinal()][KerberosConstants.KRB_SAFE_PVNO_TAG]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE, KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE,
KerberosConstants.KRB_SAFE_PVNO_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno tag to pvno value
+        // --------------------------------------------------------------------------------------------
+        // KRB-SAFE         ::= SEQUENCE {
+        //         pvno            [0] INTEGER (5) ,
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE, KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE,
UniversalTag.INTEGER.getValue(),
+            new StorePvno() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno to msg-type tag
+        // --------------------------------------------------------------------------------------------
+        // msg-type        [1]
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE.ordinal()][KerberosConstants.KRB_SAFE_MSGTYPE_TAG]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE, KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE,
KerberosConstants.KRB_SAFE_MSGTYPE_TAG, 
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type tag to msg-type value
+        // --------------------------------------------------------------------------------------------
+        // msg-type        [1] INTEGER (30)
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE, KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE,
UniversalTag.INTEGER.getValue(), 
+            new CheckMsgType() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type value to safe-body tag
+        // --------------------------------------------------------------------------------------------
+        // safe-body       [2] KRB-SAFE-BODY
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE.ordinal()][KerberosConstants.KRB_SAFE_SAFE_BODY_TAG]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE, KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE,
KerberosConstants.KRB_SAFE_SAFE_BODY_TAG, 
+            new StoreSafeBody() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from safe-body tag to cksum tag
+        // --------------------------------------------------------------------------------------------
+        // cksum           [3] Checksum
+        super.transitions[KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE.ordinal()][KerberosConstants.KRB_SAFE_CKSUM_TAG]
= new GrammarTransition(
+            KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE, KrbSafeStatesEnum.KRB_SAFE_CKSUM_TAG_STATE,
KerberosConstants.KRB_SAFE_CKSUM_TAG, 
+            new StoreChecksum() );
+    }
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the KRB-SAFE Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeStatesEnum.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/KrbSafeStatesEnum.java
Sun Nov 21 14:07:54 2010
@@ -0,0 +1,116 @@
+/*
+ *  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.krbSafe;
+
+
+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-SAFE grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum KrbSafeStatesEnum implements States
+{
+    // Start
+    START_STATE,                       // 0
+    
+    // ----- KRB-SAFE component --------------------------------------
+    KRB_SAFE_TAG_STATE,               // 1
+    
+    KRB_SAFE_SEQ_STATE,           // 2
+    
+    KRB_SAFE_PVNO_TAG_STATE,          // 3
+    KRB_SAFE_PVNO_STATE,              // 4
+    
+    KRB_SAFE_MSGTYPE_TAG_STATE,       // 5
+    KRB_SAFE_MSGTYPE_STATE,           // 6
+    
+    KRB_SAFE_SAFE_BODY_TAG_STATE,     // 7
+    KRB_SAFE_CKSUM_TAG_STATE,         // 8
+    
+    // End
+    LAST_KRB_SAFE_STATE;              // 9
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "KRB_SAFE_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_SAFE_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_SAFE_STATE.ordinal() ) ? "LAST_KRB_SAFE_STATE" : name()
);
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_KRB_SAFE_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public KrbSafeStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/CheckMsgType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/CheckMsgType.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/CheckMsgType.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/CheckMsgType.java
Sun Nov 21 14:07:54 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.krbSafe.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-SAFE 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_SAFE )
+        {
+            String msg = "The msg-type should be KRB-SAFE";
+            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/krbSafe/actions/KrbSafeInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/KrbSafeInit.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/KrbSafeInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/KrbSafeInit.java
Sun Nov 21 14:07:54 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.krbSafe.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.krbSafe.KrbSafeContainer;
+import org.apache.directory.shared.kerberos.messages.KrbSafe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the KrbSafe object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafeInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KrbSafeInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new KrbSafeInit action.
+     */
+    public KrbSafeInit()
+    {
+        super( "Creates a KrbSafe instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KrbSafeContainer krbSafeContainer = ( KrbSafeContainer ) container;
+
+        TLV tlv = krbSafeContainer.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 ) );
+        }
+        
+        KrbSafe krbSafe = new KrbSafe();
+        krbSafeContainer.setKrbSafe( krbSafe );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KrbSafe created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreChecksum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreChecksum.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreChecksum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreChecksum.java
Sun Nov 21 14:07:54 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.krbSafe.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadCheckSum;
+import org.apache.directory.shared.kerberos.codec.krbSafe.KrbSafeContainer;
+import org.apache.directory.shared.kerberos.components.Checksum;
+
+
+/**
+ * The action used to set the KrbSafe cksum
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreChecksum extends AbstractReadCheckSum
+{
+
+    /**
+     * Instantiates a new StoreChecksum action.
+     */
+    public StoreChecksum()
+    {
+        super( "KRB-SAFE cksum" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setChecksum( Checksum checksum, Asn1Container container )
+    {
+        KrbSafeContainer krbSafeContainer = ( KrbSafeContainer ) container;
+        krbSafeContainer.getKrbSafe().setChecksum( checksum );
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StorePvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StorePvno.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StorePvno.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StorePvno.java
Sun Nov 21 14:07:54 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.krbSafe.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.krbSafe.KrbSafeContainer;
+
+
+/**
+ * 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-SAFE pvno" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setPvno( int pvno, Asn1Container container )
+    {
+        KrbSafeContainer krbSafeContainer = ( KrbSafeContainer ) container;
+        krbSafeContainer.getKrbSafe().setProtocolVersionNumber( pvno );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreSafeBody.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreSafeBody.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreSafeBody.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafe/actions/StoreSafeBody.java
Sun Nov 21 14:07:54 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.krbSafe.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+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.krbSafe.KrbSafeContainer;
+import org.apache.directory.shared.kerberos.codec.krbSafeBody.KrbSafeBodyContainer;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to read the KrbSafeBody
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSafeBody extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreSafeBody.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreSafeBody action.
+     */
+    public StoreSafeBody()
+    {
+        super( "KRB-SAFE safe-body" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        KrbSafeContainer krbSafeContainer = ( KrbSafeContainer ) container;
+        
+        TLV tlv = krbSafeContainer.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 ) );
+        }
+        
+        // Now, let's decode the HostAddress
+        Asn1Decoder krbSafeBodyDecoder = new Asn1Decoder();
+        
+        KrbSafeBodyContainer krbSafeBodyContainer = new KrbSafeBodyContainer();
+        
+        // Passes the Stream to the decoder
+        krbSafeBodyContainer.setStream( container.getStream() );
+
+        // Decode the KrbSafeBody PDU
+        try
+        {
+            krbSafeBodyDecoder.decode( container.getStream(), krbSafeBodyContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+
+        // Store the KrbSafeBody in the container
+        KrbSafeBody krbSafeBody = krbSafeBodyContainer.getKrbSafeBody();
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "KrbSafeBody : {}", krbSafeBody );
+        }
+        
+        krbSafeContainer.getKrbSafe().setSafeBody( krbSafeBody );
+        
+        
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbSafe.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbSafe.java?rev=1037454&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbSafe.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/KrbSafe.java
Sun Nov 21 14:07:54 2010
@@ -0,0 +1,218 @@
+/*
+ *   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.Checksum;
+import org.apache.directory.shared.kerberos.components.KrbSafeBody;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * KRB-SAFE        ::= [APPLICATION 20] SEQUENCE {
+ *      pvno            [0] INTEGER (5),
+ *      msg-type        [1] INTEGER (20),
+ *      safe-body       [2] KRB-SAFE-BODY,
+ *      cksum           [3] Checksum
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbSafe extends KerberosMessage
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( KrbError.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** body of this message */
+    private KrbSafeBody krbSafeBody;
+
+    /** the checksum */
+    private Checksum checksum;
+
+    // Storage for computed lengths
+    private transient int pvnoLen;
+    private transient int msgTypeLength;
+    private transient int krbSafeBodyLen;
+    private transient int checksumLen;
+    private transient int krbSafeSeqLen;
+    private transient int krbSafeLen;
+
+
+    /**
+     * Creates a new instance of KrbSafe.
+     */
+    public KrbSafe()
+    {
+        super( 5, KerberosMessageType.KRB_SAFE );
+    }
+
+
+    /**
+     * 0x14 L1 KRB-SAFE APPLICATION[20]
+     *  |
+     *  +--> 0x30 L2 KRB-ERROR sequence
+     *        |
+     *        +--> 0xA0 0x03 pvno tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x05 pvno (5)
+     *        |
+     *        +--> 0xA1 0x03 msg-type tag
+     *        |     |
+     *        |     +--> 0x02 0x01 0x14 msg-type (20)
+     *        |     
+     *        +--> 0xA2 L3 safe-body tag
+     *        |     |
+     *        |     +--> 0x30 L3-1 safe-body (krb-safe-body)
+     *        |
+     *        +--> 0xA3 L4 cksum tag
+     *              |
+     *              +--> 0x30 L4-1 cksum (checksum)
+     */
+    @Override
+    public int computeLength()
+    {
+        pvnoLen = 1 + 1 + 1;
+        krbSafeSeqLen = 1 + TLV.getNbBytes( pvnoLen ) + pvnoLen;
+
+        msgTypeLength = 1 + 1 + Value.getNbBytes( getMessageType().getValue() );
+        krbSafeSeqLen += 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength;
+
+        krbSafeBodyLen = krbSafeBody.computeLength();
+        krbSafeSeqLen += 1 + TLV.getNbBytes( krbSafeBodyLen ) + krbSafeBodyLen;
+
+        checksumLen = checksum.computeLength();
+        krbSafeSeqLen += 1 + TLV.getNbBytes( checksumLen ) + checksumLen;
+
+        krbSafeLen = 1 + TLV.getNbBytes( krbSafeSeqLen ) + krbSafeSeqLen;
+
+        return 1 + TLV.getNbBytes( krbSafeLen ) + krbSafeLen;
+    }
+
+
+    /**
+     * {@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_SAFE_TAG );
+            buffer.put( TLV.getBytes( krbSafeLen ) );
+
+            // The KRB-SAFE sequence
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( krbSafeSeqLen ) );
+
+            // pvno tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_PVNO_TAG );
+            buffer.put( TLV.getBytes( pvnoLen ) );
+            Value.encode( buffer, getProtocolVersionNumber() );
+
+            // msg-type tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_MSGTYPE_TAG );
+            buffer.put( TLV.getBytes( msgTypeLength ) );
+            Value.encode( buffer, getMessageType().getValue() );
+
+            // safe-body tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_SAFE_BODY_TAG );
+            buffer.put( TLV.getBytes( krbSafeBodyLen ) );
+            krbSafeBody.encode( buffer );
+
+            // cksum tag and value
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_CKSUM_TAG );
+            buffer.put( TLV.getBytes( checksumLen ) );
+            checksum.encode( buffer );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( I18n.err( I18n.ERR_736_CANNOT_ENCODE_KRBSAFE, 1 + TLV.getNbBytes(
krbSafeSeqLen )
+                + krbSafeSeqLen, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "KrbSafe encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            log.debug( "KrbSafe initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @return the krbSafeBody
+     */
+    public KrbSafeBody getSafeBody()
+    {
+        return krbSafeBody;
+    }
+
+
+    /**
+     * @param safeBody the KrbSafeBody to set
+     */
+    public void setSafeBody( KrbSafeBody safeBody )
+    {
+        this.krbSafeBody = safeBody;
+    }
+
+
+    /**
+     * @return the checksum
+     */
+    public Checksum getChecksum()
+    {
+        return checksum;
+    }
+
+
+    /**
+     * @param checksum the checksum to set
+     */
+    public void setChecksum( Checksum checksum )
+    {
+        this.checksum = checksum;
+    }
+
+}



Mime
View raw message