You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/09/24 12:18:45 UTC
svn commit: r578743 [9/12] - in
/directory/apacheds/branches/apacheds-kerberos: kerberos-shared/
kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/
kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/crypto...
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosErrorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosErrorTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosErrorTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosErrorTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,240 @@
+/*
+ * 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.messages;
+
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.shared.messages.value.KerberosTime;
+import org.apache.directory.server.kerberos.shared.messages.value.types.KerberosErrorType;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the KRB-ERROR encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KerberosErrorTest extends TestCase
+{
+ private static Date date = null;
+
+ static
+ {
+ try
+ {
+ date = new SimpleDateFormat( "yyyyMMddHHmmss'Z'" ).parse( "20070717114503Z" );
+ }
+ catch ( ParseException pe )
+ {
+ // Do nothing
+ }
+ }
+
+ public void testKrbErrorBase() throws Exception
+ {
+ KerberosError kem = new KerberosError();
+
+ KerberosTime serverTime = new KerberosTime( date );
+ kem.setServerTime( serverTime );
+ kem.setServerMicroseconds( 128 );
+
+ kem.setErrorCode( KerberosErrorType.KDC_ERR_C_PRINCIPAL_UNKNOWN );
+
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "admin@APACHE.ORG" );
+ kem.setServerPrincipal( serverPrincipal );
+ kem.setServerRealm( serverPrincipal.getRealm() );
+
+ ByteBuffer encoded = ByteBuffer.allocate( kem.computeLength() );
+
+ kem.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x7E, 0x4C,
+ 0x30, 0x4A,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x1E,
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA5, 0x04,
+ 0x02, 0x02, 0x00, (byte)0x80,
+ (byte)0xA6, 0x03,
+ 0x02, 0x01, 0x06,
+ (byte)0xA9, 0x0C,
+ 0x1B, 0x0A,
+ 'A', 'P', 'A', 'C', 'H', 'E', '.', 'O', 'R', 'G',
+ (byte)0xAA, 0x12,
+ 0x30, 0x10,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x09,
+ 0x30, 0x07,
+ 0x1B, 0x05,
+ 'a', 'd', 'm', 'i', 'n'
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testKrbErrorWithClientTime() throws Exception
+ {
+ KerberosError kem = new KerberosError();
+
+ KerberosTime serverTime = new KerberosTime( date );
+ kem.setServerTime( serverTime );
+ kem.setServerMicroseconds( 128 );
+
+ kem.setClientTime( serverTime );
+
+ kem.setErrorCode( KerberosErrorType.KDC_ERR_C_PRINCIPAL_UNKNOWN );
+
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "admin@APACHE.ORG" );
+ kem.setServerPrincipal( serverPrincipal );
+ kem.setServerRealm( serverPrincipal.getRealm() );
+
+ ByteBuffer encoded = ByteBuffer.allocate( kem.computeLength() );
+
+ kem.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x7E, 0x5F,
+ 0x30, 0x5D,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x1E,
+ (byte)0xA2, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA5, 0x04,
+ 0x02, 0x02, 0x00, (byte)0x80,
+ (byte)0xA6, 0x03,
+ 0x02, 0x01, 0x06,
+ (byte)0xA9, 0x0C,
+ 0x1B, 0x0A,
+ 'A', 'P', 'A', 'C', 'H', 'E', '.', 'O', 'R', 'G',
+ (byte)0xAA, 0x12,
+ 0x30, 0x10,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x09,
+ 0x30, 0x07,
+ 0x1B, 0x05,
+ 'a', 'd', 'm', 'i', 'n'
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testKrbErrorWithAll() throws Exception
+ {
+ KerberosError kem = new KerberosError();
+
+ KerberosTime serverTime = new KerberosTime( date );
+ kem.setServerTime( serverTime );
+ kem.setServerMicroseconds( 128 );
+
+ kem.setClientTime( serverTime );
+ kem.setClientMicroSecond( 128 );
+
+ kem.setErrorCode( KerberosErrorType.KDC_ERR_C_PRINCIPAL_UNKNOWN );
+
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "admin@APACHE.ORG" );
+ kem.setServerPrincipal( serverPrincipal );
+ kem.setServerRealm( serverPrincipal.getRealm() );
+
+ kem.setClientPrincipal( serverPrincipal );
+ kem.setClientRealm( serverPrincipal.getRealm() );
+
+ kem.setExplanatoryText( "test" );
+ kem.setExplanatoryData( new byte[]{0x00, 0x01, 0x02, 0x03} );
+
+ ByteBuffer encoded = ByteBuffer.allocate( kem.computeLength() );
+
+ kem.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x7E, (byte)0x81, (byte)0x98,
+ 0x30, (byte)0x81, (byte)0x95,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x1E,
+ (byte)0xA2, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA3, 0x04,
+ 0x02, 0x02, 0x00, (byte)0x80,
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA5, 0x04,
+ 0x02, 0x02, 0x00, (byte)0x80,
+ (byte)0xA6, 0x03,
+ 0x02, 0x01, 0x06,
+ (byte)0xA7, 0x0C,
+ 0x1B, 0x0A,
+ 'A', 'P', 'A', 'C', 'H', 'E', '.', 'O', 'R', 'G',
+ (byte)0xA8, 0x12,
+ 0x30, 0x10,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x09,
+ 0x30, 0x07,
+ 0x1B, 0x05,
+ 'a', 'd', 'm', 'i', 'n',
+ (byte)0xA9, 0x0C,
+ 0x1B, 0x0A,
+ 'A', 'P', 'A', 'C', 'H', 'E', '.', 'O', 'R', 'G',
+ (byte)0xAA, 0x12,
+ 0x30, 0x10,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x09,
+ 0x30, 0x07,
+ 0x1B, 0x05,
+ 'a', 'd', 'm', 'i', 'n',
+ (byte)0xAB, 0x06,
+ 0x1B, 0x04,
+ 't', 'e', 's', 't',
+ (byte)0xAC, 0x06,
+ 0x04, 0x04,
+ 0x00, 0x01, 0x02, 0x03
+ };
+
+ assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosPrivTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosPrivTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosPrivTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/KerberosPrivTest.java Mon Sep 24 03:18:05 2007
@@ -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.server.kerberos.shared.messages;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+import org.apache.directory.server.kerberos.shared.messages.value.EncryptedData;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the KRB-PRIV encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KerberosPrivTest extends TestCase
+{
+ public void testKrbPrivBase() throws Exception
+ {
+ KerberosPriv kp = new KerberosPriv();
+
+ EncryptedData ed = new EncryptedData(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, 1,
+ new byte[] { 0x01, 0x02, 0x03, 0x04 } );
+
+ kp.setEncPart( ed );
+
+ ByteBuffer encoded = ByteBuffer.allocate( kp.computeLength() );
+
+ kp.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x75, 0x22,
+ 0x30, 0x20,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x15,
+ (byte)0xA3, 0x14,
+ 0x30, 0x12,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testKrbNoEncryptedData() throws Exception
+ {
+ KerberosPriv kp = new KerberosPriv();
+
+ try
+ {
+ kp.encode( null );
+ fail(); // We should not reach this point : null enc-part is not allowed
+ }
+ catch ( EncoderException ee )
+ {
+ assertTrue( true );
+ }
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/TicketGrantingServerRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/TicketGrantingServerRequestTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/TicketGrantingServerRequestTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/TicketGrantingServerRequestTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,258 @@
+/*
+ * 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.messages;
+
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+import org.apache.directory.server.kerberos.shared.exceptions.KerberosException;
+import org.apache.directory.server.kerberos.shared.messages.components.Ticket;
+import org.apache.directory.server.kerberos.shared.messages.value.EncryptedData;
+import org.apache.directory.server.kerberos.shared.messages.value.EncryptionKey;
+import org.apache.directory.server.kerberos.shared.messages.value.HostAddress;
+import org.apache.directory.server.kerberos.shared.messages.value.HostAddresses;
+import org.apache.directory.server.kerberos.shared.messages.value.KerberosRequestBody;
+import org.apache.directory.server.kerberos.shared.messages.value.KerberosTime;
+import org.apache.directory.server.kerberos.shared.messages.value.PreAuthenticationData;
+import org.apache.directory.server.kerberos.shared.messages.value.PrincipalName;
+import org.apache.directory.server.kerberos.shared.messages.value.flags.KdcOption;
+import org.apache.directory.server.kerberos.shared.messages.value.flags.KdcOptions;
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddressType;
+import org.apache.directory.server.kerberos.shared.messages.value.types.PreAuthenticationDataType;
+import org.apache.directory.server.kerberos.shared.messages.value.types.PrincipalNameType;
+import org.apache.directory.server.kerberos.shared.store.TicketFactory;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the TGS-REQ encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TicketGrantingServerRequestTest extends TestCase
+{
+ private static Date date = null;
+
+ static
+ {
+ try
+ {
+ date = new SimpleDateFormat( "yyyyMMddHHmmss'Z'" ).parse( "20070717114503Z" );
+ }
+ catch ( ParseException pe )
+ {
+ // Do nothing
+ }
+ }
+
+ private KerberosRequestBody getReqBody() throws ParseException, KerberosException
+ {
+ KerberosRequestBody krb = new KerberosRequestBody();
+
+ // KdcOptions
+ KdcOptions kdcOptions = new KdcOptions();
+ kdcOptions.setFlag( KdcOption.FORWARDABLE );
+ kdcOptions.setFlag( KdcOption.PROXIABLE );
+ kdcOptions.setFlag( KdcOption.POSTDATED );
+ kdcOptions.setFlag( KdcOption.VALIDATE );
+
+ krb.setKdcOptions( kdcOptions );
+
+ // cName
+ PrincipalName cname = new PrincipalName( "test@APACHE.ORG", PrincipalNameType.KRB_NT_PRINCIPAL );
+ krb.setClientPrincipalName( cname );
+
+ // Realm
+ krb.setRealm( "APACHE.ORG" );
+
+ // sName
+ PrincipalName sname = new PrincipalName( "server@APACHE.ORG", PrincipalNameType.KRB_NT_PRINCIPAL );
+ krb.setServerPrincipalName( sname );
+
+ // from, till and renew
+ KerberosTime kerberosTime = new KerberosTime( date );
+ krb.setFrom( kerberosTime );
+ krb.setTill( kerberosTime );
+ krb.setRenewtime( kerberosTime );
+
+ // nonce
+ krb.setNonce( 1000 );
+
+ // EncryptionTypes
+ krb.addEncryptionType( EncryptionType.AES128_CTS_HMAC_SHA1_96 );
+ krb.addEncryptionType( EncryptionType.DES3_CBC_MD5 );
+
+ // addresses
+ HostAddress[] ha = new HostAddress[]
+ {
+ new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[] { 0x01, 0x02, 0x03, 0x04 } )
+ };
+
+ HostAddresses addresses = new HostAddresses( ha );
+ krb.setAddresses( addresses );
+
+ // encAuthorizationData
+ EncryptedData ed = new EncryptedData( EncryptionType.AES128_CTS_HMAC_SHA1_96, 1, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } );
+ krb.setEncAuthorizationData( ed );
+
+ // additionalTickets
+ TicketFactory ticketFactory = new TicketFactory();
+
+ KerberosPrincipal clientPrincipal = new KerberosPrincipal( "hnelson@EXAMPLE.COM" );
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "kadmin/changepw@EXAMPLE.COM" );
+ String serverPassword = "s3crEt";
+
+ EncryptionKey serverKey = ticketFactory.getServerKey( serverPrincipal, serverPassword );
+
+ Ticket serviceTicket = ticketFactory.getTicket( clientPrincipal, serverPrincipal, serverKey );
+
+ krb.addAdditionalTicket( serviceTicket );
+
+ return krb;
+ }
+
+ public void testTicketGrantingServerRequestBase() throws Exception
+ {
+ PreAuthenticationData pad = new PreAuthenticationData(
+ PreAuthenticationDataType.PA_ASF3_SALT,
+ new byte[] { 0x01, 0x02, 0x03 } );
+
+ List<PreAuthenticationData> paData = new ArrayList<PreAuthenticationData>();
+ paData.add( pad );
+
+ TicketGrantingServerRequest tgsr = new TicketGrantingServerRequest( paData, getReqBody() );
+
+ ByteBuffer encoded = tgsr.encode( null );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x6C, (byte)0x82, 0x01, (byte)0xD1,
+ 0x30, (byte)0x82, 0x01, (byte)0xCD,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA2, 0x03,
+ 0x02, 0x01, 0x0C,
+ (byte)0xA3, 0x10,
+ 0x30, 0x0E,
+ 0x30, 0x0C,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x0A,
+ (byte)0xA2, 0x05,
+ 0x04, 0x03,
+ 0x01, 0x02, 0x03,
+ (byte)0xA4, (byte)0x82, 0x01, (byte)0xAD,
+ 0x30, (byte)0x82, 0x01, (byte)0xA9,
+ (byte)0xA0, 0x07,
+ 0x03, 0x05,
+ 0x00, (byte)0x52, 0x00, 0x00, 0x01,
+ (byte)0xA1, 0x11,
+ 0x30, 0x0F,
+ (byte) 0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte) 0xA1, 0x08,
+ 0x30, 0x06,
+ 0x1B, 0x04,
+ 't', 'e', 's', 't',
+ (byte)0xA2,0x0C,
+ 0x1B, 0x0A,
+ 'A', 'P', 'A', 'C', 'H', 'E', '.', 'O', 'R', 'G',
+ (byte)0xA3, 0x13,
+ 0x30, 0x11,
+ (byte) 0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte) 0xA1, 0x0A,
+ 0x30, 0x08,
+ 0x1B, 0x06,
+ 's', 'e', 'r', 'v', 'e', 'r',
+ (byte)0xA4, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA6, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA7, 0x04,
+ 0x02, (byte)0x02, 0x03, (byte)0xE8,
+ (byte)0xA8, 0x08,
+ 0x30, 0x06,
+ 0x02, 0x01, 0x11,
+ 0x02, 0x01, 0x05,
+ (byte)0xA9, 0x11,
+ 0x30, 0x0F,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04,
+ (byte)0xAA, 0x14,
+ 0x30, 0x12,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA2, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04,
+ (byte)0xAB, (byte)0x81, (byte)0xF5,
+ 0x30, (byte)0x81, (byte)0xF2,
+ 0x61, (byte)0x81, (byte)0xEF,
+ 0x30, (byte)0x81, (byte)0xEC,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA2, 0x1D,
+ 0x30, 0x1B,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x14,
+ 0x30, 0x12,
+ 0x1B, 0x06,
+ 'k', 'a', 'd', 'm', 'i', 'n',
+ 0x1B, 0x08,
+ 'c', 'h', 'a', 'n', 'g', 'e', 'p', 'w',
+ (byte)0xA3, (byte)0x81, (byte)0xB6,
+ 0x30, (byte)0x81, (byte)0xB3,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x03,
+ (byte)0xA2, (byte)0x81, (byte)0xAB,
+ 0x04, (byte)0x81, (byte)0xA8
+
+ };
+
+ // We will just compared the first bytes (everyting before the encrypted data)
+ String expectedResultString = StringTools.dumpBytes( expectedResult );
+ String resultString = StringTools.dumpBytes( encoded.array() ).substring( 0, expectedResultString.length() );
+
+ assertEquals( expectedResultString, resultString );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/AuthenticatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/AuthenticatorTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/AuthenticatorTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/AuthenticatorTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,157 @@
+/*
+ * 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.messages.components;
+
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.shared.crypto.checksum.ChecksumType;
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+import org.apache.directory.server.kerberos.shared.io.encoder.AuthenticatorEncoder;
+import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationData;
+import org.apache.directory.server.kerberos.shared.messages.value.AuthorizationDataEntry;
+import org.apache.directory.server.kerberos.shared.messages.value.Checksum;
+import org.apache.directory.server.kerberos.shared.messages.value.EncryptionKey;
+import org.apache.directory.server.kerberos.shared.messages.value.KerberosTime;
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the Authenticator encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class AuthenticatorTest extends TestCase
+{
+ private static Date date = null;
+
+ static
+ {
+ try
+ {
+ date = new SimpleDateFormat( "yyyyMMddHHmmss'Z'" ).parse( "20070717114503Z" );
+ }
+ catch ( ParseException pe )
+ {
+ // Do nothing
+ }
+ }
+
+ public void testAuthenticator() throws Exception
+ {
+ Authenticator authenticator = new Authenticator();
+
+ // authenticator-vno
+ authenticator.setVersionNumber( 5 );
+
+ // crealm
+ authenticator.setClientRealm( "EXAMPLE.COM" );
+
+ // cname
+ //PrincipalName cname = new PrincipalName( "test@APACHE.ORG", PrincipalNameType.KRB_NT_PRINCIPAL );
+ KerberosPrincipal clientPrincipal = new KerberosPrincipal( "test@APACHE.ORG" );
+ authenticator.setClientPrincipal( clientPrincipal );
+
+ // cksum
+ Checksum chk = new Checksum( ChecksumType.CRC32, new byte[] { 0x01, 0x02, 0x03 } );
+ authenticator.setChecksum( chk );
+
+ // cusec
+ authenticator.setClientMicroSecond( 128 );
+
+ // ctime
+ KerberosTime cTime = new KerberosTime( date );
+ authenticator.setClientTime( cTime );
+
+ // subkey
+ EncryptionKey subkey = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96,
+ new byte[] { 0x01, 0x02, 0x03 } );
+ authenticator.setSubSessionKey( subkey );
+
+ // seqNumber
+ authenticator.setSequenceNumber( 0x1010 );
+
+ // authorization-data
+ AuthorizationData ad = new AuthorizationData();
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } ) );
+ authenticator.setAuthorizationData( ad );
+
+ byte[] encodedAuthenticator = new AuthenticatorEncoder().encode( authenticator );
+
+ ByteBuffer encoded = authenticator.encode( null );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x62, 0x7B,
+ 0x30, 0x79,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA2, 0x11,
+ 0x30, 0x0F,
+ (byte) 0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte) 0xA1, 0x08,
+ 0x30, 0x06,
+ 0x1B, 0x04,
+ 't', 'e', 's', 't',
+ (byte)0xA3, 0x0E,
+ 0x30, 0x0c,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x05,
+ 0x04, 0x03,
+ 0x01, 0x02, 0x03,
+ (byte)0xA4, 0x04,
+ 0x02, 0x02, 0x00, (byte)0x80,
+ (byte)0xA5, 0x11,
+ 0x18, 0x0F,
+ '2', '0', '0', '7', '0', '7', '1', '7', '0', '9', '4', '5', '0', '3', 'Z',
+ (byte)0xA6, 0x0E,
+ 0x30, 0x0c,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA1, 0x05,
+ 0x04, 0x03, 0x01, 0x02, 0x03,
+ (byte)0xA7, 0x04,
+ 0x02, 0x02, 0x10, 0x10,
+ (byte)0xA8, 0x11,
+ 0x30, 0x0F,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x04,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertEquals( StringTools.dumpBytes( expectedResult ) , StringTools.dumpBytes( encoded.array() ) );
+ assertEquals( StringTools.dumpBytes( encodedAuthenticator ) , StringTools.dumpBytes( encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/TicketTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/TicketTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/TicketTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/components/TicketTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,133 @@
+/*
+ * 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.messages.components;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.kerberos.shared.io.encoder.TicketEncoder;
+import org.apache.directory.server.kerberos.shared.messages.value.EncryptionKey;
+import org.apache.directory.server.kerberos.shared.store.TicketFactory;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the Ticket encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class TicketTest extends TestCase
+{
+ public void testTicket() throws Exception
+ {
+ TicketFactory ticketFactory = new TicketFactory();
+
+ KerberosPrincipal clientPrincipal = new KerberosPrincipal( "hnelson@EXAMPLE.COM" );
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "kadmin/changepw@EXAMPLE.COM" );
+ String serverPassword = "s3crEt";
+
+ EncryptionKey serverKey = ticketFactory.getServerKey( serverPrincipal, serverPassword );
+
+ Ticket serviceTicket = ticketFactory.getTicket( clientPrincipal, serverPrincipal, serverKey );
+
+ byte[] encodedTicket = TicketEncoder.encodeTicket( serviceTicket );
+
+ ByteBuffer encoded = serviceTicket.encode( null );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x61, (byte)0x81, (byte)0xEF,
+ 0x30, (byte)0x81, (byte)0xEC,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x05,
+ (byte)0xA1, 0x0D,
+ 0x1B, 0x0B,
+ 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+ (byte)0xA2, 0x1D,
+ 0x30, 0x1B,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x14,
+ 0x30, 0x12,
+ 0x1B, 0x06,
+ 'k', 'a', 'd', 'm', 'i', 'n',
+ 0x1B, 0x08,
+ 'c', 'h', 'a', 'n', 'g', 'e', 'p', 'w',
+ (byte)0xA3, (byte)0x81, (byte)0xB6,
+ 0x30, (byte)0x81, (byte)0xB3,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x03,
+ (byte)0xA2, (byte)0x81, (byte)0xAB,
+ 0x04, (byte)0x81, (byte)0xA8
+ };
+
+ // We will just compared the first bytes (everyting before the encrypted data)
+ String expectedResultString = StringTools.dumpBytes( expectedResult );
+ String resultString = StringTools.dumpBytes( encoded.array() ).substring( 0, expectedResultString.length() );
+
+ assertEquals( expectedResultString, resultString );
+ assertTrue( Arrays.equals( encodedTicket, encodedTicket ) );
+ }
+
+ /*
+ public void testTicketPerf() throws Exception
+ {
+ TicketFactory ticketFactory = new TicketFactory();
+
+ KerberosPrincipal clientPrincipal = new KerberosPrincipal( "hnelson@EXAMPLE.COM" );
+ KerberosPrincipal serverPrincipal = new KerberosPrincipal( "kadmin/changepw@EXAMPLE.COM" );
+ String serverPassword = "s3crEt";
+
+ EncryptionKey serverKey = ticketFactory.getServerKey( serverPrincipal, serverPassword );
+
+ Ticket serviceTicket = ticketFactory.getTicket( clientPrincipal, serverPrincipal, serverKey );
+
+ byte[] encodedTicket = TicketEncoder.encodeTicket( serviceTicket );
+
+ long t0 = System.currentTimeMillis();
+
+ for ( int i=0; i < 1000000; i++ )
+ {
+ TicketEncoder.encodeTicket( serviceTicket );
+ }
+
+ long t1 = System.currentTimeMillis();
+
+ System.out.println( "Delta slow = " + ( t1 - t0 ) );
+
+ long t2 = System.currentTimeMillis();
+
+ for ( int i=0; i < 1000000; i++ )
+ {
+ serviceTicket.encode( null );
+ }
+
+ long t3 = System.currentTimeMillis();
+
+ System.out.println( "Delta slow = " + ( t3 - t2 ) );
+
+ assertTrue( Arrays.equals( encodedTicket, encodedTicket ) );
+ }
+ */
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AdAndOrTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AdAndOrTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AdAndOrTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AdAndOrTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.messages.value;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the AdaNDoR encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class AdAndOrTest extends TestCase
+{
+ public void testAdAndOrOROneAuthorizationData() throws Exception
+ {
+ AdAndOr aao = new AdAndOr();
+ AuthorizationData elements = new AuthorizationData();
+ elements.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]{0x01, 0x02, 0x03, 0x04} ) );
+
+ aao.setAuthorizationData( elements );
+
+ ByteBuffer encoded = ByteBuffer.allocate( aao.computeLength() );
+
+ aao.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x18,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x11,
+ 0x30, 0x0F,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x04,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04,
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testAdAndOrORThreeAD() throws Exception
+ {
+ AuthorizationData ad = new AuthorizationData();
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]{0x01, 0x02, 0x03, 0x04} ) );
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_IF_RELEVANT, new byte[]{0x05, 0x06, 0x07, 0x08} ) );
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_MANDATORY_TICKET_EXTENSIONS, new byte[]{0x09, 0x0A, 0x0B, 0x0C} ) );
+
+ AdAndOr aao = new AdAndOr();
+ aao.setORAuthorizationData( ad );
+
+ ByteBuffer encoded = ByteBuffer.allocate( aao.computeLength() );
+
+ aao.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x36,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x2F,
+ 0x30, 0x2D,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x04,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x06,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04, 0x09, 0x0A, 0x0B, 0x0C
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/AuthorizationDataTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,102 @@
+/*
+ * 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.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the AuthorizationData encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class AuthorizationDataTest extends TestCase
+{
+ public void testAuthorizationDataOneAD() throws Exception
+ {
+ AuthorizationData ad = new AuthorizationData();
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } ) );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
+
+ ad.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0F,
+ 0x30, 0x0d,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x04,
+ ( byte ) 0xA1, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testAuthorizationDataThreeAD() throws Exception
+ {
+ AuthorizationData ad = new AuthorizationData();
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } ) );
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_IF_RELEVANT, new byte[]
+ { 0x05, 0x06, 0x07, 0x08 } ) );
+ ad.add( new AuthorizationDataEntry( AuthorizationType.AD_MANDATORY_TICKET_EXTENSIONS, new byte[]
+ { 0x09, 0x0A, 0x0B, 0x0C } ) );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
+
+ ad.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x2D,
+ 0x30, 0x0d,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x04,
+ ( byte ) 0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04,
+ 0x30, 0x0d,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ ( byte ) 0xA1, 0x06,
+ 0x04, 0x04,
+ 0x05, 0x06, 0x07, 0x08,
+ 0x30, 0x0d,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x06,
+ ( byte ) 0xA1, 0x06,
+ 0x04, 0x04,
+ 0x09, 0x0A, 0x0B, 0x0C
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/ChecksumTest.java Mon Sep 24 03:18:05 2007
@@ -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.server.kerberos.shared.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.checksum.ChecksumType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the Checksum encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class ChecksumTest extends TestCase
+{
+ public void testEncodingChecksum() throws Exception
+ {
+ Checksum chk = new Checksum( ChecksumType.CRC32, new byte[]
+ { 0x01, 0x02, 0x03 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( chk.computeLength() );
+
+ chk.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0c,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01,
+ (byte)0xA1, 0x05,
+ 0x04, 0x03,
+ 0x01, 0x02, 0x03
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingNullChecksum() throws Exception
+ {
+ Checksum chk = new Checksum( ChecksumType.CRC32, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( chk.computeLength() );
+
+ chk.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ ( byte ) 0xA0,
+ 0x03, 0x02, 0x01, 0x01,
+ ( byte ) 0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptedDataTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptedDataTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptedDataTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptedDataTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,128 @@
+/*
+ * 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.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the EncryptedData encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class EncryptedDataTest extends TestCase
+{
+ public void testEncodingEncryptedData() throws Exception
+ {
+ EncryptedData ed = new EncryptedData( EncryptionType.AES128_CTS_HMAC_SHA1_96, 1, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ed.computeLength() );
+
+ ed.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x12,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x03,
+ 0x02, 0x01, 0x01,
+ ( byte ) 0xA2, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
+ }
+
+
+ public void testEncodingEncryptedDataNullCipher() throws Exception
+ {
+ EncryptedData ed = new EncryptedData( EncryptionType.AES128_CTS_HMAC_SHA1_96, 1, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ed.computeLength() );
+
+ ed.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0E,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x03,
+ 0x02, 0x01, 0x01,
+ ( byte ) 0xA2, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingEncryptedDataNoKvno() throws Exception
+ {
+ EncryptedData ed = new EncryptedData( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ed.computeLength() );
+
+ ed.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0D,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA2, 0x06,
+ 0x04, 0x04, 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingEncryptedDataNoKvnoNullCipher() throws Exception
+ {
+ EncryptedData ed = new EncryptedData( EncryptionType.AES128_CTS_HMAC_SHA1_96, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ed.computeLength() );
+
+ ed.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA2, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionKeyTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.messages.value;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+import org.apache.directory.server.kerberos.shared.io.encoder.EncryptionKeyEncoder;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the EncryptionKey encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class EncryptionKeyTest extends TestCase
+{
+ public void testEncodingFast() throws Exception
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+ { 0x01, 0x02, 0x03 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ec.computeLength() );
+
+ ec.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0c,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x05,
+ 0x04, 0x03, 0x01, 0x02, 0x03
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingNoStructureFast() throws Exception
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ec.computeLength() );
+
+ ec.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ /*
+ public void testEncodingNoStructureSlow() throws Exception
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, null );
+
+ byte[] encoded = EncryptionKeyEncoder.encode( ec );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ (byte)0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded ) );
+ }
+ */
+
+ public void testEncodingSlow() throws Exception
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+ { 0x01, 0x02, 0x03 } );
+
+ byte[] encoded = EncryptionKeyEncoder.encode( ec );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0c,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x05,
+ 0x04, 0x03, 0x01, 0x02, 0x03
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded ) );
+ }
+
+
+ public void testPerfSlow() throws IOException
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+ { 0x01, 0x02, 0x03 } );
+ EncryptionKeyEncoder.encode( ec );
+
+ long t0 = System.currentTimeMillis();
+
+ //for ( int i = 0; i < 10000000; i++ )
+ {
+ EncryptionKeyEncoder.encode( ec );
+ }
+
+ long t1 = System.currentTimeMillis();
+
+ System.out.println( "Delta = " + ( t1 - t0 ) );
+ }
+
+
+ public void testPerfFast() throws EncoderException
+ {
+ EncryptionKey ec = new EncryptionKey( EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]
+ { 0x01, 0x02, 0x03 } );
+ ByteBuffer encoded = ByteBuffer.allocate( ec.computeLength() );
+ ec.encode( encoded );
+
+ long t0 = System.currentTimeMillis();
+
+ //for ( int i = 0; i < 40000000; i++ )
+ {
+ encoded = ByteBuffer.allocate( ec.computeLength() );
+
+ ec.encode( encoded );
+ }
+
+ long t1 = System.currentTimeMillis();
+
+ System.out.println( "Delta2 = " + ( t1 - t0 ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfo2EntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfo2EntryTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfo2EntryTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfo2EntryTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,148 @@
+/*
+ * 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.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the EncryptionTypeInfo2Entry encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class EncryptionTypeInfo2EntryTest extends TestCase
+{
+ public void testEncryptionTypeInfo2EntrySaltS2kparams() throws Exception
+ {
+ EncryptionTypeInfo2Entry eti2e = new EncryptionTypeInfo2Entry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, "test", new byte[]{ 0x01, 0x02, 0x03, 0x04} );
+
+ ByteBuffer encoded = ByteBuffer.allocate( eti2e.computeLength() );
+
+ eti2e.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x15,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x06,
+ 0x1B, 0x04,
+ 't', 'e', 's', 't',
+ ( byte ) 0xA2, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfo2EntrySalt() throws Exception
+ {
+ EncryptionTypeInfo2Entry eti2e = new EncryptionTypeInfo2Entry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, "test" );
+
+ ByteBuffer encoded = ByteBuffer.allocate( eti2e.computeLength() );
+
+ eti2e.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0D,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x06,
+ 0x1B, 0x04,
+ 't', 'e', 's', 't'
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfo2EntryNoSaltNoS2kparams() throws Exception
+ {
+ EncryptionTypeInfo2Entry eti2e = new EncryptionTypeInfo2Entry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96 );
+
+ ByteBuffer encoded = ByteBuffer.allocate( eti2e.computeLength() );
+
+ eti2e.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x05,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfo2EntryEmptySalt() throws Exception
+ {
+ EncryptionTypeInfo2Entry eti2e = new EncryptionTypeInfo2Entry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[] {} );
+
+ ByteBuffer encoded = ByteBuffer.allocate( eti2e.computeLength() );
+
+ eti2e.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA2, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfo2EntryNoSaltS2kparams() throws Exception
+ {
+ EncryptionTypeInfo2Entry eti2e = new EncryptionTypeInfo2Entry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[]{ 0x01, 0x02, 0x03, 0x04} );
+
+ ByteBuffer encoded = ByteBuffer.allocate( eti2e.computeLength() );
+
+ eti2e.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0D,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA2, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfoEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfoEntryTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfoEntryTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/EncryptionTypeInfoEntryTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,100 @@
+/*
+ * 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.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the EncryptionTypeInfoEntry encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class EncryptionTypeInfoEntryTest extends TestCase
+{
+ public void testEncryptionTypeInfoEntry() throws Exception
+ {
+ EncryptionTypeInfoEntry etie = new EncryptionTypeInfoEntry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[] { 0x01, 0x02, 0x03 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( etie.computeLength() );
+
+ etie.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0c,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x05,
+ 0x04, 0x03,
+ 0x01, 0x02, 0x03
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfoEntryNoSalt() throws Exception
+ {
+ EncryptionTypeInfoEntry etie = new EncryptionTypeInfoEntry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( etie.computeLength() );
+
+ etie.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x05,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+ public void testEncryptionTypeInfoEntryEmptySalt() throws Exception
+ {
+ EncryptionTypeInfoEntry etie = new EncryptionTypeInfoEntry(
+ EncryptionType.AES128_CTS_HMAC_SHA1_96, new byte[] {} );
+
+ ByteBuffer encoded = ByteBuffer.allocate( etie.computeLength() );
+
+ etie.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ ( byte ) 0xA0, 0x03,
+ 0x02, 0x01, 0x11,
+ ( byte ) 0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressTest.java Mon Sep 24 03:18:05 2007
@@ -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.server.kerberos.shared.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddressType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the HostAddress encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class HostAddressTest extends TestCase
+{
+ public void testEncodingHostAddressIP() throws Exception
+ {
+ HostAddress ha = new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ha.computeLength() );
+
+ ha.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingHostAddressIPNullAddress() throws Exception
+ {
+ HostAddress ha = new HostAddress( HostAddressType.ADDRTYPE_INET, null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( ha.computeLength() );
+
+ ha.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x09,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x02,
+ 0x04, 0x00
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}
Added: directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java?rev=578743&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java (added)
+++ directory/apacheds/branches/apacheds-kerberos/kerberos-shared/src/test/java/org/apache/directory/server/kerberos/shared/messages/value/HostAddressesTest.java Mon Sep 24 03:18:05 2007
@@ -0,0 +1,120 @@
+/*
+ * 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.messages.value;
+
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.server.kerberos.shared.messages.value.types.HostAddressType;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test the HostAddresses encoding and decoding
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
+ */
+public class HostAddressesTest extends TestCase
+{
+ public void testEncodingHostAddressesIPOneAddresses() throws Exception
+ {
+ HostAddress[] ha = new HostAddress[]
+ { new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } ), };
+
+ HostAddresses has = new HostAddresses( ha );
+
+ ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+ has.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x0F,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingHostAddressesIP3Addresses() throws Exception
+ {
+ HostAddress[] ha = new HostAddress[]
+ { new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[]
+ { 0x01, 0x02, 0x03, 0x04 } ), new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[]
+ { 0x05, 0x06, 0x07, 0x08 } ), new HostAddress( HostAddressType.ADDRTYPE_INET, new byte[]
+ { 0x09, 0x0A, 0x0B, 0x0C } ) };
+
+ HostAddresses has = new HostAddresses( ha );
+
+ ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+ has.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ {
+ 0x30, 0x2D,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x01, 0x02, 0x03, 0x04,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x05, 0x06, 0x07, 0x08,
+ 0x30, 0x0d,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x06,
+ 0x04, 0x04,
+ 0x09, 0x0A, 0x0B, 0x0C
+ };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+
+
+ public void testEncodingHostAddressIPNullAddress() throws Exception
+ {
+ HostAddresses has = new HostAddresses( null );
+
+ ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
+
+ has.encode( encoded );
+
+ byte[] expectedResult = new byte[]
+ { 0x30, 0x00 };
+
+ assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
+ }
+}