directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1035025 - in /directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos: KerberosConstants.java KerberosMessageType.java components/KdcReq.java
Date Sun, 14 Nov 2010 17:35:58 GMT
Author: elecharny
Date: Sun Nov 14 17:35:58 2010
New Revision: 1035025

URL: http://svn.apache.org/viewvc?rev=1035025&view=rev
Log:
o Added the KDC-REQ component
o Fixed some few other minor things.

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosMessageType.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1035025&r1=1035024&r2=1035025&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
Sun Nov 14 17:35:58 2010
@@ -78,4 +78,10 @@ public class KerberosConstants
     public static final int KDC_REQ_BODY_ADDRESSES_TAG = 0xA9;
     public static final int KDC_REQ_BODY_ENC_AUTHZ_DATA_TAG = 0xAA;
     public static final int KDC_REQ_BODY_ADDITIONAL_TICKETS_TAG = 0xAB;
+
+    /** KRB-REQ's tags */
+    public static final int KDC_REQ_PVNO_TAG = 0xA1;
+    public static final int KDC_REQ_MSG_TYPE_TAG = 0xA2;
+    public static final int KDC_REQ_PA_DATA_TAG = 0xA3;
+    public static final int KDC_REQ_KDC_REQ_BODY_TAG = 0xA4;
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosMessageType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosMessageType.java?rev=1035025&r1=1035024&r2=1035025&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosMessageType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosMessageType.java
Sun Nov 14 17:35:58 2010
@@ -74,7 +74,7 @@ public enum KerberosMessageType
      *
      * @return The int value of this element
      */
-    public int getOrdinal()
+    public int getValue()
     {
         return value;
     }

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java?rev=1035025&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/KdcReq.java
Sun Nov 14 17:35:58 2010
@@ -0,0 +1,307 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.components;
+
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosMessageType;
+
+
+
+/**
+ * The KDC-REQ data structure. It will store the object described by the ASN.1 grammar :
+ * <pre>
+ * KDC-REQ    ::= SEQUENCE {
+ *      -- NOTE: first tag is [1], not [0]
+ *      pvno            [1] INTEGER (5) ,
+ *      msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),
+ *      padata          [3] SEQUENCE OF <PA-DATA> OPTIONAL
+                            -- NOTE: not empty --,
+ *      req-body        [4] <KDC-REQ-BODY>
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KdcReq
+{
+    /** The PVNO field */
+    private int pvno;
+    
+    /** The message type, either it's a AS-REQ or a TGS-REQ */
+    private KerberosMessageType msgType;
+    
+    /** The PA-DATAs */
+    private List<PaData> paData;
+    
+    /** The KDC-REQ-BODYl */
+    private KdcReqBody kdcReqBody;
+
+    // Storage for computed lengths
+    private transient int pvnoLength;
+    private transient int msgTypeLength;
+    private transient int paDataLength;
+    private transient int paDataSeqLength;
+    private transient int[] paDataLengths;
+    private transient int kdcReqBodyLength;
+    private transient int kdcReqSeqLength;
+    private transient int kdcReqLength;
+
+    /**
+     * Creates a new instance of KDC-REQ.
+     */
+    public KdcReq()
+    {
+        paData = new ArrayList<PaData>();
+    }
+
+
+    /**
+     * @return the pvno
+     */
+    public int getPvno()
+    {
+        return pvno;
+    }
+
+
+    /**
+     * @param pvno the pvno to set
+     */
+    public void setPvno( int pvno )
+    {
+        this.pvno = pvno;
+    }
+
+
+    /**
+     * @return the msgType
+     */
+    public KerberosMessageType getMsgType()
+    {
+        return msgType;
+    }
+
+
+    /**
+     * @param msgType the msgType to set
+     */
+    public void setMsgType( KerberosMessageType msgType )
+    {
+        this.msgType = msgType;
+    }
+
+
+    /**
+     * @return the paData
+     */
+    public List<PaData> getPaData()
+    {
+        return paData;
+    }
+
+
+    /**
+     * @param paData the paData to set
+     */
+    public void addPaData( PaData paData )
+    {
+        this.paData.add( paData );
+    }
+
+
+    /**
+     * @return the kdcReqBody
+     */
+    public KdcReqBody getKdcReqBody()
+    {
+        return kdcReqBody;
+    }
+
+
+    /**
+     * @param kdcReqBody the kdcReqBody to set
+     */
+    public void setKdcReqBody( KdcReqBody kdcReqBody )
+    {
+        this.kdcReqBody = kdcReqBody;
+    }
+
+    
+    /**
+     * Compute the KDC-REQ length
+     * 
+     * KDC-REQ :
+     * 
+     * 0x30 L1 KDC-REQ sequence
+     *  |
+     *  +--> 0xA1 0x03 pvno tag
+     *  |     |
+     *  |     +--> 0x02 0x01 0x05 pvno (5)
+     *  |
+     *  +--> 0xA2 0x03 msg-type tag
+     *  |     |
+     *  |     +--> 0x02 0x01 0x0A/0x0C msg-type : either AS-REQ (0x0A) or TGS-REQ (0x0C)
+     *  |     
+     *  +--> 0xA3 L2 pa-data tag
+     *  |     |
+     *  |     +--> 0x30 L2-1 pa-data
+     *  |     
+     *  +--> 0xA4 L3 req-body tag
+     *  |     |
+     *  |     +--> 0x30 L3-1 req-body (KDC-REQ-BODY)
+     *        
+     */
+    public int computeLength()
+    {
+        // The pvno length
+        pvnoLength = 1 + 1 + 1;
+        
+        // The msg-type length
+        msgTypeLength = 1 + 1 + 1;
+
+        // Compute the pa-data length.
+        paDataLengths = new int[paData.size()];
+        int pos = 0;
+        
+        for ( PaData paDataElem : paData )
+        {
+            paDataLengths[pos] = paDataElem.computeLength();
+            paDataSeqLength += paDataLengths[pos];
+            pos++;
+        }
+        
+        paDataLength = 1 + TLV.getNbBytes( paDataSeqLength ) + paDataSeqLength;
+        
+        // The KDC-REQ-BODY length
+        kdcReqBodyLength = kdcReqBody.computeLength();
+
+        // Compute the sequence size.
+        kdcReqSeqLength = 1 + TLV.getNbBytes( pvnoLength ) + pvnoLength; 
+        kdcReqSeqLength = 1 + TLV.getNbBytes( msgTypeLength ) + msgTypeLength; 
+        kdcReqSeqLength = 1 + TLV.getNbBytes( paDataLength ) + paDataLength; 
+        kdcReqSeqLength = 1 + TLV.getNbBytes( kdcReqBodyLength ) + kdcReqBodyLength; 
+        
+        // compute the global size
+        kdcReqLength = 1 + TLV.getNbBytes( kdcReqSeqLength ) + kdcReqSeqLength;
+        
+        return kdcReqLength;
+    }
+    
+    
+    /**
+     * Encode the KDC-REQ component
+     * 
+     * @param buffer The buffer containing the encoded result
+     * @return The encoded component
+     * @throws EncoderException If the encoding failed
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+        
+        // The KDC-REQ SEQ Tag
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+        buffer.put( TLV.getBytes( kdcReqSeqLength ) );
+        
+        // The PVNO -----------------------------------------------------------
+        // The tag
+        buffer.put( (byte)KerberosConstants.KDC_REQ_PVNO_TAG );
+        buffer.put( TLV.getBytes( pvnoLength ) );
+        
+        // The value
+        Value.encode( buffer, pvno );
+        
+        // The msg-type if any ------------------------------------------------
+        // The tag
+        buffer.put( (byte)KerberosConstants.KDC_REQ_MSG_TYPE_TAG );
+        buffer.put( TLV.getBytes( msgTypeLength ) );
+        
+        // The value
+        Value.encode( buffer, msgType.getValue() );
+        
+        // The PD-DATA --------------------------------------------------------
+        // The tag
+        buffer.put( (byte)KerberosConstants.KDC_REQ_PA_DATA_TAG );
+        buffer.put( TLV.getBytes( paDataLength ) );
+        
+        // The sequence
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+        buffer.put( TLV.getBytes( paDataSeqLength ) );
+        
+        // The values
+        for ( PaData paDataElem : paData )
+        {
+            paDataElem.encode( buffer );
+        }
+
+        // The KDC-REQ-BODY ---------------------------------------------------
+        // The tag
+        buffer.put( (byte)KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG );
+        buffer.put( TLV.getBytes( kdcReqBodyLength ) );
+        
+        // The value
+        kdcReqBody.encode( buffer );
+        
+        return buffer;
+    }
+
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "pvno : " ).append( pvno ).append( '\n' );
+
+        sb.append( "msg-type : " );
+
+        if ( msgType == KerberosMessageType.AS_REQ )
+        {
+            sb.append( "AS-REQ" ).append( '\n' );
+        }
+        else
+        {
+            sb.append( "TGS-REQ" ).append( '\n' );
+        }
+
+        for ( PaData paDataElem : paData )
+        {
+            sb.append( "padata : " ).append( paDataElem ).append( '\n' );
+        }
+        
+        sb.append( "kdc-req-body" ).append( kdcReqBody ).append( '\n' );
+        
+        return sb.toString();
+    }
+}



Mime
View raw message