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/16 15:01:59 UTC
svn commit: r1035638 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/
main/java/org/apache/directory/shared/kerberos/codec/tgsReq/
main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/ ma...
Author: elecharny
Date: Tue Nov 16 14:01:59 2010
New Revision: 1035638
URL: http://svn.apache.org/viewvc?rev=1035638&view=rev
Log:
o Added the TGS-REQ decoder
o Added some more tests
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/StoreKdcReq.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsReq.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsReqDecoderTest.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.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=1035638&r1=1035637&r2=1035638&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 Tue Nov 16 14:01:59 2010
@@ -87,4 +87,7 @@ public class KerberosConstants
/** AS-REQ's tags */
public static final int AS_REQ_TAG = 0x6A;
+
+ /** TGS-REQ's tags */
+ public static final int TGS_REQ_TAG = 0x6C;
}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqContainer.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqContainer.java Tue Nov 16 14:01:59 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.tgsReq;
+
+import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.messages.TgsReq;
+
+
+/**
+ * The TGS-REQ container stores the KdcReq decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TgsReqContainer extends KdcReqContainer
+{
+ /** An TGS-REQ container */
+ private TgsReq tgsReq;
+
+ /**
+ * Creates a new TgsReqContainer object.
+ */
+ public TgsReqContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = TgsReqGrammar.getInstance();
+ setTransition( TgsReqStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the TgsReq.
+ */
+ public TgsReq getTgsReq()
+ {
+ return tgsReq;
+ }
+
+
+ /**
+ * Set an TgsReq Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param tgsReq The TgsReq to set.
+ */
+ public void setTgsReq( TgsReq tgsReq )
+ {
+ this.tgsReq = tgsReq;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java Tue Nov 16 14:01:59 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.tgsReq;
+
+
+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.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.tgsReq.actions.StoreKdcReq;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the TGS-REQ 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 TgsReqGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( TgsReqGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. AsReqGrammar is a singleton */
+ private static Grammar instance = new TgsReqGrammar();
+
+
+ /**
+ * Creates a new TgsReqGrammar object.
+ */
+ private TgsReqGrammar()
+ {
+ setName( TgsReqGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[TgsReqStatesEnum.LAST_TGS_REQ_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // TS-REQ
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from TS-REQ init to KDC-REQ
+ // --------------------------------------------------------------------------------------------
+ // TGS-REQ ::= [APPLICATION 12] KDC-REQ
+ super.transitions[TgsReqStatesEnum.START_STATE.ordinal()][KerberosConstants.TGS_REQ_TAG] = new GrammarTransition(
+ TgsReqStatesEnum.START_STATE, TgsReqStatesEnum.TGS_REQ_STATE, KerberosConstants.TGS_REQ_TAG,
+ new StoreKdcReq() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the AS-REQ Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqStatesEnum.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqStatesEnum.java Tue Nov 16 14:01:59 2010
@@ -0,0 +1,105 @@
+/*
+ * 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.tgsReq;
+
+
+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 TGS-REQ grammar's constants. It is also used for debugging
+ * purpose
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum TgsReqStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- HostAddresses message --------------------------------------
+ TGS_REQ_STATE, // 1
+
+ // End
+ LAST_TGS_REQ_STATE; // 2
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "TGS_REQ_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar grammar )
+ {
+ if ( grammar instanceof KerberosMessageGrammar )
+ {
+ return "TGS_REQ_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_TGS_REQ_STATE.ordinal() ) ? "TGS_REQ_END_STATE" : name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_TGS_REQ_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TgsReqStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/StoreKdcReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/StoreKdcReq.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/StoreKdcReq.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/actions/StoreKdcReq.java Tue Nov 16 14:01:59 2010
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.kerberos.codec.tgsReq.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.kdcReq.KdcReqContainer;
+import org.apache.directory.shared.kerberos.codec.tgsReq.TgsReqContainer;
+import org.apache.directory.shared.kerberos.messages.TgsReq;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a KDC-REQ object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreKdcReq 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 KDC-REQ action.
+ */
+ public StoreKdcReq()
+ {
+ super( "Add an KDC-REQ instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ TgsReqContainer tgsReqContainer = ( TgsReqContainer ) container;
+
+ TLV tlv = tgsReqContainer.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 KDC-REQ
+ Asn1Decoder kdcReqDecoder = new Asn1Decoder();
+
+ KdcReqContainer kdcReqContainer = new KdcReqContainer();
+ kdcReqContainer.setStream( container.getStream() );
+
+ // Store the created TGS-REQ object into the KDC-REQ container
+ TgsReq tgsReq = new TgsReq();
+ kdcReqContainer.setKdcReq( tgsReq );
+
+ // Decode the KDC_REQ PDU
+ try
+ {
+ kdcReqDecoder.decode( container.getStream(), kdcReqContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ tgsReqContainer.setTgsReq( tgsReq );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "TGS-REQ : {}", tgsReq );
+ }
+
+ container.setGrammarEndAllowed( true );
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsReq.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsReq.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsReq.java Tue Nov 16 14:01:59 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.KdcReq;
+
+
+/**
+ * TGS-REQ message. It's just a KDC-REQ message with a message type set to 12.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TgsReq extends KdcReq
+{
+ // Storage for computed lengths
+ private transient int kdcReqLength;
+ private transient int tgsReqLength;
+
+ /**
+ * Creates a new instance of TGS-REQ.
+ */
+ public TgsReq()
+ {
+ super( KerberosMessageType.TGS_REQ );
+ }
+
+
+ /**
+ * Compute the TGS-REQ length
+ * <pre>
+ * TGS-REQ :
+ *
+ * 0x6A L1 TGS-REQ message
+ * |
+ * +--> 0x30 L2 KDC-REQ sequence
+ */
+ public int computeLength()
+ {
+ kdcReqLength = super.computeLength();
+ tgsReqLength = 1 + TLV.getNbBytes( kdcReqLength ) + kdcReqLength;
+
+ return tgsReqLength;
+ }
+
+
+ /**
+ * Encode the TGS-REQ 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 TGS-REQ SEQ Tag
+ buffer.put( (byte)KerberosConstants.TGS_REQ_TAG );
+ buffer.put( TLV.getBytes( tgsReqLength ) );
+
+ // The KDC-REQ --------------------------------------------------------
+ super.encode( buffer );
+
+ return buffer;
+ }
+}
Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java?rev=1035638&r1=1035637&r2=1035638&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AsReqDecoderTest.java Tue Nov 16 14:01:59 2010
@@ -34,7 +34,6 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.kerberos.codec.asReq.AsReqContainer;
import org.apache.directory.shared.kerberos.messages.AsReq;
-import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -187,7 +186,6 @@ public class AsReqDecoderTest
'a', 'b', 'c', 'd', 'e', 'f'
});
- String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
// Allocate a AsReq Container
@@ -232,6 +230,158 @@ public class AsReqDecoderTest
/**
+ * Test the decoding of a AsReq message with a bad MsgType
+ */
+ @Test( expected = DecoderException.class)
+ public void testDecodeFullAsReqBadMsgType() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x193 );
+
+ stream.put( new byte[]
+ {
+ 0x6A, (byte)0x82, 0x01, (byte)0x8F,
+ 0x30, (byte)0x82, 0x01, (byte)0x8B,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA2, 0x03,
+ 0x02, 0x01, 0x0C,
+ (byte)0xA3, 0x20,
+ 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)0xA4, (byte)0x82, 0x01, 0x5B,
+ 0x30, (byte)0x82, 0x01, 0x57,
+ (byte)0xA0, 0x07,
+ 0x03, 0x05,
+ 0x00, 0x01, 0x04, 0x00, 0x32,
+ (byte)0xA1, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 'c', 'l', 'i', 'e', 'n', 't',
+ (byte)0xA2, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA3, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA6, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA7, 0x04,
+ 0x02, 0x02,
+ 0x30, 0x39,
+ (byte)0xA8, 0x0B,
+ 0x30, 0x09,
+ 0x02, 0x01, 0x06,
+ 0x02, 0x01, 0x11,
+ 0x02, 0x01, 0x12,
+ (byte)0xA9, 0x2E,
+ 0x30, 0x2C,
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1',
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2',
+ (byte)0xAA, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ (byte)0xAB, (byte)0x81, (byte)0x83,
+ 0x30, (byte)0x81, (byte)0x80,
+ 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',
+ 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,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA3, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ });
+
+ stream.flip();
+
+ // Allocate a AsReq Container
+ AsReqContainer asReqContainer = new AsReqContainer();
+ asReqContainer.setStream( stream );
+
+ // Decode the AsReq PDU
+ kerberosDecoder.decode( stream, asReqContainer );
+ fail();
+ }
+
+
+ /**
* Test the decoding of a AS-REQ with nothing in it
*/
@Test( expected = DecoderException.class)
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsReqDecoderTest.java?rev=1035638&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsReqDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsReqDecoderTest.java Tue Nov 16 14:01:59 2010
@@ -0,0 +1,406 @@
+/*
+ * 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.assertTrue;
+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.tgsReq.TgsReqContainer;
+import org.apache.directory.shared.kerberos.messages.TgsReq;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a TgsReq
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class TgsReqDecoderTest
+{
+ /**
+ * Test the decoding of a TgsReq message
+ */
+ @Test
+ public void testDecodeFullTgsReq() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x193 );
+
+ stream.put( new byte[]
+ {
+ 0x6C, (byte)0x82, 0x01, (byte)0x8F,
+ 0x30, (byte)0x82, 0x01, (byte)0x8B,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA2, 0x03,
+ 0x02, 0x01, 0x0C,
+ (byte)0xA3, 0x20,
+ 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)0xA4, (byte)0x82, 0x01, 0x5B,
+ 0x30, (byte)0x82, 0x01, 0x57,
+ (byte)0xA0, 0x07,
+ 0x03, 0x05,
+ 0x00, 0x01, 0x04, 0x00, 0x32,
+ (byte)0xA1, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 'c', 'l', 'i', 'e', 'n', 't',
+ (byte)0xA2, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA3, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA6, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA7, 0x04,
+ 0x02, 0x02,
+ 0x30, 0x39,
+ (byte)0xA8, 0x0B,
+ 0x30, 0x09,
+ 0x02, 0x01, 0x06,
+ 0x02, 0x01, 0x11,
+ 0x02, 0x01, 0x12,
+ (byte)0xA9, 0x2E,
+ 0x30, 0x2C,
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1',
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2',
+ (byte)0xAA, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ (byte)0xAB, (byte)0x81, (byte)0x83,
+ 0x30, (byte)0x81, (byte)0x80,
+ 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',
+ 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,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA3, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ });
+
+ stream.flip();
+
+ // Allocate a TgsReq Container
+ TgsReqContainer tgsReqContainer = new TgsReqContainer();
+ tgsReqContainer.setStream( stream );
+
+ // Decode the TgsReq PDU
+ try
+ {
+ kerberosDecoder.decode( stream, tgsReqContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ TgsReq tgsReq = tgsReqContainer.getTgsReq();
+
+ assertTrue( tgsReq instanceof TgsReq );
+
+ // Check the encoding
+ int length = tgsReq.computeLength();
+
+ // Check the length
+ assertEquals( 0x193, length );
+
+ // Check the encoding
+ ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+
+ try
+ {
+ encodedPdu = tgsReq.encode( encodedPdu );
+
+ // Check the length
+ assertEquals( 0x193, encodedPdu.limit() );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * Test the decoding of a TgsReq message with a bad MsgType
+ */
+ @Test( expected = DecoderException.class)
+ public void testDecodeFullTgsReqBadMsgType() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x193 );
+
+ stream.put( new byte[]
+ {
+ 0x6C, (byte)0x82, 0x01, (byte)0x8F,
+ 0x30, (byte)0x82, 0x01, (byte)0x8B,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA2, 0x03,
+ 0x02, 0x01, 0x0C,
+ (byte)0xA3, 0x20,
+ 0x30, 0x1E,
+ 0x30, 0x0D,
+ (byte)0xA1,0x03,
+ 0x02, 0x01, 01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 'a', 'b', 'c', 'd',
+ 0x30, 0x0A,
+ (byte)0xA1,0x03,
+ 0x02, 0x01, 01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 'e', 'f', 'g', 'h',
+ (byte)0xA4, (byte)0x82, 0x01, 0x5B,
+ 0x30, (byte)0x82, 0x01, 0x57,
+ (byte)0xA0, 0x07,
+ 0x03, 0x05,
+ 0x00, 0x01, 0x04, 0x00, 0x32,
+ (byte)0xA1, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 'c', 'l', 'i', 'e', 'n', 't',
+ (byte)0xA2, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA3, 0x13,
+ 0x30, 0x11,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA6, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z',
+ (byte)0xA7, 0x04,
+ 0x02, 0x02,
+ 0x30, 0x39,
+ (byte)0xA8, 0x0B,
+ 0x30, 0x09,
+ 0x02, 0x01, 0x06,
+ 0x02, 0x01, 0x11,
+ 0x02, 0x01, 0x12,
+ (byte)0xA9, 0x2E,
+ 0x30, 0x2C,
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1',
+ 0x30, 0x14,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x0D,
+ 0x04, 0x0B,
+ '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2',
+ (byte)0xAA, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ (byte)0xAB, (byte)0x81, (byte)0x83,
+ 0x30, (byte)0x81, (byte)0x80,
+ 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',
+ 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,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA3, 0x11,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA2, 0x08,
+ 0x04, 0x06,
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ });
+
+ stream.flip();
+
+ // Allocate a TgsReq Container
+ TgsReqContainer tgsReqContainer = new TgsReqContainer();
+ tgsReqContainer.setStream( stream );
+
+ // Decode the TgsReq PDU
+ kerberosDecoder.decode( stream, tgsReqContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a TGS-REQ with nothing in it
+ */
+ @Test( expected = DecoderException.class)
+ public void testTgsReqEmpty() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+
+ stream.put( new byte[]
+ { 0x6C, 0x00 } );
+
+ stream.flip();
+
+ // Allocate a TGS-REQ Container
+ Asn1Container tgsReqContainer = new TgsReqContainer();
+
+ // Decode the TGS-REQ PDU
+ kerberosDecoder.decode( stream, tgsReqContainer );
+ fail();
+ }
+}