Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 12714 invoked from network); 7 Nov 2010 01:46:56 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Nov 2010 01:46:56 -0000 Received: (qmail 5251 invoked by uid 500); 7 Nov 2010 01:47:28 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 5199 invoked by uid 500); 7 Nov 2010 01:47:28 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 5192 invoked by uid 99); 7 Nov 2010 01:47:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Nov 2010 01:47:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Nov 2010 01:47:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 667C623889FD; Sun, 7 Nov 2010 01:46:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1032195 [3/3] - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec: ./ encryptedData/ encryptedData/actions/ principalName/ ticket/actions/ Date: Sun, 07 Nov 2010 01:46:05 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101107014605.667C623889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java?rev=1032195&r1=1032194&r2=1032195&view=diff ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java (original) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/EncryptedDataGrammar.java Sun Nov 7 01:46:04 2010 @@ -20,23 +20,16 @@ package org.apache.directory.shared.kerberos.codec.encryptedData; -import org.apache.directory.shared.asn1.ber.Asn1Container; 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.GrammarAction; import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition; -import org.apache.directory.shared.asn1.ber.tlv.TLV; import org.apache.directory.shared.asn1.ber.tlv.UniversalTag; -import org.apache.directory.shared.asn1.ber.tlv.Value; -import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.asn1.util.IntegerDecoder; -import org.apache.directory.shared.asn1.util.IntegerDecoderException; -import org.apache.directory.shared.i18n.I18n; import org.apache.directory.shared.kerberos.KerberosConstants; import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength; -import org.apache.directory.shared.kerberos.components.EncryptedData; -import org.apache.directory.shared.kerberos.components.EncryptionType; -import org.apache.directory.shared.ldap.util.StringTools; +import org.apache.directory.shared.kerberos.codec.encryptedData.actions.EncryptedPartCipher; +import org.apache.directory.shared.kerberos.codec.encryptedData.actions.EncryptedPartEType; +import org.apache.directory.shared.kerberos.codec.encryptedData.actions.EncryptedPartInit; +import org.apache.directory.shared.kerberos.codec.encryptedData.actions.EncryptedPartKvno; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,32 +72,7 @@ public final class EncryptedDataGrammar // EncryptedData ::= SEQUENCE super.transitions[EncryptedDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition( EncryptedDataStatesEnum.START_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_SEQ_STATE, UniversalTag.SEQUENCE.getValue(), - new GrammarAction( "EncryptedData SEQUENCE" ) - { - public void action( Asn1Container container ) throws DecoderException - { - EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; - - TLV tlv = encryptedDataContainer.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 ) ); - } - - EncryptedData encryptedData = new EncryptedData(); - encryptedDataContainer.setEncryptedData( encryptedData ); - - if ( IS_DEBUG ) - { - LOG.debug( "EncryptedData created" ); - } - } - } ); + new EncryptedPartInit() ); // -------------------------------------------------------------------------------------------- // Transition from EncryptedData SEQ to etype tag @@ -122,56 +90,7 @@ public final class EncryptedDataGrammar // etype [0] Int32, super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition( EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_ETYPE_STATE, UniversalTag.INTEGER.getValue(), - new GrammarAction( "EncryptedData SEQUENCE" ) - { - public void action( Asn1Container container ) throws DecoderException - { - EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; - - TLV tlv = encryptedDataContainer.getCurrentTLV(); - - // The Length should not be null - if ( tlv.getLength() == 0 ) - { - LOG.error( I18n.err( I18n.ERR_04066 ) ); - - // This will generate a PROTOCOL_ERROR - throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); - } - - // The encyptionType is an integer - Value value = tlv.getValue(); - - EncryptionType encryptionType = null; - EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); - - try - { - int eType = IntegerDecoder.parse( value ); - encryptionType = EncryptionType.getTypeByOrdinal( eType ); - - encryptedData.setEType( encryptionType ); - - if ( IS_DEBUG ) - { - LOG.debug( "etype : " + encryptionType ); - } - } - catch ( IntegerDecoderException ide ) - { - LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide - .getLocalizedMessage() ) ); - - // This will generate a PROTOCOL_ERROR - throw new DecoderException( ide.getMessage() ); - } - - if ( IS_DEBUG ) - { - LOG.debug( "EncryptionType : {}", encryptionType ); - } - } - } ); + new EncryptedPartEType() ); // -------------------------------------------------------------------------------------------- // Transition from etype value to kvno tag @@ -201,47 +120,7 @@ public final class EncryptedDataGrammar // kvno [1] UInt32 super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition( EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_KVNO_STATE, UniversalTag.INTEGER.getValue(), - new GrammarAction( "EncryptedData kvno" ) - { - public void action( Asn1Container container ) throws DecoderException - { - EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; - - TLV tlv = encryptedDataContainer.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 ) ); - } - - Value value = tlv.getValue(); - - try - { - int kvno = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE ); - - EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); - encryptedData.setKvno( kvno ); - - if ( IS_DEBUG ) - { - LOG.debug( "kvno : {}", kvno ); - } - } - catch ( IntegerDecoderException ide ) - { - LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide - .getLocalizedMessage() ) ); - - // This will generate a PROTOCOL_ERROR - throw new DecoderException( ide.getMessage() ); - } - } - }); + new EncryptedPartKvno() ); // -------------------------------------------------------------------------------------------- // Transition from kvno value value to cipher tag @@ -261,45 +140,7 @@ public final class EncryptedDataGrammar // cipher [2] OCTET STRING super.transitions[EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition( EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_TAG_STATE, EncryptedDataStatesEnum.ENCRYPTED_DATA_CIPHER_STATE, UniversalTag.OCTET_STRING.getValue(), - new GrammarAction( "EncryptedData SEQUENCE" ) - { - public void action( Asn1Container container ) throws DecoderException - { - EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; - - TLV tlv = encryptedDataContainer.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 ) ); - } - - Value value = tlv.getValue(); - - // The encrypted data should not be null - if ( value.getData() == null ) - { - LOG.error( I18n.err( I18n.ERR_04066 ) ); - - // This will generate a PROTOCOL_ERROR - throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); - } - - EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); - encryptedData.setCipher( value.getData() ); - - if ( IS_DEBUG ) - { - LOG.debug( "cipher : {}", StringTools.dumpBytes( value.getData() ) ); - } - - encryptedDataContainer.setGrammarEndAllowed( true ); - } - } ); + new EncryptedPartCipher() ); } Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartCipher.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartCipher.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartCipher.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartCipher.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,99 @@ +/* + * 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.encryptedData.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer; +import org.apache.directory.shared.kerberos.components.EncryptedData; +import org.apache.directory.shared.ldap.util.StringTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to store the EncryptedPart cipher + * + * @author Apache Directory Project + */ +public class EncryptedPartCipher 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 EncryptedPartKvno action. + */ + public EncryptedPartCipher() + { + super( "EncryptedPart cipher" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; + + TLV tlv = encryptedDataContainer.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 ) ); + } + + Value value = tlv.getValue(); + + // The encrypted data should not be null + if ( value.getData() == null ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); + encryptedData.setCipher( value.getData() ); + + if ( IS_DEBUG ) + { + LOG.debug( "cipher : {}", StringTools.dumpBytes( value.getData() ) ); + } + + encryptedDataContainer.setGrammarEndAllowed( true ); + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartEType.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartEType.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartEType.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartEType.java Sun Nov 7 01:46:04 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.encryptedData.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.asn1.util.IntegerDecoder; +import org.apache.directory.shared.asn1.util.IntegerDecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer; +import org.apache.directory.shared.kerberos.components.EncryptedData; +import org.apache.directory.shared.kerberos.components.EncryptionType; +import org.apache.directory.shared.ldap.util.StringTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to store the EncryptedPart EType + * + * @author Apache Directory Project + */ +public class EncryptedPartEType 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 EncryptedPartEType action. + */ + public EncryptedPartEType() + { + super( "EncryptedPart Etype" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; + + TLV tlv = encryptedDataContainer.getCurrentTLV(); + + // The Length should not be null + if ( tlv.getLength() == 0 ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + // The encyptionType is an integer + Value value = tlv.getValue(); + + EncryptionType encryptionType = null; + EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); + + try + { + int eType = IntegerDecoder.parse( value ); + encryptionType = EncryptionType.getTypeByOrdinal( eType ); + + encryptedData.setEType( encryptionType ); + + if ( IS_DEBUG ) + { + LOG.debug( "etype : " + encryptionType ); + } + } + catch ( IntegerDecoderException ide ) + { + LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide + .getLocalizedMessage() ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( ide.getMessage() ); + } + + if ( IS_DEBUG ) + { + LOG.debug( "EncryptionType : {}", encryptionType ); + } + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartInit.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartInit.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartInit.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartInit.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,84 @@ +/* + * 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.encryptedData.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer; +import org.apache.directory.shared.kerberos.components.EncryptedData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the EncryptedPart object + * + * @author Apache Directory Project + */ +public class EncryptedPartInit 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 EncryptedPartInit action. + */ + public EncryptedPartInit() + { + super( "Creates a EncryptedPart instance" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; + + TLV tlv = encryptedDataContainer.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 ) ); + } + + EncryptedData encryptedData = new EncryptedData(); + encryptedDataContainer.setEncryptedData( encryptedData ); + + if ( IS_DEBUG ) + { + LOG.debug( "EncryptedData created" ); + } + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartKvno.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartKvno.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartKvno.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedPartKvno.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,103 @@ +/* + * 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.encryptedData.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.asn1.util.IntegerDecoder; +import org.apache.directory.shared.asn1.util.IntegerDecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer; +import org.apache.directory.shared.kerberos.components.EncryptedData; +import org.apache.directory.shared.ldap.util.StringTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to store the EncryptedPart Kvno + * + * @author Apache Directory Project + */ +public class EncryptedPartKvno 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 EncryptedPartKvno action. + */ + public EncryptedPartKvno() + { + super( "EncryptedPart kvno" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + EncryptedDataContainer encryptedDataContainer = ( EncryptedDataContainer ) container; + + TLV tlv = encryptedDataContainer.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 ) ); + } + + Value value = tlv.getValue(); + + try + { + int kvno = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE ); + + EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); + encryptedData.setKvno( kvno ); + + if ( IS_DEBUG ) + { + LOG.debug( "kvno : {}", kvno ); + } + } + catch ( IntegerDecoderException ide ) + { + LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide + .getLocalizedMessage() ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( ide.getMessage() ); + } + } +} Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java?rev=1032195&r1=1032194&r2=1032195&view=diff ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java (original) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/PrincipalNameGrammar.java Sun Nov 7 01:46:04 2010 @@ -20,20 +20,15 @@ package org.apache.directory.shared.kerberos.codec.principalName; -import org.apache.directory.shared.asn1.ber.Asn1Container; 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.GrammarAction; import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition; -import org.apache.directory.shared.asn1.ber.tlv.TLV; import org.apache.directory.shared.asn1.ber.tlv.UniversalTag; -import org.apache.directory.shared.asn1.codec.DecoderException; -import org.apache.directory.shared.i18n.I18n; import org.apache.directory.shared.kerberos.KerberosConstants; import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength; +import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameInit; import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameString; import org.apache.directory.shared.kerberos.codec.principalName.actions.PrincipalNameNameType; -import org.apache.directory.shared.kerberos.components.PrincipalName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,32 +71,8 @@ public final class PrincipalNameGrammar // PrincipalName ::= SEQUENCE super.transitions[PrincipalNameStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition( PrincipalNameStatesEnum.START_STATE, PrincipalNameStatesEnum.PRINCIPAL_NAME_SEQ_STATE, UniversalTag.SEQUENCE.getValue(), - new GrammarAction( "principalName SEQUENCE" ) - { - public void action( Asn1Container container ) throws DecoderException - { - PrincipalNameContainer principalNameContainer = ( PrincipalNameContainer ) container; - - TLV tlv = principalNameContainer.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 ) ); - } - - PrincipalName principalName = new PrincipalName(); - principalNameContainer.setPrincipalName( principalName ); - - if ( IS_DEBUG ) - { - LOG.debug( "PrincipalName created" ); - } - } - } ); + new PrincipalNameInit() ) ; + // -------------------------------------------------------------------------------------------- // Transition from PrincipalName SEQ to name-type tag @@ -112,6 +83,7 @@ public final class PrincipalNameGrammar PrincipalNameStatesEnum.PRINCIPAL_NAME_SEQ_STATE, PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_TYPE_TAG_STATE, KerberosConstants.PRINCIPAL_NAME_NAME_TYPE_TAG, new CheckNotNullLength() ); + // -------------------------------------------------------------------------------------------- // Transition from name-type tag to name-type value // -------------------------------------------------------------------------------------------- @@ -121,6 +93,7 @@ public final class PrincipalNameGrammar PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_TYPE_TAG_STATE, PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_TYPE_STATE, UniversalTag.INTEGER.getValue(), new PrincipalNameNameType() ); + // -------------------------------------------------------------------------------------------- // Transition from name-type value to name-string tag // -------------------------------------------------------------------------------------------- @@ -131,6 +104,7 @@ public final class PrincipalNameGrammar PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_TYPE_STATE, PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_STRING_TAG_STATE, KerberosConstants.PRINCIPAL_NAME_NAME_STRING_TAG, new CheckNotNullLength() ); + // -------------------------------------------------------------------------------------------- // Transition from name-string tag to name-string SEQ // -------------------------------------------------------------------------------------------- @@ -141,6 +115,7 @@ public final class PrincipalNameGrammar PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_STRING_TAG_STATE, PrincipalNameStatesEnum.PRINCIPAL_NAME_NAME_STRING_SEQ_STATE, UniversalTag.SEQUENCE.getValue(), new CheckNotNullLength() ); + // -------------------------------------------------------------------------------------------- // Transition from name-string SEQ to name-string value // -------------------------------------------------------------------------------------------- @@ -152,10 +127,6 @@ public final class PrincipalNameGrammar new PrincipalNameNameString() ); } - - // ~ Methods - // ------------------------------------------------------------------------------------ - /** * Get the instance of this grammar * Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketEncPart.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketEncPart.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketEncPart.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketEncPart.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,103 @@ +/* + * 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.ticket.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.KerberosMessageContainer; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer; +import org.apache.directory.shared.kerberos.components.EncryptedData; +import org.apache.directory.shared.kerberos.messages.Ticket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the ticket EncodedPart + * + * @author Apache Directory Project + */ +public class TicketEncPart extends GrammarAction +{ + /** The logger */ + private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = LOG.isDebugEnabled(); + + + /** + * Instantiates a new TicketEncPart action. + */ + public TicketEncPart() + { + super( "Kerberos Ticket EncodedPart" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) container; + + TLV tlv = kerberosMessageContainer.getCurrentTLV(); + + // The Length should not be null + if ( tlv.getLength() == 0 ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + // Now, let's decode the PrincipalName + Asn1Decoder encryptedDataDecoder = new Asn1Decoder(); + + EncryptedDataContainer encryptedDataContainer = new EncryptedDataContainer(); + + // Decode the Ticket PDU + try + { + encryptedDataDecoder.decode( container.getStream(), encryptedDataContainer ); + } + catch ( DecoderException de ) + { + throw de; + } + + EncryptedData encryptedData = encryptedDataContainer.getEncryptedData(); + Ticket ticket = (Ticket)kerberosMessageContainer.getMessage(); + ticket.setEncPart( encryptedData ); + + if ( IS_DEBUG ) + { + LOG.debug( "EncryptedData : " + encryptedData ); + } + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketInit.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketInit.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketInit.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketInit.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,81 @@ +/* + * 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.ticket.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageContainer; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.messages.Ticket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Ticket object + * + * @author Apache Directory Project + */ +public class TicketInit 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 TicketInit action. + */ + public TicketInit() + { + super( "Kerberos Ticket initialization" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) container; + + TLV tlv = kerberosMessageContainer.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 ) ); + } + + // Create the Ticket now + Ticket ticket = new Ticket(); + + kerberosMessageContainer.setMessage( ticket ); + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketRealm.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketRealm.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketRealm.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketRealm.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.shared.kerberos.codec.ticket.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageContainer; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.messages.Ticket; +import org.apache.directory.shared.ldap.util.StringTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the ticket Realm + * + * @author Apache Directory Project + */ +public class TicketRealm extends GrammarAction +{ + /** The logger */ + private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = LOG.isDebugEnabled(); + + + /** + * Instantiates a new TicketRealm action. + */ + public TicketRealm() + { + super( "Kerberos Ticket realm value" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) container; + + TLV tlv = kerberosMessageContainer.getCurrentTLV(); + + // The Length should not be null + if ( tlv.getLength() == 0 ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + // The value is the realm + Value value = tlv.getValue(); + String realm = StringTools.utf8ToString( value.getData() ); + Ticket ticket = kerberosMessageContainer.getTicket(); + + ticket.setRealm( realm ); + + if ( IS_DEBUG ) + { + LOG.debug( "Realm : " + realm ); + } + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketSName.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,107 @@ +/* + * 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.ticket.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.KerberosMessageContainer; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.codec.principalName.PrincipalNameContainer; +import org.apache.directory.shared.kerberos.components.PrincipalName; +import org.apache.directory.shared.kerberos.messages.Ticket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the ticket SName + * + * @author Apache Directory Project + */ +public class TicketSName 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 TicketSName action. + */ + public TicketSName() + { + super( "Kerberos Ticket principalName" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) container; + + TLV tlv = kerberosMessageContainer.getCurrentTLV(); + + // The Length should not be null + if ( tlv.getLength() == 0 ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + // Now, let's decode the PrincipalName + Asn1Decoder principalNameDecoder = new Asn1Decoder(); + + PrincipalNameContainer principalNameContainer = new PrincipalNameContainer(); + + // Decode the Ticket PDU + try + { + principalNameDecoder.decode( container.getStream(), principalNameContainer ); + } + catch ( DecoderException de ) + { + throw de; + } + + // Store the Principal name in the Ticket + PrincipalName principalName = principalNameContainer.getPrincipalName(); + Ticket ticket = kerberosMessageContainer.getTicket(); + ticket.setSName( principalName ); + + // Update the parent + container.setParentTLV( tlv.getParent() ); + + if ( IS_DEBUG ) + { + LOG.debug( "PrincipalName : " + kerberosMessageContainer ); + } + } +} Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketTktVno.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketTktVno.java?rev=1032195&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketTktVno.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/ticket/actions/TicketTktVno.java Sun Nov 7 01:46:04 2010 @@ -0,0 +1,104 @@ +/* + * 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.ticket.actions; + + +import org.apache.directory.shared.asn1.ber.Asn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.asn1.util.IntegerDecoder; +import org.apache.directory.shared.asn1.util.IntegerDecoderException; +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.kerberos.codec.KerberosMessageContainer; +import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar; +import org.apache.directory.shared.kerberos.messages.Ticket; +import org.apache.directory.shared.ldap.util.StringTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the ticket VNO + * + * @author Apache Directory Project + */ +public class TicketTktVno 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 TicketTktVno action. + */ + public TicketTktVno() + { + super( "Kerberos Ticket tktvno value" ); + } + + + /** + * {@inheritDoc} + */ + public void action( Asn1Container container ) throws DecoderException + { + KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer ) container; + + TLV tlv = kerberosMessageContainer.getCurrentTLV(); + + // The Length should not be null + if ( tlv.getLength() == 0 ) + { + LOG.error( I18n.err( I18n.ERR_04066 ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); + } + + // The value should be an integer an equal to 5 + Value value = tlv.getValue(); + Ticket ticket = kerberosMessageContainer.getTicket(); + + try + { + int tktvno = IntegerDecoder.parse( value, 5, 5 ); + + ticket.setTktVno( tktvno ); + + if ( IS_DEBUG ) + { + LOG.debug( "TktVno : " + tktvno ); + } + } + catch ( IntegerDecoderException ide ) + { + LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ), ide + .getLocalizedMessage() ) ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( ide.getMessage() ); + } + } +}