Author: elecharny
Date: Wed Nov 17 23:56:36 2010
New Revision: 1036292
URL: http://svn.apache.org/viewvc?rev=1036292&view=rev
Log:
Added the TgsRep grammar
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepGrammar.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepStatesEnum.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/StoreKdcRep.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsRep.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsRepDecoderTest.java
Modified:
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/tgsRep/TgsRepContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepContainer.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepContainer.java
Wed Nov 17 23:56:36 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.tgsRep;
+
+import org.apache.directory.shared.kerberos.codec.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.messages.TgsRep;
+
+
+/**
+ * The TGS-REP container stores the TgsRep decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TgsRepContainer extends KdcRepContainer
+{
+ /** An TGS-REP container */
+ private TgsRep tgsRep;
+
+ /**
+ * Creates a new TgsRepContainer object.
+ */
+ public TgsRepContainer()
+ {
+ super();
+ this.stateStack = new int[1];
+ this.grammar = TgsRepGrammar.getInstance();
+ setTransition( TgsRepStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the TgsRep.
+ */
+ public TgsRep getTgsRep()
+ {
+ return tgsRep;
+ }
+
+
+ /**
+ * Set an TgsRep Object into the container. It will be completed by the
+ * KerberosDecoder.
+ *
+ * @param tgsRep The TgsRep to set.
+ */
+ public void setTgsRep( TgsRep tgsRep )
+ {
+ this.tgsRep = tgsRep;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepGrammar.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepGrammar.java
Wed Nov 17 23:56:36 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.tgsRep;
+
+
+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.tgsRep.actions.StoreKdcRep;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the TGS-REP structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class TgsRepGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( TgsRepGrammar.class );
+
+ /** A speedup for logger */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. TgsRepGrammar is a singleton */
+ private static Grammar instance = new TgsRepGrammar();
+
+
+ /**
+ * Creates a new TgsRepGrammar object.
+ */
+ private TgsRepGrammar()
+ {
+ setName( TgsRepGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[TgsRepStatesEnum.LAST_TGS_REP_STATE.ordinal()][256];
+
+ // ============================================================================================
+ // TS-REP
+ // ============================================================================================
+ // --------------------------------------------------------------------------------------------
+ // Transition from TS-REP init to KDC-REP
+ // --------------------------------------------------------------------------------------------
+ // TGS-REP ::= [APPLICATION 13] KDC-REP
+ super.transitions[TgsRepStatesEnum.START_STATE.ordinal()][KerberosConstants.TGS_REP_TAG]
= new GrammarTransition(
+ TgsRepStatesEnum.START_STATE, TgsRepStatesEnum.TGS_REP_STATE, KerberosConstants.TGS_REP_TAG,
+ new StoreKdcRep() );
+ }
+
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the AS-REP Grammar
+ */
+ public static Grammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepStatesEnum.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/TgsRepStatesEnum.java
Wed Nov 17 23:56:36 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.tgsRep;
+
+
+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-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 TgsRepStatesEnum implements States
+{
+ // Start
+ START_STATE, // 0
+
+ // ----- HostAddresses message --------------------------------------
+ TGS_REP_STATE, // 1
+
+ // End
+ LAST_TGS_REP_STATE; // 2
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "TGS_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 "TGS_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_TGS_REP_STATE.ordinal() ) ? "TGS_REP_END_STATE" : name()
);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == LAST_TGS_REP_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TgsRepStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/StoreKdcRep.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/StoreKdcRep.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/StoreKdcRep.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsRep/actions/StoreKdcRep.java
Wed Nov 17 23:56:36 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.tgsRep.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.kdcRep.KdcRepContainer;
+import org.apache.directory.shared.kerberos.codec.tgsRep.TgsRepContainer;
+import org.apache.directory.shared.kerberos.messages.TgsRep;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add a KDC-REP object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreKdcRep 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-REP action.
+ */
+ public StoreKdcRep()
+ {
+ super( "Add an KDC-REP instance" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ TgsRepContainer tgsRepContainer = ( TgsRepContainer ) container;
+
+ TLV tlv = tgsRepContainer.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-REP
+ Asn1Decoder kdcRepDecoder = new Asn1Decoder();
+
+ KdcRepContainer kdcRepContainer = new KdcRepContainer();
+ kdcRepContainer.setStream( container.getStream() );
+
+ // Store the created TGS-REP object into the KDC-REP container
+ TgsRep tgsRep = new TgsRep();
+ kdcRepContainer.setKdcRep( tgsRep );
+
+ // Decode the KDC_REP PDU
+ try
+ {
+ kdcRepDecoder.decode( container.getStream(), kdcRepContainer );
+ }
+ catch ( DecoderException de )
+ {
+ throw de;
+ }
+
+ // Update the expected length for the current TLV
+ tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+ // Update the parent
+ container.updateParent();
+
+ tgsRepContainer.setTgsRep( tgsRep );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "TGS-REP : {}", tgsRep );
+ }
+
+ container.setGrammarEndAllowed( true );
+ }
+}
Modified: 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=1036292&r1=1036291&r2=1036292&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/tgsReq/TgsReqGrammar.java
Wed Nov 17 23:56:36 2010
@@ -44,7 +44,7 @@ public final class TgsReqGrammar extends
/** A speedup for logger */
static final boolean IS_DEBUG = LOG.isDebugEnabled();
- /** The instance of grammar. AsReqGrammar is a singleton */
+ /** The instance of grammar. TgsReqGrammar is a singleton */
private static Grammar instance = new TgsReqGrammar();
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsRep.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsRep.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsRep.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/messages/TgsRep.java
Wed Nov 17 23:56:36 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;
+
+
+/**
+ * TGS-REP message. It's just a KDC-REP message with a message type set to 13.
+ * It will store the object described by the ASN.1 grammar :
+ * <pre>
+ * TGS-REP ::= [APPLICATION 13] <KDC-REP>
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TgsRep extends KdcRep
+{
+ // Storage for computed lengths
+ private transient int kdcRepLength;
+ private transient int tgsRepLength;
+
+ /**
+ * Creates a new instance of TGS-REP.
+ */
+ public TgsRep()
+ {
+ super( KerberosMessageType.TGS_REP );
+ }
+
+
+ /**
+ * Compute the TGS-REP length
+ * <pre>
+ * TGS-REP :
+ *
+ * 0x6D L1 TGS-REP message
+ * |
+ * +--> 0x30 L2 KDC-REP sequence
+ * </pre>
+ */
+ public int computeLength()
+ {
+ kdcRepLength = super.computeLength();
+ tgsRepLength = 1 + TLV.getNbBytes( kdcRepLength ) + kdcRepLength;
+
+ return tgsRepLength;
+ }
+
+
+ /**
+ * Encode the TGS-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 TGS-REP SEQ Tag
+ buffer.put( (byte)KerberosConstants.TGS_REP_TAG );
+ buffer.put( TLV.getBytes( tgsRepLength ) );
+
+ // The KDC-REP --------------------------------------------------------
+ super.encode( buffer );
+
+ return buffer;
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsRepDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsRepDecoderTest.java?rev=1036292&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsRepDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TgsRepDecoderTest.java
Wed Nov 17 23:56:36 2010
@@ -0,0 +1,237 @@
+/*
+ * 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.tgsRep.TgsRepContainer;
+import org.apache.directory.shared.kerberos.messages.TgsRep;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for a TGS-REP
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class TgsRepDecoderTest
+{
+ /**
+ * Test the decoding of a TGS-REP message
+ */
+ @Test
+ public void testDecodeFullTgsRep() throws Exception
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0xAC );
+
+ stream.put( new byte[]
+ {
+ 0x6D, (byte)0x81, (byte)0xA9,
+ 0x30, (byte)0x81, (byte)0xA6,
+ (byte)0xA0, 0x03, // PVNO
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03, // msg-type
+ 0x02, 0x01, 0x0D,
+ (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 TgsRep Container
+ TgsRepContainer tgsRepContainer = new TgsRepContainer();
+ tgsRepContainer.setStream( stream );
+
+ // Decode the TgsRep PDU
+ try
+ {
+ kerberosDecoder.decode( stream, tgsRepContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ TgsRep tgsRep = tgsRepContainer.getTgsRep();
+
+ // Check the encoding
+ int length = tgsRep.computeLength();
+
+ // Check the length
+ assertEquals( 0xAC, length );
+
+ // Check the encoding
+ ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+
+ try
+ {
+ encodedPdu = tgsRep.encode( encodedPdu );
+
+ // Check the length
+ assertEquals( 0xAC, encodedPdu.limit() );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+
+
+ /**
+ * Test the decoding of a TGS-REP with nothing in it
+ */
+ @Test( expected = DecoderException.class)
+ public void testTgsRepEmpty() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+
+ stream.put( new byte[]
+ { 0x30, 0x00 } );
+
+ stream.flip();
+
+ // Allocate a TGS-REP Container
+ Asn1Container tgsRepContainer = new TgsRepContainer();
+
+ // Decode the TGS-REP PDU
+ kerberosDecoder.decode( stream, tgsRepContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a TGS-REP with empty Pvno tag
+ */
+ @Test( expected = DecoderException.class)
+ public void testTgsRepEmptyPvnoTag() throws DecoderException
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x02,
+ (byte)0xA0, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a TGS-REP Container
+ Asn1Container tgsRepContainer = new TgsRepContainer();
+
+ // Decode the TGS-REP PDU
+ kerberosDecoder.decode( stream, tgsRepContainer );
+ fail();
+ }
+
+
+ /**
+ * Test the decoding of a TGS-REP with empty Pvno value
+ */
+ @Test( expected = DecoderException.class)
+ public void testTgsRepEmptyPvnoValue() 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 TGS-REP Container
+ Asn1Container tgsRepContainer = new TgsRepContainer();
+
+ // Decode the TGS-REP PDU
+ kerberosDecoder.decode( stream, tgsRepContainer );
+ fail();
+ }
+}
|