directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1036559 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/apRep/ main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ main/java/org/apache/directory/shared/kerberos/codec...
Date Thu, 18 Nov 2010 17:57:29 GMT
Author: elecharny
Date: Thu Nov 18 17:57:29 2010
New Revision: 1036559

URL: http://svn.apache.org/viewvc?rev=1036559&view=rev
Log:
Added the AP-REP codec

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ApRepInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/CheckMsgType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StoreEncPart.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StorePvno.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ApRepDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apReq/ApReqStatesEnum.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepContainer.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepContainer.java
Thu Nov 18 17:57:29 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.apRep;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+
+
+/**
+ * The AP-REP container.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ApRepContainer extends KdcReqContainer
+{
+    /** An AP-REP container */
+    private ApRep apRep;
+
+    /**
+     * Creates a new ApRepContainer object.
+     */
+    public ApRepContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = ApRepGrammar.getInstance();
+        setTransition( ApRepStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the ApRep.
+     */
+    public ApRep getApRep()
+    {
+        return apRep;
+    }
+
+    
+    /**
+     * Set an ApRep Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param apRep The ApRep to set.
+     */
+    public void setApRep( ApRep apRep )
+    {
+        this.apRep = apRep;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepGrammar.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepGrammar.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,145 @@
+/*
+ *  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.apRep;
+
+
+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.apRep.actions.ApRepInit;
+import org.apache.directory.shared.kerberos.codec.apRep.actions.CheckMsgType;
+import org.apache.directory.shared.kerberos.codec.apRep.actions.StoreEncPart;
+import org.apache.directory.shared.kerberos.codec.apRep.actions.StorePvno;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the AP-REP 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 ApRepGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( ApRepGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. ApRepGrammar is a singleton */
+    private static Grammar instance = new ApRepGrammar();
+
+
+    /**
+     * Creates a new ApRepGrammar object.
+     */
+    private ApRepGrammar()
+    {
+        setName( ApRepGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[ApRepStatesEnum.LAST_AP_REP_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // AP-REP 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from AP-REP init to AP-REP tag
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15]
+        super.transitions[ApRepStatesEnum.START_STATE.ordinal()][KerberosConstants.AP_REP_TAG]
= new GrammarTransition(
+            ApRepStatesEnum.START_STATE, ApRepStatesEnum.AP_REP_STATE, KerberosConstants.AP_REP_TAG,
+            new ApRepInit() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from AP-REP tag to AP-REP SEQUENCE
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        super.transitions[ApRepStatesEnum.AP_REP_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_STATE, ApRepStatesEnum.AP_REP_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from AP-REP SEQUENCE to pvno tag
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        //        pvno            [0]
+        super.transitions[ApRepStatesEnum.AP_REP_SEQ_STATE.ordinal()][KerberosConstants.AP_REP_PVNO_TAG]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_SEQ_STATE, ApRepStatesEnum.AP_REP_PVNO_TAG_STATE, KerberosConstants.AP_REP_PVNO_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno tag to pvno value
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        //        pvno            [0] INTEGER (5),
+        super.transitions[ApRepStatesEnum.AP_REP_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_PVNO_TAG_STATE, ApRepStatesEnum.AP_REP_PVNO_STATE, UniversalTag.INTEGER.getValue(),
+            new StorePvno() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from pvno value to msg-type tag
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        //        ...
+        //        msg-type        [1]
+        super.transitions[ApRepStatesEnum.AP_REP_PVNO_STATE.ordinal()][KerberosConstants.AP_REP_MSG_TYPE_TAG]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_PVNO_STATE, ApRepStatesEnum.AP_REP_MSG_TYPE_TAG_STATE,
KerberosConstants.AP_REP_MSG_TYPE_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type tag to msg-type value
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        //        ...
+        //        msg-type        [1] INTEGER (15),
+        super.transitions[ApRepStatesEnum.AP_REP_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_MSG_TYPE_TAG_STATE, ApRepStatesEnum.AP_REP_MSG_TYPE_STATE,
UniversalTag.INTEGER.getValue(),
+            new CheckMsgType() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from msg-type value to enc-part
+        // --------------------------------------------------------------------------------------------
+        // AP-REP          ::= [APPLICATION 15] SEQUENCE OF {
+        //        ...
+        //        enc-part        [2] EncryptedData -- EncAPRepPart
+        // }
+        super.transitions[ApRepStatesEnum.AP_REP_MSG_TYPE_STATE.ordinal()][KerberosConstants.AP_REP_ENC_PART_TAG]
= new GrammarTransition(
+            ApRepStatesEnum.AP_REP_MSG_TYPE_STATE, ApRepStatesEnum.AP_REP_ENC_PART_STATE,
KerberosConstants.AP_REP_ENC_PART_TAG,
+            new StoreEncPart() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the AP-REP Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepStatesEnum.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/ApRepStatesEnum.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,114 @@
+/*
+ *  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.apRep;
+
+
+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 AP-REP grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum ApRepStatesEnum implements States
+{
+    // Start
+    START_STATE,                            // 0
+    
+    // ----- AP-REP message --------------------------------------
+    AP_REP_STATE,                           // 1
+    AP_REP_SEQ_STATE,                       // 2
+    
+    AP_REP_PVNO_TAG_STATE,                  // 3
+    AP_REP_PVNO_STATE,                      // 4
+    
+    AP_REP_MSG_TYPE_TAG_STATE,              // 5
+    AP_REP_MSG_TYPE_STATE,                  // 6
+    
+    AP_REP_ENC_PART_STATE,                  // 7
+    
+    // End
+    LAST_AP_REP_STATE;                      // 8
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "AP_REP_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "AP_REP_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_AP_REP_STATE.ordinal() ) ? "AP_REP_END_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_AP_REP_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public ApRepStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ApRepInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ApRepInit.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ApRepInit.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/ApRepInit.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,77 @@
+/*
+ *  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.apRep.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.apRep.ApRepContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the AP-REP object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ApRepInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /**
+     * Instantiates a new ApRepInit action.
+     */
+    public ApRepInit()
+    {
+        super( "AP-REP initialization" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        ApRepContainer apRepContainer = ( ApRepContainer ) container;
+
+        TLV tlv = apRepContainer.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 ) );
+        }
+        
+        // Create the AP-REP now
+        ApRep apRep = new ApRep();
+        
+        apRepContainer.setApRep( apRep );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/CheckMsgType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/CheckMsgType.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/CheckMsgType.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/CheckMsgType.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,71 @@
+/*
+ *  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.apRep.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.apache.directory.shared.kerberos.codec.apRep.ApRepContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+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( "AP-REP msg-type" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void verifyMsgType( KerberosMessageType krbMsgType, Asn1Container container
) throws DecoderException
+    {
+        ApRepContainer apRepContainer = ( ApRepContainer ) container;
+        ApRep apRep = apRepContainer.getApRep();
+
+        // The message type must be the expected one
+        if ( krbMsgType != apRep.getMessageType() )
+        {
+            LOG.error( I18n.err( I18n.ERR_04070, krbMsgType, "The msg-type should be AP-REP"
) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( "The msg-type should be AP-REP" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StoreEncPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StoreEncPart.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StoreEncPart.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StoreEncPart.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,113 @@
+/*
+ *  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.apRep.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.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.apRep.ApRepContainer;
+import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to set the AP-REP enc-part
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEncPart extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreEncPart action.
+     */
+    public StoreEncPart()
+    {
+        super( "EncPart" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        ApRepContainer apRepContainer = ( ApRepContainer ) container;
+
+        TLV tlv = apRepContainer.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 EncPart
+        Asn1Decoder encryptedDataDecoder = new Asn1Decoder();
+        
+        EncryptedDataContainer encryptedDataContainer = new EncryptedDataContainer();
+        encryptedDataContainer.setStream( container.getStream() );
+
+        // Decode the EncPart PDU
+        try
+        {
+            encryptedDataDecoder.decode( container.getStream(), encryptedDataContainer );
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+
+        EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+        ApRep apRep = apRepContainer.getApRep();
+        apRep.setEncPart( encryptedData );
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncPart : {}", StringTools.dumpBytes( encryptedData.getCipher() )
);
+        }
+
+        // Update the TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StorePvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StorePvno.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StorePvno.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apRep/actions/StorePvno.java
Thu Nov 18 17:57:29 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.apRep.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.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.apRep.ApRepContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to set the AP-REP VNO
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StorePvno extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StorePvno action.
+     */
+    public StorePvno()
+    {
+        super( "StorePvno value" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        ApRepContainer apRepContainer = ( ApRepContainer ) container;
+
+        TLV tlv = apRepContainer.getCurrentTLV();
+
+        // The Length should not be null
+        if ( tlv.getLength() == 0 )
+        {
+            LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+        }
+        
+        // The value should be an integer an equal to 5
+        Value value = tlv.getValue();
+        ApRep apRep = apRepContainer.getApRep();
+
+        try
+        {
+            int pvno = IntegerDecoder.parse( value, 5, 5 );
+
+            apRep.setProtocolVersionNumber( pvno );
+
+            if ( IS_DEBUG )
+            {
+                LOG.debug( "Pvno : " + pvno );
+            }
+        }
+        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() );
+        }
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apReq/ApReqStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apReq/ApReqStatesEnum.java?rev=1036559&r1=1036558&r2=1036559&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apReq/ApReqStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/apReq/ApReqStatesEnum.java
Thu Nov 18 17:57:29 2010
@@ -36,7 +36,7 @@ public enum ApReqStatesEnum implements S
     // Start
     START_STATE,                            // 0
     
-    // ----- AS-REQ message --------------------------------------
+    // ----- AP-REQ message --------------------------------------
     AP_REQ_STATE,                           // 1
     AP_REQ_SEQ_STATE,                       // 2
     

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ApRepDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ApRepDecoderTest.java?rev=1036559&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ApRepDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/ApRepDecoderTest.java
Thu Nov 18 17:57:29 2010
@@ -0,0 +1,259 @@
+/*
+ *  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.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.apRep.ApRepContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a AP-REP
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ApRepDecoderTest
+{
+    /**
+     * Test the decoding of a AP-REP message
+     */
+    @Test
+    public void testDecodeFullApRep() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x21 );
+        
+        stream.put( new byte[]
+        {
+            0x6F, 0x1F,
+              0x30, 0x1D,
+                (byte)0xA0, 0x03,                 // pvno
+                  0x02, 0x01, 0x05,
+                (byte)0xA1, 0x03,                 // msg-type
+                  0x02, 0x01, 0x0F,
+                (byte)0xA2, 0x11,                 // enc-part
+                  0x30, 0x0F, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x11, 
+                    (byte)0xA2, 0x08, 
+                      0x04, 0x06, 
+                        'a', 'b', 'c', 'd', 'e', 'f', 
+        });
+
+        stream.flip();
+
+        // Allocate a AsRep Container
+        ApRepContainer apRepContainer = new ApRepContainer();
+        apRepContainer.setStream( stream );
+        
+        // Decode the ApRep PDU
+        try
+        {
+            kerberosDecoder.decode( stream, apRepContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        ApRep apRep = apRepContainer.getApRep();
+        
+        // Check the encoding
+        int length = apRep.computeLength();
+
+        // Check the length
+        assertEquals( 0x21, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = apRep.encode( encodedPdu );
+            
+            // Check the length
+            assertEquals( 0x21, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    /**
+     * Test the decoding of a AP-REP message with a wrong msg-type
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeFullApRepWrongMsgType() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x21 );
+        
+        stream.put( new byte[]
+        {
+            0x6F, 0x1F,
+              0x30, 0x1D,
+                (byte)0xA0, 0x03,                 // pvno
+                  0x02, 0x01, 0x05,
+                (byte)0xA1, 0x03,                 // msg-type
+                  0x02, 0x01, 0x0F,
+                (byte)0xA2, 0x11,                 // enc-part
+                  0x30, 0x0E, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x11, 
+                    (byte)0xA2, 0x08, 
+                      0x04, 0x06, 
+                        'a', 'b', 'c', 'd', 'e', 'f', 
+        });
+
+        stream.flip();
+
+        // Allocate a AsRep Container
+        ApRepContainer apRepContainer = new ApRepContainer();
+        apRepContainer.setStream( stream );
+        
+        // Decode the ApRep PDU
+        kerberosDecoder.decode( stream, apRepContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a AP-REP with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testApRepEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x6F, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a AP-REP Container
+        Asn1Container apRepContainer = new ApRepContainer();
+
+        // Decode the AP-REP PDU
+        kerberosDecoder.decode( stream, apRepContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a AP-REP with empty SEQ
+     */
+    @Test( expected = DecoderException.class)
+    public void testApRepEmptSEQ() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+                0x6F, 0x02,
+                  0x30, 0x00,
+            } );
+
+        stream.flip();
+
+        // Allocate a AP-REP Container
+        Asn1Container apRepContainer = new ApRepContainer();
+
+        // Decode the AP-REP PDU
+        kerberosDecoder.decode( stream, apRepContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a AP-REP with empty Pvno tag
+     */
+    @Test( expected = DecoderException.class)
+    public void testApRepEmptyPvnoTag() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x06 );
+        
+        stream.put( new byte[]
+            { 
+                0x6F, 0x04,
+                  0x30, 0x02,
+                    (byte)0xA0, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a AP-REP Container
+        Asn1Container apRepContainer = new ApRepContainer();
+
+        // Decode the AP-REP PDU
+        kerberosDecoder.decode( stream, apRepContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a AP-REP with empty Pvno value
+     */
+    @Test( expected = DecoderException.class)
+    public void testAsRepEmptyPvnoValue() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x08 );
+        
+        stream.put( new byte[]
+            { 
+                0x6E, 0x06,
+                  0x30, 0x04,
+                    (byte)0xA0, 0x02,
+                      0x02, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a AP-REP Container
+        Asn1Container apRepContainer = new ApRepContainer();
+
+        // Decode the AP-REP PDU
+        kerberosDecoder.decode( stream, apRepContainer );
+        fail();
+    }
+}



Mime
View raw message