directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1039399 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/ main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/ main/java/org/apache/directory/shar...
Date Fri, 26 Nov 2010 15:01:28 GMT
Author: elecharny
Date: Fri Nov 26 15:01:27 2010
New Revision: 1039399

URL: http://svn.apache.org/viewvc?rev=1039399&view=rev
Log:
Added the PA-ENC-TIMESTAMP grammar and test

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/PaEncTimestampContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTimestamp.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTimestampDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedDataInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedDataInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedDataInit.java?rev=1039399&r1=1039398&r2=1039399&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedDataInit.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encryptedData/actions/EncryptedDataInit.java
Fri Nov 26 15:01:27 2010
@@ -72,12 +72,15 @@ public class EncryptedDataInit extends G
             throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
         }
         
-        EncryptedData encryptedData = new EncryptedData();
-        encryptedDataContainer.setEncryptedData( encryptedData );
-        
-        if ( IS_DEBUG )
+        if ( encryptedDataContainer.getEncryptedData() == null )
         {
-            LOG.debug( "EncryptedData created" );
+            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/paEncTimestamp/PaEncTimestampContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/PaEncTimestampContainer.java?rev=1039399&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/PaEncTimestampContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/paEncTimestamp/PaEncTimestampContainer.java
Fri Nov 26 15:01:27 2010
@@ -0,0 +1,51 @@
+/*
+ *  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.paEncTimestamp;
+
+import org.apache.directory.shared.kerberos.codec.encryptedData.EncryptedDataContainer;
+import org.apache.directory.shared.kerberos.components.PaEncTimestamp;
+
+
+/**
+ * The PA-ENC-TIMESTAMP container stores the PA-ENC-TIMESTAMP decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTimestampContainer extends EncryptedDataContainer
+{
+    /**
+     * Creates a new PaEncTimestampContainer object.
+     */
+    public PaEncTimestampContainer()
+    {
+        super();
+        
+        setEncryptedData( new PaEncTimestamp() );
+    }
+
+
+    /**
+     * @return Returns the PA-ENC-TIMESTAMP
+     */
+    public PaEncTimestamp getPaEncTimestamp()
+    {
+        return (PaEncTimestamp)getEncryptedData();
+    }
+}

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java?rev=1039399&r1=1039398&r2=1039399&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncryptedData.java
Fri Nov 26 15:01:27 2010
@@ -364,22 +364,32 @@ public class EncryptedData extends Abstr
         return true;
     }
 
+    
     /**
      * @see Object#toString()
      */
     public String toString()
     {
+        return toString( "" );
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString( String tabs )
+    {
         StringBuilder sb = new StringBuilder();
 
-        sb.append( "EncryptedData : {\n" );
-        sb.append( "    etype: " ).append( eType ).append( '\n' );
+        sb.append( tabs ).append( "EncryptedData : {\n" );
+        sb.append( tabs ).append( "    etype: " ).append( eType ).append( '\n' );
 
         if ( hasKvno )
         {
-            sb.append( "    kvno: " ).append( kvno ).append( '\n' );
+            sb.append( tabs ).append( "    kvno: " ).append( kvno ).append( '\n' );
         }
 
-        sb.append( "    cipher: " ).append( StringTools.dumpBytes( cipher ) ).append( "\n}\n"
);
+        sb.append( tabs ).append( "    cipher: " ).append( StringTools.dumpBytes( cipher
) ).append( "\n}\n" );
 
         return sb.toString();
     }

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTimestamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTimestamp.java?rev=1039399&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTimestamp.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/PaEncTimestamp.java
Fri Nov 26 15:01:27 2010
@@ -0,0 +1,68 @@
+/*
+ *  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;
+
+
+
+
+/**
+ * The PaEncTimestamp structure is used to store a PA-ENC-TIMESTAMP associated to a type.
+ * 
+ * The ASN.1 grammar is :
+ * <pre>
+ * PA-ENC-TIMESTAMP          ::= EncryptedData -- PA-ENC-TS-ENC
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PaEncTimestamp extends EncryptedData
+{
+    /**
+     * Creates a new instance of PA-ENC-TIMESTAMP.
+     */
+    public PaEncTimestamp()
+    {
+        super();
+    }
+
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return toString( "" );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString( String tabs )
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( tabs ).append( "PA-ENC-TIMESTAMP : {\n" );
+        sb.append( tabs ).append( super.toString( "    " + tabs) ).append( '\n' );
+
+        sb.append( tabs + "}\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTimestampDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTimestampDecoderTest.java?rev=1039399&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTimestampDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/PaEncTimestampDecoderTest.java
Fri Nov 26 15:01:27 2010
@@ -0,0 +1,116 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.paEncTimestamp.PaEncTimestampContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.PaEncTimestamp;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the PaEncTimestamp decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class PaEncTimestampDecoderTest
+{
+    /**
+     * Test the decoding of a PaEncTimestamp
+     */
+    @Test
+    public void testPaEncTimestamp()
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+        
+        stream.put( new byte[]
+            { 
+              0x30, 0x14,
+                (byte)0xA0, 0x03,                 // etype
+                  0x02, 0x01, 0x12,               //
+                (byte)0xA1, 0x03,                 // kvno
+                  0x02, 0x01, 0x05,               //
+                (byte)0xA2, 0x08,                 // cipher
+                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a PaEncTimestamp Container
+        Asn1Container paEncTimestampContainer = new PaEncTimestampContainer();
+
+        // Decode the PaEncTimestamp PDU
+        try
+        {
+            kerberosDecoder.decode( stream, paEncTimestampContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded PaEncTimestamp
+        PaEncTimestamp paEncTimestamp = ( ( PaEncTimestampContainer ) paEncTimestampContainer
).getPaEncTimestamp();
+
+        assertEquals( EncryptionType.AES256_CTS_HMAC_SHA1_96, paEncTimestamp.getEType() );
+        assertEquals( 5, paEncTimestamp.getKvno() );
+        assertTrue( Arrays.equals( StringTools.getBytesUtf8( "abcdef" ), paEncTimestamp.getCipher()
) );
+
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( paEncTimestamp.computeLength() );
+        
+        try
+        {
+            bb = paEncTimestamp.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x16, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+}



Mime
View raw message