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/23 18:26:41 UTC
svn commit: r1038213 - in
/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos:
codec/etypeInfo2Entry/ codec/etypeInfo2Entry/actions/ components/
Author: elecharny
Date: Tue Nov 23 17:26:41 2010
New Revision: 1038213
URL: http://svn.apache.org/viewvc?rev=1038213&view=rev
Log:
Added the ETYPE-INFO2-ENTRY grammar
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/ETypeInfo2EntryInit.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreEType.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreS2KParams.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreSalt.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryContainer.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryContainer.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.kerberos.codec.etypeInfo2Entry;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfo2Entry;
+
+
+/**
+ * The ETypeInfo2Entry container stores the ETYPE-INFO2-ENTRY decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ETypeInfo2EntryContainer extends AbstractContainer
+{
+ /** holds ETypeInfo2Entry */
+ private ETypeInfo2Entry etypeInfo2Entry;
+
+ /**
+ * Creates a new ETypeInfo2EntryContainer object.
+ */
+ public ETypeInfo2EntryContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = ETypeInfo2EntryGrammar.getInstance();
+ setTransition( ETypeInfo2EntryStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the ETypeInfo2Entry.
+ */
+ public ETypeInfo2Entry getETypeInfo2Entry()
+ {
+ return etypeInfo2Entry;
+ }
+
+
+ /**
+ * Set a ETypeInfo2Entry Object into the container
+ *
+ * @param etypeInfo2Entry The ETypeInfo2Entry to set.
+ */
+ public void setETypeInfo2Entry( ETypeInfo2Entry etypeInfo2Entry )
+ {
+ this.etypeInfo2Entry = etypeInfo2Entry;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryGrammar.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryGrammar.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.kerberos.codec.etypeInfo2Entry;
+
+
+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.etypeInfo2Entry.actions.ETypeInfo2EntryInit;
+import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreEType;
+import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreS2KParams;
+import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreSalt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the ETYPE-INFO2-ENTRY 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 ETypeInfo2EntryGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( ETypeInfo2EntryGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. ETypeInfo2EntryGrammar is a singleton */
+ private static Grammar instance = new ETypeInfo2EntryGrammar();
+
+
+ /**
+ * Creates a new ETypeInfoEntryGrammar object.
+ */
+ private ETypeInfo2EntryGrammar()
+ {
+ setName( ETypeInfo2EntryGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[ETypeInfo2EntryStatesEnum.LAST_ETYPE_INFO2_ENTRY_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // ETYPE-INFO2-ENTRY
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from ETYPE-INFO2-ENTRY init to ETYPE-INFO2-ENTRY SEQ
+ // --------------------------------------------------------------------------------------------
+ // ETYPE-INFO2-ENTRY ::= SEQUENCE {
+ super.transitions[ETypeInfo2EntryStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.START_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+ new ETypeInfo2EntryInit() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_ETYPE_TAG] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE, KerberosConstants.ETYPE_INFO2_ENTRY_ETYPE_TAG,
+ new CheckNotNullLength()) ;
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE, UniversalTag.INTEGER.getValue(),
+ new StoreEType() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE, KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG,
+ new CheckNotNullLength() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE, KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG,
+ new CheckNotNullLength() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE, UniversalTag.OCTET_STRING.getValue(),
+ new StoreSalt() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE, KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG,
+ new CheckNotNullLength() );
+
+ super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+ ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE, ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_STATE, UniversalTag.OCTET_STRING.getValue(),
+ new StoreS2KParams() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the ETYPE-INFO2-ENTRY Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryStatesEnum.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/ETypeInfo2EntryStatesEnum.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.kerberos.codec.etypeInfo2Entry;
+
+
+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 ETYPE-INFO2-ENTRY grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum ETypeInfo2EntryStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ ETYPE_INFO2_ENTRY_SEQ_STATE, // 1
+
+ ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE, // 2
+
+ ETYPE_INFO2_ENTRY_ETYPE_STATE, // 3
+
+ ETYPE_INFO2_ENTRY_SALT_TAG_STATE, // 4
+
+ ETYPE_INFO2_ENTRY_SALT_STATE, // 5
+
+ ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE, // 6
+
+ ETYPE_INFO2_ENTRY_S2KPARAMS_STATE, // 7
+
+ // End
+ LAST_ETYPE_INFO2_ENTRY_STATE; // 8
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "ETYPE_INFO2_ENTRY_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "ETYPE_INFO2_ENTRY_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_ETYPE_INFO2_ENTRY_STATE.ordinal() ) ? "LAST_ETYPE_INFO2_ENTRY_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_ETYPE_INFO2_ENTRY_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ETypeInfo2EntryStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/ETypeInfo2EntryInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/ETypeInfo2EntryInit.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/ETypeInfo2EntryInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/ETypeInfo2EntryInit.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.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.etypeInfo2Entry.ETypeInfo2EntryContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfo2Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the ETYPE-INFO2-ENTRY object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ETypeInfo2EntryInit extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( ETypeInfo2EntryInit.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new ETypeInfo2EntryInit action.
+ */
+ public ETypeInfo2EntryInit()
+ {
+ super( "Creates a ETYPE-INFO2-ENTRY instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ ETypeInfo2EntryContainer etypeInfo2EntryContainer = ( ETypeInfo2EntryContainer ) container;
+
+ TLV tlv = etypeInfo2EntryContainer.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 ) );
+ }
+
+ ETypeInfo2Entry etypeInfo2Entry = new ETypeInfo2Entry();
+ etypeInfo2EntryContainer.setETypeInfo2Entry( etypeInfo2Entry );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "ETYPE-INFO2-ENTRY created" );
+ }
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreEType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreEType.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreEType.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreEType.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.etypeInfo2Entry.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.etypeInfo2Entry.ETypeInfo2EntryContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.ETypeInfo2Entry;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the ETYPE-INFO2-ENTRY etype
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreEType extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreEType.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreEType action.
+ */
+ public StoreEType()
+ {
+ super( "ETYPE-INFO2-ENTRY etype" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ ETypeInfo2EntryContainer etypeInfo2EntryContainer = ( ETypeInfo2EntryContainer ) container;
+
+ TLV tlv = etypeInfo2EntryContainer.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 etype is an integer
+ Value value = tlv.getValue();
+
+ EncryptionType etype = null;
+ ETypeInfo2Entry etypeInfo2Entry = etypeInfo2EntryContainer.getETypeInfo2Entry();
+
+ try
+ {
+ int eType = IntegerDecoder.parse( value );
+ etype = EncryptionType.getTypeByValue( eType );
+
+ etypeInfo2Entry.setEType( etype );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "etype : " + etype );
+ }
+
+ // The next tag is optional, we can end here
+ etypeInfo2EntryContainer.setGrammarEndAllowed( true );
+ }
+ 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/etypeInfo2Entry/actions/StoreS2KParams.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreS2KParams.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreS2KParams.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreS2KParams.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,88 @@
+/*
+ * 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.etypeInfo2Entry.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.kerberos.codec.etypeInfo2Entry.ETypeInfo2EntryContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfo2Entry;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the ETYPE-INFO2-ENTRY cipher
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreS2KParams extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreS2KParams.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreS2Params action.
+ */
+ public StoreS2KParams()
+ {
+ super( "ETYPE-INFO2-ENTRY s2kparams" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ ETypeInfo2EntryContainer etypeInfo2EntryContainer = ( ETypeInfo2EntryContainer ) container;
+
+ TLV tlv = etypeInfo2EntryContainer.getCurrentTLV();
+ ETypeInfo2Entry etypeInfo2Entry = etypeInfo2EntryContainer.getETypeInfo2Entry();
+
+ // The Length may be null
+ if ( tlv.getLength() != 0 )
+ {
+ Value value = tlv.getValue();
+
+ // The encrypted data may be null
+ if ( value.getData() != null )
+ {
+ etypeInfo2Entry.setS2kparams( value.getData() );
+ }
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "salt : {}", StringTools.dumpBytes( etypeInfo2Entry.getS2kparams() ) );
+ }
+
+ // We can end here
+ etypeInfo2EntryContainer.setGrammarEndAllowed( true );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreSalt.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreSalt.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreSalt.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo2Entry/actions/StoreSalt.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.etypeInfo2Entry.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.kerberos.codec.etypeInfo2Entry.ETypeInfo2EntryContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfo2Entry;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to store the ETYPE-INFO2-ENTRY cipher
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSalt extends GrammarAction
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( StoreSalt.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /**
+ * Instantiates a new StoreSalt action.
+ */
+ public StoreSalt()
+ {
+ super( "ETYPE-INFO2-ENTRY salt" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ ETypeInfo2EntryContainer etypeInfo2EntryContainer = ( ETypeInfo2EntryContainer ) container;
+
+ TLV tlv = etypeInfo2EntryContainer.getCurrentTLV();
+ ETypeInfo2Entry etypeInfo2Entry = etypeInfo2EntryContainer.getETypeInfo2Entry();
+
+ // The Length may be null
+ if ( tlv.getLength() != 0 )
+ {
+ Value value = tlv.getValue();
+
+ // The encrypted data may be null
+ if ( value.getData() != null )
+ {
+ String salt = StringTools.utf8ToString( value.getData() );
+ etypeInfo2Entry.setSalt( salt );
+ }
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "salt : {}", etypeInfo2Entry.getSalt() );
+ }
+
+ // We can end here
+ etypeInfo2EntryContainer.setGrammarEndAllowed( true );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java?rev=1038213&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/ETypeInfo2Entry.java Tue Nov 23 17:26:41 2010
@@ -0,0 +1,295 @@
+/*
+ * 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.components;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Provides encryption info information sent to the client.
+ *
+ * The ASN.1 grammar for this structure is :
+ * <pre>
+ * ETYPE-INFO2-ENTRY ::= SEQUENCE {
+ * etype [0] Int32,
+ * salt [1] KerberosString OPTIONAL,
+ * s2kparams [2] OCTET STRING OPTIONAL
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ETypeInfo2Entry extends AbstractAsn1Object
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( ETypeInfo2Entry.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The encryption type */
+ private EncryptionType etype;
+
+ /** The salt */
+ private String salt;
+ private byte[] saltBytes;
+
+ /** The s2k params */
+ private byte[] s2kparams;
+
+ // Storage for computed lengths
+ private transient int etypeTagLength;
+ private transient int saltTagLength;
+ private transient int s2kparamsTagLength;
+ private transient int etypeInfo2EntrySeqLength;
+
+ /**
+ * Creates a new instance of ETypeInfo2Entry.
+ */
+ public ETypeInfo2Entry()
+ {
+ }
+
+
+ /**
+ * Returns the salt.
+ *
+ * @return The salt.
+ */
+ public String getSalt()
+ {
+ return salt;
+ }
+
+
+ /**
+ * @param salt the salt to set
+ */
+ public void setSalt( String salt )
+ {
+ this.salt = salt;
+ }
+
+
+ /**
+ * Returns the s2kparams.
+ *
+ * @return The s2kparams.
+ */
+ public byte[] getS2kparams()
+ {
+ return s2kparams;
+ }
+
+
+ /**
+ * @param s2kparams the s2kparams to set
+ */
+ public void setS2kparams( byte[] s2kparams )
+ {
+ this.s2kparams = s2kparams;
+ }
+
+
+ /**
+ * Returns the {@link EncryptionType}.
+ *
+ * @return The {@link EncryptionType}.
+ */
+ public EncryptionType getEType()
+ {
+ return etype;
+ }
+
+
+ /**
+ * @param encryptionType the encryptionType to set
+ */
+ public void setEType( EncryptionType etype )
+ {
+ this.etype = etype;
+ }
+
+
+ /**
+ * Compute the ETYPE-INFO2-ENTRY length
+ * <pre>
+ * ETYPE-INFO-ENTRY :
+ *
+ * 0x30 L1 ETYPE-INFO2-ENTRY sequence
+ * |
+ * +--> 0xA0 L2 etype tag
+ * | |
+ * | +--> 0x02 L2-1etype (int)
+ * |
+ * +--> 0xA1 L3 salt tag
+ * | |
+ * | +--> 0x1B L3-1 salt (KerberosString)
+ * |
+ * +--> 0xA2 L4 s2kparams tag
+ * |
+ * +--> 0x04 L4-1 salt (OCTET STRING)
+ *
+ * where L1 = L2 + length(0xA0) + length(L2) +
+ * L3 + length(0xA1) + length(L3) +
+ * L4 + length(0xA2) + length( L4)
+ * and
+ * L2 = L2-1 + length(0x02) + length( L2-1)
+ * L3 = L3-1 + length(0x1B) + length( L3-1)
+ * L4 = L4-1 + length(0x04) + length( L4-1)
+ * </pre>
+ */
+ public int computeLength()
+ {
+ // Compute the etype. The Length will always be contained in 1 byte
+ int etypeLength = Value.getNbBytes( etype.getValue() );
+ etypeTagLength = 1 + TLV.getNbBytes( etypeLength ) + etypeLength;
+ etypeInfo2EntrySeqLength = 1 + TLV.getNbBytes( etypeTagLength ) + etypeTagLength;
+
+ // Compute the salt
+ if ( salt != null )
+ {
+ saltBytes = StringTools.getBytesUtf8( salt );
+ saltTagLength = 1 + TLV.getNbBytes( saltBytes.length ) + saltBytes.length;
+ etypeInfo2EntrySeqLength += 1 + TLV.getNbBytes( saltTagLength ) + saltTagLength;
+ }
+
+ // Compute the s2kparams
+ if ( s2kparams != null )
+ {
+ s2kparamsTagLength = 1 + TLV.getNbBytes( s2kparams.length ) + s2kparams.length;
+ etypeInfo2EntrySeqLength += 1 + TLV.getNbBytes( s2kparamsTagLength ) + s2kparamsTagLength;
+ }
+
+ return 1 + TLV.getNbBytes( etypeInfo2EntrySeqLength ) + etypeInfo2EntrySeqLength;
+ }
+
+
+ /**
+ * Encode the ETYPE-INFO2-ENTRY message to a PDU.
+ * <pre>
+ * ETYPE-INFO2-ENTRY :
+ *
+ * 0x30 LL
+ * 0xA0 LL
+ * 0x02 0x01 etype
+ * 0xA1 LL
+ * 0x1B LL salt
+ * 0xA2 LL
+ * 0x04 LL s2kparams
+ * </pre>
+ * @param buffer The buffer where to put the PDU. It should have been allocated
+ * before, with the right size.
+ * @return The constructed PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+ }
+
+ try
+ {
+ // The ETYPE-INFO2-ENTRY SEQ Tag
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( etypeInfo2EntrySeqLength ) );
+
+ // The etype, first the tag, then the value
+ buffer.put( ( byte ) KerberosConstants.ETYPE_INFO2_ENTRY_ETYPE_TAG );
+ buffer.put( TLV.getBytes( etypeTagLength ) );
+ Value.encode( buffer, etype.getValue() );
+
+ // The salt, first the tag, then the value, if salt is not null
+ if ( salt != null )
+ {
+ // The tag
+ buffer.put( ( byte ) KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG );
+ buffer.put( TLV.getBytes( saltTagLength ) );
+
+ // The value
+ buffer.put( UniversalTag.GENERAL_STRING.getValue() );
+ buffer.put( TLV.getBytes( saltBytes.length ) );
+ buffer.put( saltBytes );
+ }
+
+ // The s2kparams, first the tag, then the value, if s2kparams is not null
+ if ( s2kparams != null )
+ {
+ buffer.put( ( byte ) KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG );
+ buffer.put( TLV.getBytes( saltTagLength ) );
+ Value.encode( buffer, s2kparams );
+ }
+ }
+ catch ( BufferOverflowException boe )
+ {
+ LOG.error( I18n.err( I18n.ERR_145, 1 + TLV.getNbBytes( etypeInfo2EntrySeqLength )
+ + etypeInfo2EntrySeqLength, buffer.capacity() ) );
+ throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "ETYPE-INFO2-ENTRY encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ LOG.debug( "ETYPE-INFO2-ENTRY initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "ETYPE-INFO2-ENTRY : {\n" );
+ sb.append( " etype: " ).append( etype ).append( '\n' );
+
+ if ( salt != null )
+ {
+ sb.append( " salt: " ).append( salt ).append( '\n' );
+ }
+
+ if ( salt != null )
+ {
+ sb.append( " s2kparams: " ).append( StringTools.dumpBytes( s2kparams ) ).append( '\n' );
+ }
+
+ sb.append( "}\n" );
+
+ return sb.toString();
+ }
+}