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 2005/05/04 23:18:22 UTC
svn commit: r168196 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
Author: elecharny
Date: Wed May 4 14:18:22 2005
New Revision: 168196
URL: http://svn.apache.org/viewcvs?rev=168196&view=rev
Log:
Finished the NegTokenInit part of the grammar.
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java?rev=168196&r1=168195&r2=168196&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/spnego/codec/grammars/SpnegoGrammar.java Wed May 4 14:18:22 2005
@@ -75,6 +75,8 @@
//============================================================================================
// SPNEGO
//============================================================================================
+ // NegTokenInit State
+ //--------------------------------------------------------------------------------------------
// SPNEGO --> CHOICE {
// negTokenInit [0] NegTokenInit, (Tag)
// We have a negTokenInit, and the tag must be 0xA0. We will create the Spnego POJO
@@ -112,8 +114,7 @@
// SPNEGO --> CHOICE { ...
// negTokenInit [0] NegTokenInit, (Length)
- // We have a negTokenInit, and the tag must be 0xA0
- // We get the negTokenInit length, and store it in the Spnego POJO
+ // We get the negTokenInit length, and store it in the Spnego POJO
super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH][0xA0] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_LENGTH,
SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE,
@@ -141,6 +142,9 @@
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_VALUE,
SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_TAG, null );
+ //============================================================================================
+ // NegTokenInitSequence State
+ //--------------------------------------------------------------------------------------------
// NegTokenInit ::= SEQUENCE { (Tag)
// mechTypes [0] MechTypeList OPTIONAL,
// reqFlags [1] ContextFlags OPTIONAL,
@@ -164,18 +168,20 @@
{
public void action( IAsn1Container container ) throws DecoderException
{
+
// first, we check that the length is OK
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
checkLength( spnego, tlv );
-
+
// Second, we store the new expected length into the global
// expected length, as it won't be usefull any more (this is
// an optimisation, we could have declared another class
// member to do this.) We also reset the current length to 0.
spnego.setExpectedLength( tlv.getLength().getLength() );
- spnego.setCurrentLength(0);
+ spnego.setCurrentLength( 0 );
return;
}
} );
@@ -192,7 +198,9 @@
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_VALUE,
SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG, null );
- //------------------------------------------------------------------------------------------
+ //============================================================================================
+ // mechTypes State
+ //--------------------------------------------------------------------------------------------
// NegTokenInit ::= SEQUENCE {
// mechTypes [0] MechTypeList OPTIONAL, (Tag)
// ...
@@ -204,25 +212,27 @@
// NegTokenInit ::= SEQUENCE {
// mechTypes [0] MechTypeList OPTIONAL, (Length)
// ...
- // MechTypeList ::= SEQUENCE OF MechType
+ // MechTypeList ::= SEQUENCE OF MechType
// The Length part. We just have to check the length and store the sequence
// expected length.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LENGTH][0xA0] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LENGTH,
- SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE,
- new GrammarAction( "Mech Type list Length" )
+ SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE,
+ new GrammarAction( "Mech Types Length" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
// Checks the length.
- checkLength(spnego, tlv);
-
+ checkLength( spnego, tlv );
+
// Stores the current length in the associated accumulator.
- spnego.setMechTypesExpectedLength(tlv.getLength().getLength());
+ spnego.setMechTypesExpectedLength( tlv.getLength().getLength() );
return;
}
} );
@@ -235,7 +245,10 @@
SpnegoStatesEnum.SPNEGO_MECH_TYPES_VALUE,
SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG, null );
- // MechTypeList ::= SEQUENCE OF MechType (Tag)
+ //============================================================================================
+ // mechTypeList State
+ //--------------------------------------------------------------------------------------------
+ // MechTypeList ::= SEQUENCE OF MechType (Tag)
// Nothing to do
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG][0x30] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_TAG,
@@ -245,41 +258,48 @@
// We have to check the length.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_LENGTH][0x30] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_LENGTH,
- SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE, new GrammarAction( "Mech Type list sequence Length" )
+ SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE,
+ new GrammarAction( "Mech Type list sequence Length" )
{
- public void action( IAsn1Container container ) throws DecoderException
- {
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
- // Checks the length.
- int expectedLength = spnego.getMechTypesExpectedLength();
-
- int currentLength = tlv.getLength().getLength() + tlv.getSize();
-
- if (expectedLength < currentLength)
- {
- throw new DecoderException("The current length is longer than the expected length");
- }
-
- // Stores the expected length of the mech types.
- spnego.setMechTypeListExpectedLength(tlv.getLength().getLength());
- return;
- }
- });
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Checks the length.
+ int expectedLength = spnego.getMechTypesExpectedLength();
+
+ int currentLength = tlv.getLength().getLength() + tlv.getSize();
- // MechTypeList ::= SEQUENCE OF MechType (Value)
+ if ( expectedLength < currentLength )
+ {
+ throw new DecoderException(
+ "The current length is longer than the expected length" );
+ }
+
+ // Stores the expected length of the mech types.
+ spnego.setMechTypeListExpectedLength( tlv.getLength().getLength() );
+ return;
+ }
+ } );
+
+ // MechTypeList ::= SEQUENCE OF MechType (Value)
// Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE][0x30] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPES_LIST_VALUE,
SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG, null );
+ //============================================================================================
+ // mechType State
+ //--------------------------------------------------------------------------------------------
// MechType ::= OBJECT IDENTIFIER (Tag)
// Nothing to do.
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG][0x06] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG, SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH,
- null );
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG][0x06] = new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_TYPE_TAG,
+ SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH, null );
// MechType ::= OBJECT IDENTIFIER (Length)
// We have to check the length.
@@ -287,68 +307,81 @@
SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH, SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE,
new GrammarAction( "Mech Type Length" )
{
- public void action( IAsn1Container container ) throws DecoderException
- {
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
- // Checks the length.
- int expectedLength = spnego.getMechTypeListExpectedLength();
-
- int currentLength = tlv.getLength().getLength() + tlv.getSize();
-
- if (expectedLength < currentLength)
- {
- throw new DecoderException("The current length is longer than the expected length");
- }
-
- // Updates the current length.
- spnego.setMechTypeListExpectedLength( expectedLength - currentLength );
- return;
- }
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Checks the length.
+ int expectedLength = spnego.getMechTypeListExpectedLength();
+
+ int currentLength = tlv.getLength().getLength() + tlv.getSize();
+
+ if ( expectedLength < currentLength )
+ {
+ throw new DecoderException(
+ "The current length is longer than the expected length" );
+ }
+
+ // Updates the current length.
+ spnego.setMechTypeListExpectedLength( expectedLength - currentLength );
+ return;
+ }
} );
- // MechType ::= OBJECT IDENTIFIER (Value)
+ // MechType ::= OBJECT IDENTIFIER (Value)
// Here we will add a new Mech Type to the MechTypeList
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE][0x06] = new GrammarTransition(
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE][0x06] = new GrammarTransition(
SpnegoStatesEnum.SPNEGO_MECH_TYPE_VALUE,
- SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG, new GrammarAction( "Mech Type Value" )
+ SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
+ new GrammarAction( "Mech Type Value" )
{
- public void action( IAsn1Container container ) throws DecoderException
- {
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
- // Creates a new OID, and add it to the mech type list
- try
- {
- OID oid = (OID)(spnegoContainer.getPoolManager().allocate(PoolEnum.OID_POOL));
-
- oid.setOID(tlv.getValue().getData());
- spnego.addMechTypeList( oid );
- }
- catch (PoolException pe)
- {
- throw new DecoderException("Cannot allocate an OID");
- }
- return;
- }
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Creates a new OID, and add it to the mech type list
+ try
+ {
+
+ OID oid = ( OID ) ( spnegoContainer.getPoolManager().allocate(
+ PoolEnum.OID_POOL ) );
+
+ oid.setOID( tlv.getValue().getData() );
+ spnego.addMechTypeList( oid );
+ }
+ catch ( PoolException pe )
+ {
+ throw new DecoderException( "Cannot allocate an OID" );
+ }
+
+ return;
+ }
} );
- // MechType ::= OBJECT IDENTIFIER (Tag)
+ // MechType ::= OBJECT IDENTIFIER (Tag)
// Nothing to do, this is just a recursive call.
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0x06] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG, SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH,
- null );
-
- //------------------------------------------------------------------------------------------
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0x06] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
+ SpnegoStatesEnum.SPNEGO_MECH_TYPE_LENGTH, null );
+
+ //============================================================================================
+ // reqFlags State
+ //--------------------------------------------------------------------------------------------
// NegTokenInit ::= SEQUENCE {
// ...
// reqFlags [1] ContextFlags OPTIONAL, (Tag)
// ...
- // Here, we have to switch to the Length transition of a reqFlags state
+ // We are coming from a mechType state.
+ // We have to switch to the Length transition of a reqFlags state
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0xA1] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_REQ_FLAGS_LENGTH, null );
@@ -357,7 +390,8 @@
// ...
// reqFlags [1] ContextFlags OPTIONAL, (Tag)
// ...
- // Nothing to do
+ // We are coming from a NegtTokenInitSequence state
+ // We have to switch to the Length transition of a reqFlags state
super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG][0xA1] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_REQ_FLAGS_LENGTH, null );
@@ -371,30 +405,35 @@
SpnegoStatesEnum.SPNEGO_REQ_FLAGS_LENGTH, SpnegoStatesEnum.SPNEGO_REQ_FLAGS_VALUE,
new GrammarAction( "Req Flags Length" )
{
- public void action( IAsn1Container container ) throws DecoderException
- {
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
- // Checks the length.
- checkLength(spnego, tlv);
-
- // Store the length in the req flags expected length
- spnego.setReqFlagsExpectedLength(tlv.getLength().getLength());
- return;
- }
- } );
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Checks the length.
+ checkLength( spnego, tlv );
+
+ // Store the length in the req flags expected length
+ spnego.setReqFlagsExpectedLength( tlv.getLength().getLength() );
+ return;
+ }
+ } );
// NegTokenInit ::= SEQUENCE {
// ...
// reqFlags [1] ContextFlags OPTIONAL, (Value)
// ...
- // Nothing to do.
+ // Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_REQ_FLAGS_VALUE][0xA1] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_REQ_FLAGS_VALUE, SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG,
- null );
+ SpnegoStatesEnum.SPNEGO_REQ_FLAGS_VALUE,
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG, null );
+ //============================================================================================
+ // ContextFlags State
+ //--------------------------------------------------------------------------------------------
// ContextFlags ::= BIT_STRING { (Tag)
// delegFlag (0),
// mutualFlag (1),
@@ -405,9 +444,10 @@
// integFlag (6)
// }
// Nothing to do. We have a BitString
- super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG][0x03] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG, SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH,
- null );
+ super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG][0x03] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_TAG,
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH, null );
// ContextFlags ::= BIT_STRING { (Length)
// delegFlag (0),
@@ -418,29 +458,36 @@
// confFlag (5),
// integFlag (6)
// }
- // We have to check the length, and handle the special case of an empty length, which
+ // We have to check the length, and handle the special case of an empty length, which
/// is an error.
- super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH][0x03] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH, SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE,
+ super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH][0x03] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_LENGTH,
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE,
new GrammarAction( "Req Flags Length" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
- int expectedLength = spnego.getReqFlagsExpectedLength();
- int currentLength = tlv.getLength().getSize() + tlv.getTag().getSize() + tlv.getLength().getLength();
-
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ int expectedLength = spnego.getReqFlagsExpectedLength();
+ int currentLength =
+ tlv.getLength().getSize() + tlv.getTag().getSize() +
+ tlv.getLength().getLength();
+
if ( expectedLength != currentLength )
{
- throw new DecoderException("The ReqFlags length is different than the expected length");
+ throw new DecoderException(
+ "The ReqFlags length is different than the expected length" );
}
-
- if (tlv.getLength().getLength() == 0)
+
+ if ( tlv.getLength().getLength() == 0 )
{
- throw new DecoderException("The req flags must not be empty");
+ throw new DecoderException( "The req flags must not be empty" );
}
return;
@@ -456,185 +503,232 @@
// confFlag (5),
// integFlag (6)
// }
- // The next state will be the MechToken following
- super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE][0x03] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE, SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG,
+ // The next state will be the MechToken following Tag, or End
+ super.transitions[SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE][0x03] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_CONTEXT_FLAGS_VALUE,
+ SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG,
new GrammarAction( "Req Flags Value" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
// Get the req flags and set the flag
- try
+ try
{
- BitString bitString = (BitString)(spnegoContainer.getPoolManager().allocate(PoolEnum.BIT_STRING_POOL));
- bitString.setData(tlv.getValue().getData());
- spnego.setAnonFlag(bitString.getBit(0));
- spnego.setConfFlag(bitString.getBit(1));
- spnego.setDelegFlag(bitString.getBit(2));
- spnego.setIntegFlag(bitString.getBit(3));
- spnego.setMutualFlag(bitString.getBit(4));
- spnego.setReplayFlag(bitString.getBit(5));
- spnego.setSequenceFlag(bitString.getBit(6));
+ BitString bitString = ( BitString ) ( spnegoContainer.getPoolManager()
+ .allocate( PoolEnum.BIT_STRING_POOL ) );
+ bitString.setData( tlv.getValue().getData() );
+
+ spnego.setAnonFlag( bitString.getBit( 0 ) );
+ spnego.setConfFlag( bitString.getBit( 1 ) );
+ spnego.setDelegFlag( bitString.getBit( 2 ) );
+ spnego.setIntegFlag( bitString.getBit( 3 ) );
+ spnego.setMutualFlag( bitString.getBit( 4 ) );
+ spnego.setReplayFlag( bitString.getBit( 5 ) );
+ spnego.setSequenceFlag( bitString.getBit( 6 ) );
bitString.free();
}
- catch (PoolException pe)
+ catch ( PoolException pe )
{
- throw new DecoderException("Cannot allocate a BitString : " + pe.getMessage());
+ throw new DecoderException( "Cannot allocate a BitString : " +
+ pe.getMessage() );
}
-
+
return;
}
} );
- //------------------------------------------------------------------------------------------
- // NegTokenInit ::= SEQUENCE {
+ //============================================================================================
+ // mechToken State
+ //--------------------------------------------------------------------------------------------
+ // NegTokenInit ::= SEQUENCE {
// ...
// mechToken [2] OCTET STRING OPTIONAL, (Tag)
// ...
+ // We are coming from the reqsFlag state
// Nothing to do
super.transitions[SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG][0xA2] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG,
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null);
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
// NegTokenInit ::= SEQUENCE {
// ...
// mechToken [2] OCTET STRING OPTIONAL, (Tag)
// ...
- // Nothing to do.
+ // We are coming from the MechType state
+ // Nothing to do
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0xA2] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null);
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
// NegTokenInit ::= SEQUENCE {
// ...
// mechToken [2] OCTET STRING OPTIONAL, (Tag)
// ...
+ // We are coming from the NegTokenInitSequence state
// Nothing to do
super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG][0xA2] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH, null );
- // NegTokenInit ::= SEQUENCE {
+ // NegTokenInit ::= SEQUENCE {
// ...
// mechToken [2] OCTET STRING OPTIONAL, (Length)
// ...
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH][0xA2] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TOKEN_LENGTH,
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE, new GrammarAction( "Mech Token Length" )
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE,
+ new GrammarAction( "Mech Token Length" )
{
- public void action( IAsn1Container container ) throws DecoderException
- {
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
- // Checks the length.
- checkLength(spnego, tlv);
-
- // Store the length in the mech token expected length
- spnego.setMechTokenExpectedLength(tlv.getLength().getLength());
- return;
- }
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Checks the length.
+ checkLength( spnego, tlv );
+
+ // Store the length in the mech token expected length
+ spnego.setMechTokenExpectedLength( tlv.getLength().getLength() );
+ return;
+ }
} );
// mechToken [2] OCTET STRING OPTIONAL, (Value)
- // Nothing to do
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE][0xA2] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE, SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG,
- null );
-
+ // Nothing to do, the value follows.
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE][0xA2] = new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_VALUE,
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG, null );
+
+ //============================================================================================
+ // mechTokenString State
+ //--------------------------------------------------------------------------------------------
// mechToken [2] OCTET STRING OPTIONAL, (Tag)
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG][0x04] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG, SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH,
- null );
+ // Nothing to do
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG][0x04] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_TAG,
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH, null );
// mechToken [2] OCTET STRING OPTIONAL, (Length)
// Checks the length. If the length is 0, we will allocate an empty OctetString.
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH][0x04] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH, SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE,
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH][0x04] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_LENGTH,
+ SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE,
new GrammarAction( "Mech Token Length" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
- int expectedLength = spnego.getMechTokenExpectedLength();
- int currentLength = tlv.getLength().getSize() + tlv.getTag().getSize() + tlv.getLength().getLength();
-
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ int expectedLength = spnego
+ .getMechTokenExpectedLength();
+ int currentLength =
+ tlv.getLength().getSize() + tlv.getTag().getSize() +
+ tlv.getLength().getLength();
+
if ( expectedLength != currentLength )
{
- throw new DecoderException("The MechToken length is different than the expected length");
+ throw new DecoderException(
+ "The MechToken length is different than the expected length" );
}
-
- if (tlv.getLength().getLength() == 0)
+
+ if ( tlv.getLength().getLength() == 0 )
{
- spnego.setMechToken(OctetString.EMPTY_STRING);
+ spnego.setMechToken( OctetString.EMPTY_STRING );
}
else
{
+
// Creates a new mechToken
try
{
- OctetString mechToken = (OctetString)(spnegoContainer.getPoolManager().allocate(PoolEnum.OCTET_STRING_POOL));
-
- spnego.setMechToken(mechToken);
+
+ OctetString mechToken = ( OctetString )
+ ( spnegoContainer.getPoolManager().allocate(
+ PoolEnum.OCTET_STRING_POOL ) );
+
+ spnego.setMechToken( mechToken );
}
- catch (PoolException pe)
+ catch ( PoolException pe )
{
- throw new DecoderException("Cannot allocate an OID");
+ throw new DecoderException( "Cannot allocate a MechToken" );
}
}
+
return;
}
} );
// mechToken [2] OCTET STRING OPTIONAL, (Value)
// We will allocate a new Octet String.
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE][0x04] = new GrammarTransition(
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE][0x04] =
+ new GrammarTransition(
SpnegoStatesEnum.SPNEGO_MECH_TOKEN_OCTET_STRING_VALUE,
- SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG, new GrammarAction( "Mech Token Value" )
+ SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG,
+ new GrammarAction( "Mech Token Value" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
- SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )spnegoContainer.getSpnego();
- TLV tlv = spnegoContainer.getCurrentTLV();
-
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
// Stores the mechToken data
OctetString mechToken = spnego.getMechToken();
-
- mechToken.setData(tlv.getValue().getData());
+
+ mechToken.setData( tlv.getValue().getData() );
return;
}
} );
- //------------------------------------------------------------------------------------------
+ //============================================================================================
+ // mechListMIC State
+ //--------------------------------------------------------------------------------------------
// NegTokenInit ::= SEQUENCE {
// ...
// mechListMIC [3] OCTET STRING OPTIONAL } (Tag)
+ // We are coming from the NegInitTokenSequence state
+ // Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_NEG_TOKEN_INIT_SEQUENCE_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH, null );
// mechListMIC [3] OCTET STRING OPTIONAL } (Tag)
+ // We are coming from the mechType state
+ // Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_TYPE_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH, null );
// mechListMIC [3] OCTET STRING OPTIONAL } (Tag)
+ // We are coming from the ContextFlags state
+ // Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_REQ_FLAGS_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH, null );
// mechListMIC [3] OCTET STRING OPTIONAL } (Tag)
+ // We are coming from the mechToken state
+ // Nothing to do.
super.transitions[SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_METH_TOKEN_FOLLOWING_TAG,
SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH, null );
@@ -642,31 +736,124 @@
// NegTokenInit ::= SEQUENCE {
// ...
// mechListMIC [3] OCTET STRING OPTIONAL } (Length)
+ // We have to check the length.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_LENGTH,
- SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_VALUE, null );
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_VALUE,
+ new GrammarAction( "Mech List MIC Length" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Checks the length.
+ checkLength( spnego, tlv );
+
+ // Store the length in the mech token expected length
+ spnego.setMechListMICExpectedLength( tlv.getLength().getLength() );
+ return;
+ }
+ } );
// NegTokenInit ::= SEQUENCE {
// ...
// mechListMIC [3] OCTET STRING OPTIONAL } (Value)
+ // Nothing to do, the value follows.
super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_VALUE][0xA3] =
new GrammarTransition( SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_VALUE,
SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_TAG, null );
+ //============================================================================================
+ // mechListMICString State
+ //--------------------------------------------------------------------------------------------
// mechListMIC [3] OCTET STRING OPTIONAL } (Tag)
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_TAG][0x04] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_TAG, SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH,
- null );
+ // The mechListMIC tag. It's an OctetString.
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_TAG][0x04] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_TAG,
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH, null );
// mechListMIC [3] OCTET STRING OPTIONAL } (Length)
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH][0x04] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH, SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE,
- null );
+ // Checks the length. If the length is 0, we will allocate an empty OctetString.
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH][0x04] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_LENGTH,
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE,
+ new GrammarAction( "Mech ListMIC Length" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ int expectedLength =
+ spnego.getMechListMICExpectedLength();
+ int currentLength =
+ tlv.getLength().getSize() + tlv.getTag().getSize() +
+ tlv.getLength().getLength();
+
+ if ( expectedLength != currentLength )
+ {
+ throw new DecoderException(
+ "The MechListMIC length is different than the expected length" );
+ }
+
+ if ( tlv.getLength().getLength() == 0 )
+ {
+ spnego.setMechListMIC( OctetString.EMPTY_STRING );
+ }
+ else
+ {
+
+ // Creates a new mechListMIC
+ try
+ {
+
+ OctetString mechListMIC = ( OctetString )
+ ( spnegoContainer.getPoolManager().allocate(
+ PoolEnum.OCTET_STRING_POOL ) );
+
+ spnego.setMechListMIC( mechListMIC );
+ }
+ catch ( PoolException pe )
+ {
+ throw new DecoderException( "Cannot allocate a MechListMIC" );
+ }
+ }
+
+ return;
+ }
+ } );
// mechListMIC [3] OCTET STRING OPTIONAL } (Value)
- super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE][0x04] = new GrammarTransition(
- SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE,
- -1, null );
+ // Stores the MechListMIC OctetString. This is the last transition.
+ super.transitions[SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE][0x04] =
+ new GrammarTransition(
+ SpnegoStatesEnum.SPNEGO_MECH_LIST_MIC_OCTET_STRING_VALUE, -1,
+ new GrammarAction( "Mech ListMIC Value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ SpnegoContainer spnegoContainer = ( SpnegoContainer ) container;
+ SpnegoNegTokenInitPOJO spnego = ( SpnegoNegTokenInitPOJO )
+ spnegoContainer.getSpnego();
+ TLV tlv = spnegoContainer.getCurrentTLV();
+
+ // Stores the mechListMIC data
+ OctetString mechListMIC = spnego.getMechListMIC();
+
+ mechListMIC.setData( tlv.getValue().getData() );
+ return;
+ }
+ } );
}