You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/11/17 22:47:13 UTC
svn commit: r1036239 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/
main/java/org/apache/directory/shared/kerberos/codec/kdcRep/
main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/ ma...
Author: elecharny
Date: Wed Nov 17 21:47:12 2010
New Revision: 1036239
URL: http://svn.apache.org/viewvc?rev=1036239&view=rev
Log:
Added the KDC-REP grammar
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/AddPaData.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/CheckMsgType.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCName.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCRealm.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StorePvno.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreTicket.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsRep.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcRepDecoderTest.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcRep.java
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1036239&r1=1036238&r2=1036239&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java Wed Nov 17 21:47:12 2010
@@ -97,6 +97,12 @@ public class KerberosConstants
/** AS-REQ's tags */
public static final int AS_REQ_TAG = 0x6A;
+ /** AS-REP's tags */
+ public static final int AS_REP_TAG = 0x6B;
+
/** TGS-REQ's tags */
public static final int TGS_REQ_TAG = 0x6C;
+
+ /** TGS-REP's tags */
+ public static final int TGS_REP_TAG = 0x6D;
}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepContainer.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepContainer.java Wed Nov 17 21:47:12 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.kdcRep;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+
+
+/**
+ * The KdcReq container stores the KDC-REP decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KdcRepContainer extends AbstractContainer
+{
+ /** An KDC-REP container */
+ private KdcRep kdcRep;
+
+ /**
+ * Creates a new KdcReqContainer object.
+ */
+ public KdcRepContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = KdcRepGrammar.getInstance();
+ setTransition( KdcRepStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the KdcRep.
+ */
+ public KdcRep getKdcRep()
+ {
+ return kdcRep;
+ }
+
+
+ /**
+ * Set a KdcRep Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param kdcRep The KdcRep to set.
+ */
+ public void setKdcRep( KdcRep kdcRep )
+ {
+ this.kdcRep = kdcRep;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepGrammar.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepGrammar.java Wed Nov 17 21:47:12 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.codec.kdcRep;
+
+
+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.kdcRep.actions.AddPaData;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.CheckMsgType;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreCName;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreCRealm;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreEncPart;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StorePvno;
+import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreTicket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the KdcReq 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 KdcRepGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( KdcRepGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. KdcReqGrammar is a singleton */
+ private static Grammar instance = new KdcRepGrammar();
+
+
+ /**
+ * Creates a new KdcRepGrammar object.
+ */
+ private KdcRepGrammar()
+ {
+ setName( KdcRepGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[KdcRepStatesEnum.LAST_KDC_REP_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // KdcReq
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from KdcRep init to KdcRep SEQ
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ super.transitions[KdcRepStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.START_STATE, KdcRepStatesEnum.KDC_REP_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+ new CheckNotNullLength());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from KdcRep SEQ to pvno tag
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // pvno [0]
+ super.transitions[KdcRepStatesEnum.KDC_REP_SEQ_STATE.ordinal()][KerberosConstants.KDC_REP_PVNO_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_SEQ_STATE, KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE, KerberosConstants.KDC_REP_PVNO_TAG,
+ new CheckNotNullLength());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from pvno tag to pvno value
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // pvno [0] INTEGER (5)
+ super.transitions[KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE, KdcRepStatesEnum.KDC_REP_PVNO_STATE, UniversalTag.INTEGER.getValue(),
+ new StorePvno());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from pvno value to msg-type tag
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // msg-type [1]
+ super.transitions[KdcRepStatesEnum.KDC_REP_PVNO_STATE.ordinal()][KerberosConstants.KDC_REP_MSG_TYPE_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_PVNO_STATE, KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE, KerberosConstants.KDC_REP_MSG_TYPE_TAG,
+ new CheckNotNullLength());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from msg-type tag to msg-type value
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // msg-type [1] INTEGER (11 -- AS -- | 13 -- TGS --),
+ super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE, KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE, UniversalTag.INTEGER.getValue(),
+ new CheckMsgType());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from msg-type value pa-data tag
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // padata [2]
+ super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REP_PA_DATA_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE, KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE, KerberosConstants.KDC_REP_PA_DATA_TAG,
+ new CheckNotNullLength());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from pa-data tag to pa-data sequence
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // padata [2] SEQUENCE OF
+ super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE, KdcRepStatesEnum.KDC_REP_PA_DATA_STATE, UniversalTag.SEQUENCE.getValue(),
+ new CheckNotNullLength());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from pa-data sequence to PA-DATA
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // padata [2] SEQUENCE OF PA-DATA
+ super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_PA_DATA_STATE, KdcRepStatesEnum.KDC_REP_PA_DATA_STATE, UniversalTag.SEQUENCE.getValue(),
+ new AddPaData());
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from PA-DATA to crealm tag
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // crealm [3]
+ super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_STATE.ordinal()][KerberosConstants.KDC_REP_CREALM_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_PA_DATA_STATE, KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE, KerberosConstants.KDC_REP_CREALM_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from msg-type value to crealm tag (pa-data is empty)
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // crealm [3]
+ super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REP_CREALM_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE, KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE, KerberosConstants.KDC_REP_CREALM_TAG,
+ new CheckNotNullLength() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from crealm tag to crealm value
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // crealm [3] Realm,
+ super.transitions[KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE.ordinal()][UniversalTag.GENERAL_STRING.getValue()] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE, KdcRepStatesEnum.KDC_REP_CREALM_STATE, UniversalTag.GENERAL_STRING.getValue(),
+ new StoreCRealm() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from crealm value to cname
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // cname [4] PrincipalName,
+ super.transitions[KdcRepStatesEnum.KDC_REP_CREALM_STATE.ordinal()][KerberosConstants.KDC_REP_CNAME_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_CREALM_STATE, KdcRepStatesEnum.KDC_REP_CNAME_STATE, KerberosConstants.KDC_REP_CNAME_TAG,
+ new StoreCName() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from cname to ticket
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // ticket [5] Ticket,
+ super.transitions[KdcRepStatesEnum.KDC_REP_CNAME_STATE.ordinal()][KerberosConstants.KDC_REP_TICKET_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_CNAME_STATE, KdcRepStatesEnum.KDC_REP_TICKET_STATE, KerberosConstants.KDC_REP_TICKET_TAG,
+ new StoreTicket() );
+
+ // --------------------------------------------------------------------------------------------
+ // Transition from ticket to enc-part
+ // --------------------------------------------------------------------------------------------
+ // KDC-REP ::= SEQUENCE {
+ // ...
+ // enc-part [6] EncryptedData
+ super.transitions[KdcRepStatesEnum.KDC_REP_TICKET_STATE.ordinal()][KerberosConstants.KDC_REP_ENC_PART_TAG] = new GrammarTransition(
+ KdcRepStatesEnum.KDC_REP_TICKET_STATE, KdcRepStatesEnum.KDC_REP_ENC_PART_STATE, KerberosConstants.KDC_REP_ENC_PART_TAG,
+ new StoreEncPart() );
+ }
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the KDC-REQ Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepStatesEnum.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/KdcRepStatesEnum.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,123 @@
+/*
+ * 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.kdcRep;
+
+
+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 KDC-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 KdcRepStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- KDC-REP component --------------------------------------
+ KDC_REP_SEQ_STATE, // 1
+
+ KDC_REP_PVNO_TAG_STATE, // 2
+ KDC_REP_PVNO_STATE, // 3
+
+ KDC_REP_MSG_TYPE_TAG_STATE, // 4
+ KDC_REP_MSG_TYPE_STATE, // 5
+
+ KDC_REP_PA_DATA_TAG_STATE, // 6
+ KDC_REP_PA_DATA_STATE, // 7
+
+ KDC_REP_CREALM_TAG_STATE, // 8
+ KDC_REP_CREALM_STATE, // 9
+
+ KDC_REP_CNAME_STATE, // 10
+
+ KDC_REP_TICKET_STATE, // 11
+
+ KDC_REP_ENC_PART_STATE, // 12
+
+ // End
+ LAST_KDC_REP_STATE; // 13
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "KDC_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 "KDC_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_KDC_REP_STATE.ordinal() ) ? "KDC_REP_END_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_KDC_REP_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public KdcRepStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/AddPaData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/AddPaData.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/AddPaData.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/AddPaData.java Wed Nov 17 21:47:12 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.kdcRep.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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.codec.padata.PaDataContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.kerberos.components.PaData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a PaData
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddPaData extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( AddPaData.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /**
+ * Instantiates a new AddPaData action.
+ */
+ public AddPaData()
+ {
+ super( "KDC-REP Add PA-DATA" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.getCurrentTLV();
+
+ // The Length can't 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 PA-DATA
+ Asn1Decoder paDataDecoder = new Asn1Decoder();
+
+ PaDataContainer paDataContainer = new PaDataContainer();
+ paDataContainer.setStream( container.getStream() );
+
+ // We have to move back to the PA-DATA tag
+ container.rewind();
+
+ // Decode the PA-DATA PDU
+ try
+ {
+ paDataDecoder.decode( container.getStream(), paDataContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Update the parent
+ container.updateParent();
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Store the PData in the container
+ PaData paData = paDataContainer.getPaData();
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+ kdcRep.addPaData( paData );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "Added PA-DATA: {}", paData );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/CheckMsgType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/CheckMsgType.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/CheckMsgType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/CheckMsgType.java Wed Nov 17 21:47:12 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.kdcRep.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.KerberosMessageType;
+import org.apache.directory.shared.kerberos.codec.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.ldap.util.StringTools;
+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 GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( CheckMsgType.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreMsgType action.
+ */
+ public CheckMsgType()
+ {
+ super( "KDC-REP msg-type" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.getCurrentTLV();
+
+ // The Length should not be null and should be 1
+ if ( tlv.getLength() != 1 )
+ {
+ LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+ }
+
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+
+ Value value = tlv.getValue();
+
+ try
+ {
+ int msgType = IntegerDecoder.parse( value );
+ KerberosMessageType krbMsgType = KerberosMessageType.getTypeByOrdinal( msgType );
+
+ // The message type must be the expected one
+ if ( krbMsgType != kdcRep.getMsgType() )
+ {
+ LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), "The msg-type should be AS-REQ or TGS-REQ" ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( "The msg-type should be AS-REQ or TGS-REQ" );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "msg-type : {}", krbMsgType );
+ }
+ }
+ catch ( IntegerDecoderException ide )
+ {
+ LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide
+ .getLocalizedMessage() ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( ide.getMessage() );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCName.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCName.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCName.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCName.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,109 @@
+/*
+ * 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.kdcRep.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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.kerberos.components.PrincipalName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the CName
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreCName extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreCName.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreCName action.
+ */
+ public StoreCName()
+ {
+ super( "Stores the CName" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.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 PrincipalName
+ Asn1Decoder principalNameDecoder = new Asn1Decoder();
+
+ PrincipalNameContainer principalNameContainer = new PrincipalNameContainer();
+
+ // Decode the PrincipalName PDU
+ try
+ {
+ principalNameDecoder.decode( container.getStream(), principalNameContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Store the Principal name in the container
+ PrincipalName principalName = principalNameContainer.getPrincipalName();
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+ kdcRep.setCName( principalName );
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "CName : {}", principalName );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCRealm.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCRealm.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCRealm.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreCRealm.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.kdcRep.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to set the ticket Realm
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreCRealm 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 TicketRealm action.
+ */
+ public StoreCRealm()
+ {
+ super( "KDC-REP realm value" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.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 is the realm
+ Value value = tlv.getValue();
+ String crealm = StringTools.utf8ToString( value.getData() );
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+
+ kdcRep.setCRealm( crealm );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "cRealm : " + crealm );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreEncPart.java Wed Nov 17 21:47:12 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.kdcRep.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.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.codec.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.components.EncryptedData;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to set the ticket EncodedPart
+ *
+ * @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 TicketEncPart action.
+ */
+ public StoreEncPart()
+ {
+ super( "Kerberos Ticket EncodedPart" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.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 PrincipalName
+ Asn1Decoder encryptedDataDecoder = new Asn1Decoder();
+
+ EncryptedDataContainer encryptedDataContainer = new EncryptedDataContainer();
+ encryptedDataContainer.setStream( container.getStream() );
+
+ // Decode the Ticket PDU
+ try
+ {
+ encryptedDataDecoder.decode( container.getStream(), encryptedDataContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ EncryptedData encryptedData = encryptedDataContainer.getEncryptedData();
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+ kdcRep.setEncPart( encryptedData );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "EncryptedData : " + encryptedData );
+ }
+
+ // 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/kdcRep/actions/StorePvno.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StorePvno.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StorePvno.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StorePvno.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.kdcRep.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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the PVNO
+ *
+ * @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( StorePvno.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StorePvno action.
+ */
+ public StorePvno()
+ {
+ super( "KDC-REP pvno" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.getCurrentTLV();
+
+ // The Length should not be null and should be 1
+ if ( tlv.getLength() != 1 )
+ {
+ LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+ }
+
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+
+ Value value = tlv.getValue();
+
+ try
+ {
+ int pvno = IntegerDecoder.parse( value );
+
+ if ( pvno != 5 )
+ {
+ LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), "The PVNO should be 5" ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( "The PVNO should be 5" );
+ }
+
+ kdcRep.setPvno( 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() );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreTicket.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreTicket.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreTicket.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/kdcRep/actions/StoreTicket.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,109 @@
+/*
+ * 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.kdcRep.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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.codec.ticket.TicketContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.kerberos.messages.Ticket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the Ticket
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTicket extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreTicket.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /**
+ * Instantiates a new Storeicket action.
+ */
+ public StoreTicket()
+ {
+ super( "KDC-REP Store Ticket" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ KdcRepContainer kdcRepContainer = ( KdcRepContainer ) container;
+
+ TLV tlv = kdcRepContainer.getCurrentTLV();
+
+ // The Length can't 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 Ticket
+ Asn1Decoder ticketDecoder = new Asn1Decoder();
+
+ TicketContainer ticketContainer = new TicketContainer();
+ ticketContainer.setStream( container.getStream() );
+
+ // Decode the Ticket PDU
+ try
+ {
+ ticketDecoder.decode( container.getStream(), ticketContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ // Store the Ticket in the container
+ Ticket ticket = ticketContainer.getTicket();
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+ kdcRep.setTicket( ticket );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "Stored ticket: {}", ticket );
+ }
+ }
+}
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcRep.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcRep.java?rev=1036239&r1=1036238&r2=1036239&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcRep.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcRep.java Wed Nov 17 21:47:12 2010
@@ -181,7 +181,7 @@ public class KdcRep
* Set the client principalName
* @param cname the client principalName
*/
- public void setSName( PrincipalName cname )
+ public void setCName( PrincipalName cname )
{
this.cname = cname;
}
@@ -340,7 +340,7 @@ public class KdcRep
// The PVNO -----------------------------------------------------------
// The tag
- buffer.put( (byte)KerberosConstants.KDC_REQ_PVNO_TAG );
+ buffer.put( (byte)KerberosConstants.KDC_REP_PVNO_TAG );
buffer.put( TLV.getBytes( pvnoLength ) );
// The value
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsRep.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsRep.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsRep.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/AsRep.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,97 @@
+/*
+ * 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.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+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.KdcRep;
+
+
+/**
+ * AS-REQ message. It's just a KDC-REP message with a message type set to 11.
+ * It will store the object described by the ASN.1 grammar :
+ * <pre>
+ * AS-REP ::= [APPLICATION 11] <KDC-REP>
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AsRep extends KdcRep
+{
+ // Storage for computed lengths
+ private transient int kdcRepLength;
+ private transient int asRepLength;
+
+ /**
+ * Creates a new instance of AS-REP.
+ */
+ public AsRep()
+ {
+ super( KerberosMessageType.AS_REP );
+ }
+
+
+ /**
+ * Compute the AS-REP length
+ * <pre>
+ * AS-REP :
+ *
+ * 0x6B L1 AS-REP message
+ * |
+ * +--> 0x30 L2 KDC-REP sequence
+ * </pre>
+ */
+ public int computeLength()
+ {
+ kdcRepLength = super.computeLength();
+ asRepLength = 1 + TLV.getNbBytes( kdcRepLength ) + kdcRepLength;
+
+ return asRepLength;
+ }
+
+
+ /**
+ * Encode the AS-REP component
+ *
+ * @param buffer The buffer containing the encoded result
+ * @return The encoded component
+ * @throws EncoderException If the encoding failed
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ buffer = ByteBuffer.allocate( computeLength() );
+ }
+
+ // The AS-REP SEQ Tag
+ buffer.put( (byte)KerberosConstants.AS_REP_TAG );
+ buffer.put( TLV.getBytes( kdcRepLength ) );
+
+ // The KDC-REP --------------------------------------------------------
+ super.encode( buffer );
+
+ return buffer;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcRepDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcRepDecoderTest.java?rev=1036239&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcRepDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcRepDecoderTest.java Wed Nov 17 21:47:12 2010
@@ -0,0 +1,238 @@
+/*
+ * 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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.components.KdcRep;
+import org.apache.directory.shared.kerberos.messages.AsRep;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a KDC-REP
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class KdcRepDecoderTest
+{
+ /**
+ * Test the decoding of a KDC-REP message
+ */
+ @Test
+ public void testDecodeFullKdcRep() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0xA9 );
+
+ stream.put( new byte[]
+ {
+ 0x30, (byte)0x81, (byte)0xA6,
+ (byte)0xA0, 0x03, // PVNO
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03, // msg-type
+ 0x02, 0x01, 0x0B,
+ (byte)0xA2, 0x20, // PA-DATA
+ 0x30, 0x1E,
+ 0x30, 0x0D,
+ (byte)0xA1,0x03,
+ 0x02, 0x01, 01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 'a', 'b', 'c', 'd',
+ 0x30, 0x0D,
+ (byte)0xA1,0x03,
+ 0x02, 0x01, 01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 'e', 'f', 'g', 'h',
+ (byte)0xA3, 0x0D, // crealm
+ 0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA4, 0x14, // cname
+ 0x30, 0x12,
+ (byte)0xA0, 0x03, // name-type
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x0B, // name-string
+ 0x30, 0x09,
+ 0x1B, 0x07, 'h', 'n', 'e', 'l', 's', 'o', 'n',
+ (byte)0xA5, 0x40, // Ticket
+ 0x61, 0x3E,
+ 0x30, 0x3C,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA2, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 'c', 'l', 'i', 'e', 'n', 't',
+ (byte)0xA3, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ (byte)0xA6, 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 KdcRep Container
+ KdcRepContainer kdcRepContainer = new KdcRepContainer();
+ kdcRepContainer.setStream( stream );
+ kdcRepContainer.setKdcRep( new AsRep() );
+
+ // Decode the KdcRep PDU
+ try
+ {
+ kerberosDecoder.decode( stream, kdcRepContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ KdcRep kdcRep = kdcRepContainer.getKdcRep();
+
+ // Check the encoding
+ int length = kdcRep.computeLength();
+
+ // Check the length, should be 3 bytes longer as the kdcRep is a AS-REP
+ assertEquals( 0xAC, length );
+
+ // Check the encoding
+ ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+
+ try
+ {
+ encodedPdu = kdcRep.encode( encodedPdu );
+
+ // Check the length
+ assertEquals( 0xAC, encodedPdu.limit() );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * Test the decoding of a KDC-REP with nothing in it
+ */
+ @Test( expected = DecoderException.class)
+ public void testKdcRepEmpty() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+
+ stream.put( new byte[]
+ { 0x30, 0x00 } );
+
+ stream.flip();
+
+ // Allocate a KDC-REP Container
+ Asn1Container kdcRepContainer = new KdcRepContainer();
+
+ // Decode the KDC-REP PDU
+ kerberosDecoder.decode( stream, kdcRepContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a KDC-REP with empty Pvno tag
+ */
+ @Test( expected = DecoderException.class)
+ public void testKdcRepEmptyPvnoTag() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x02,
+ (byte)0xA0, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a KDC-REP Container
+ Asn1Container kdcRepContainer = new KdcRepContainer();
+
+ // Decode the KDC-REP PDU
+ kerberosDecoder.decode( stream, kdcRepContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a KDC-REP with empty Pvno value
+ */
+ @Test( expected = DecoderException.class)
+ public void testKdcRepEmptyPvnoValue() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x06 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x04,
+ (byte)0xA0, 0x02,
+ 0x02, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a KDC-REP Container
+ Asn1Container kdcRepContainer = new KdcRepContainer();
+
+ // Decode the KDC-REP PDU
+ kerberosDecoder.decode( stream, kdcRepContainer );
+ fail();
+ }
+}