directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r546368 - in /directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io: decoder/ encoder/
Date Tue, 12 Jun 2007 03:38:53 GMT
Author: erodriguez
Date: Mon Jun 11 20:38:52 2007
New Revision: 546368

URL: http://svn.apache.org/viewvc?view=rev&rev=546368
Log:
Additional codec support for Kerberos applications, such as Change Password.

Added:
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java
  (with props)
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java
  (with props)
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java
  (with props)
Modified:
    directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java

Added: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java?view=auto&rev=546368
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java
(added)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java
Mon Jun 11 20:38:52 2007
@@ -0,0 +1,95 @@
+/*
+ *  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.server.kerberos.shared.io.decoder;
+
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+import org.apache.directory.server.kerberos.shared.messages.application.ApplicationReply;
+import org.apache.directory.shared.asn1.der.ASN1InputStream;
+import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
+import org.apache.directory.shared.asn1.der.DEREncodable;
+import org.apache.directory.shared.asn1.der.DERSequence;
+import org.apache.directory.shared.asn1.der.DERTaggedObject;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 540371 $, $Date: 2007-05-21 17:00:43 -0700 (Mon, 21 May 2007) $
+ */
+public class ApplicationReplyDecoder
+{
+    /**
+     * Decodes a byte array into an {@link ApplicationReply}.
+     *
+     * @param encodedAuthHeader
+     * @return The {@link ApplicationReply}.
+     * @throws IOException
+     */
+    public ApplicationReply decode( byte[] encodedAuthHeader ) throws IOException
+    {
+        ASN1InputStream ais = new ASN1InputStream( encodedAuthHeader );
+
+        DERApplicationSpecific app = ( DERApplicationSpecific ) ais.readObject();
+
+        DERSequence apreq = ( DERSequence ) app.getObject();
+
+        return decodeApplicationRequestSequence( apreq );
+    }
+
+
+    /*
+     AP-REP ::=         [APPLICATION 15] SEQUENCE {
+     pvno[0]                   INTEGER,
+     msg-type[1]               INTEGER,
+     enc-part[2]               EncryptedData
+     }
+     */
+    private ApplicationReply decodeApplicationRequestSequence( DERSequence sequence )
+    {
+        ApplicationReply authHeader = null;
+
+        for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
+        {
+            DERTaggedObject object = ( ( DERTaggedObject ) e.nextElement() );
+            int tag = object.getTagNo();
+            DEREncodable derObject = object.getObject();
+
+            switch ( tag )
+            {
+                case 0:
+                    //DERInteger tag0 = ( DERInteger ) derObject;
+                    //authHeader.setProtocolVersionNumber( tag0.intValue() );
+                    break;
+                case 1:
+                    //DERInteger tag1 = ( DERInteger ) derObject;
+                    //authHeader.setMessageType( MessageType.getTypeByOrdinal( tag1.intValue()
) );
+                    break;
+                case 2:
+                    DERSequence tag2 = ( DERSequence ) derObject;
+                    authHeader = new ApplicationReply( EncryptedDataDecoder.decode( tag2
) );
+                    break;
+            }
+        }
+
+        return authHeader;
+    }
+}

Propchange: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/decoder/ApplicationReplyDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java?view=auto&rev=546368
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java
(added)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java
Mon Jun 11 20:38:52 2007
@@ -0,0 +1,88 @@
+/*
+ *  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.server.kerberos.shared.io.encoder;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.directory.server.kerberos.shared.messages.ApplicationRequest;
+import org.apache.directory.shared.asn1.der.ASN1OutputStream;
+import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
+import org.apache.directory.shared.asn1.der.DERInteger;
+import org.apache.directory.shared.asn1.der.DEROctetString;
+import org.apache.directory.shared.asn1.der.DERSequence;
+import org.apache.directory.shared.asn1.der.DERTaggedObject;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 540371 $, $Date: 2007-05-21 17:00:43 -0700 (Mon, 21 May 2007) $
+ */
+public class ApplicationRequestEncoder
+{
+    /**
+     * Application code constant for the {@link ApplicationRequest} (14).
+     */
+    public static final int APPLICATION_CODE = 14;
+
+
+    /**
+     * Encodes an {@link ApplicationRequest} into a byte array.
+     *
+     * @param request
+     * @return The byte array.
+     * @throws IOException
+     */
+    public byte[] encode( ApplicationRequest request ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ASN1OutputStream aos = new ASN1OutputStream( baos );
+
+        DERSequence requestSequence = encodeReplySequence( request );
+        aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, requestSequence
) );
+        aos.close();
+
+        return baos.toByteArray();
+    }
+
+
+    /*
+     AP-REQ ::=      [APPLICATION 14] SEQUENCE {
+     pvno[0]                       INTEGER,
+     msg-type[1]                   INTEGER,
+     ap-options[2]                 APOptions,
+     ticket[3]                     Ticket,
+     authenticator[4]              EncryptedData
+     }
+     */
+    private DERSequence encodeReplySequence( ApplicationRequest message )
+    {
+        DERSequence sequence = new DERSequence();
+
+        sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( message.getProtocolVersionNumber()
) ) );
+        sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( message.getMessageType().getOrdinal()
) ) );
+        sequence.add( new DERTaggedObject( 2, new DEROctetString( message.getApOptions().getBytes()
) ) );
+        sequence.add( new DERTaggedObject( 3, TicketEncoder.encode( message.getTicket() )
) );
+        sequence.add( new DERTaggedObject( 4, EncryptedDataEncoder.encodeSequence( message.getEncPart()
) ) );
+
+        return sequence;
+    }
+}

Propchange: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/ApplicationRequestEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java?view=auto&rev=546368
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java
(added)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java
Mon Jun 11 20:38:52 2007
@@ -0,0 +1,136 @@
+/*
+ *  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.server.kerberos.shared.io.encoder;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.directory.server.kerberos.shared.messages.Encodable;
+import org.apache.directory.server.kerberos.shared.messages.components.Authenticator;
+import org.apache.directory.shared.asn1.der.ASN1OutputStream;
+import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
+import org.apache.directory.shared.asn1.der.DERGeneralString;
+import org.apache.directory.shared.asn1.der.DERInteger;
+import org.apache.directory.shared.asn1.der.DERSequence;
+import org.apache.directory.shared.asn1.der.DERTaggedObject;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AuthenticatorEncoder implements Encoder, EncoderFactory
+{
+    /**
+     * Application code constant for the {@link Authenticator} (2).
+     */
+    private static final int APPLICATION_CODE = 2;
+
+
+    /**
+     * Encodes an {@link Authenticator} into a byte array.
+     *
+     * @param authenticator
+     * @return The byte array.
+     * @throws IOException
+     */
+    public byte[] encode( Encodable authenticator ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ASN1OutputStream aos = new ASN1OutputStream( baos );
+
+        DERSequence replySequence = encodeInitialSequence( ( Authenticator ) authenticator
);
+        aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, replySequence
) );
+        aos.close();
+
+        return baos.toByteArray();
+    }
+
+
+    public Encoder getEncoder()
+    {
+        return new AuthenticatorEncoder();
+    }
+
+
+    /**
+     * Encodes an {@link Authenticator} into a {@link DERSequence}.
+     * 
+     * -- Unencrypted authenticator
+     * Authenticator ::=    [APPLICATION 2] SEQUENCE
+     * {
+     *                authenticator-vno[0]          INTEGER,
+     *                crealm[1]                     Realm,
+     *                cname[2]                      PrincipalName,
+     *                cksum[3]                      Checksum OPTIONAL,
+     *                cusec[4]                      INTEGER,
+     *                ctime[5]                      KerberosTime,
+     *                subkey[6]                     EncryptionKey OPTIONAL,
+     *                seq-number[7]                 INTEGER OPTIONAL,
+     *  
+     *                authorization-data[8]         AuthorizationData OPTIONAL
+     * }
+     * 
+     * @param authenticator 
+     * @return The {@link DERSequence}.
+     */
+    private DERSequence encodeInitialSequence( Authenticator authenticator )
+    {
+        String clientRealm = authenticator.getClientPrincipal().getRealm();
+
+        DERSequence sequence = new DERSequence();
+
+        sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( authenticator.getVersionNumber()
) ) );
+        sequence.add( new DERTaggedObject( 1, DERGeneralString.valueOf( clientRealm ) ) );
+        sequence.add( new DERTaggedObject( 2, PrincipalNameEncoder.encode( authenticator.getClientPrincipal()
) ) );
+
+        // OPTIONAL
+        if ( authenticator.getChecksum() != null )
+        {
+            sequence.add( new DERTaggedObject( 3, ChecksumEncoder.encode( authenticator.getChecksum()
) ) );
+        }
+
+        sequence.add( new DERTaggedObject( 4, DERInteger.valueOf( authenticator.getClientMicroSecond()
) ) );
+        sequence.add( new DERTaggedObject( 5, KerberosTimeEncoder.encode( authenticator.getClientTime()
) ) );
+
+        // OPTIONAL
+        if ( authenticator.getSubSessionKey() != null )
+        {
+            sequence.add( new DERTaggedObject( 6, EncryptionKeyEncoder
+                .encodeSequence( authenticator.getSubSessionKey() ) ) );
+        }
+
+        // OPTIONAL
+        if ( authenticator.getSequenceNumber() > 0 )
+        {
+            sequence.add( new DERTaggedObject( 7, DERInteger.valueOf( authenticator.getSequenceNumber()
) ) );
+        }
+
+        // OPTIONAL
+        if ( authenticator.getAuthorizationData() != null )
+        {
+            sequence.add( new DERTaggedObject( 8, AuthorizationDataEncoder
+                .encode( authenticator.getAuthorizationData() ) ) );
+        }
+
+        return sequence;
+    }
+}

Propchange: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/AuthenticatorEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java?view=diff&rev=546368&r1=546367&r2=546368
==============================================================================
--- directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
(original)
+++ directory/apacheds/trunk/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/io/encoder/PrincipalNameEncoder.java
Mon Jun 11 20:38:52 2007
@@ -47,8 +47,11 @@
      *               name-type[0]     INTEGER,
      *               name-string[1]   SEQUENCE OF GeneralString
      * }
+     * 
+     * @param principal 
+     * @return The {@link DERSequence}. 
      */
-    protected static DERSequence encode( KerberosPrincipal principal )
+    public static DERSequence encode( KerberosPrincipal principal )
     {
         DERSequence vector = new DERSequence();
 



Mime
View raw message