Cleanup from old HS.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 14 Jun 2002 20:41:01 +0000 (20:41 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 14 Jun 2002 20:41:01 +0000 (20:41 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@126 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/AQHTest.java [deleted file]
src/edu/internet2/middleware/shibboleth/common/AttributeQueryHandle.java [deleted file]
src/edu/internet2/middleware/shibboleth/common/Base64.java [deleted file]

diff --git a/src/edu/internet2/middleware/shibboleth/common/AQHTest.java b/src/edu/internet2/middleware/shibboleth/common/AQHTest.java
deleted file mode 100755 (executable)
index 8aeeb63..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-package edu.internet2.middleware.shibboleth.common;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.Security;
-import javax.crypto.KeyGenerator;
-import javax.crypto.SecretKey;
-import junit.framework.TestCase;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-/**
- * Exercises the <code>AttributeQueryHandle</code>
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- *
- */
-public class AQHTest extends TestCase {
-       protected SecretKey goodKey;
-       protected String testHs;
-       public AQHTest(String name) {
-               super(name);
-       }
-
-       public static void main(String args[]) {
-               junit.textui.TestRunner.run(AQHTest.class);
-       }
-
-       /**
-        * @see TestCase#setUp()
-        */
-
-       protected void setUp() {
-               try {
-                       Security.addProvider(new BouncyCastleProvider());
-                       KeyGenerator gen = KeyGenerator.getInstance("DESede");
-                       gen.init(new SecureRandom());
-                       goodKey = gen.generateKey();
-               } catch (NoSuchAlgorithmException e) {
-                       fail("Could not generate fixture (secret key)");
-               }
-               testHs = "http://www.test.com/HS";
-       }
-       /**
-        * Tests the basic, creation, serialization, and unmarshalling of the <code>AttributeQueryHandle</code>
-        */
-
-       public void testAQH() {
-               try {
-                       //Create an AQH
-                       AttributeQueryHandle originalAQH =
-                               new AttributeQueryHandle("Walter", goodKey, 300000l, testHs);
-                       //Ensure that a unique id was generated 
-                       assertNotNull("No unique id generated for handle", originalAQH.getHandleID());
-                       String cacheHandleID = originalAQH.getHandleID();
-                       //Ensure that the principal was set correctly
-                       assertEquals("Principal incorrect", "Walter", originalAQH.getPrincipal());
-                       //Test to see that the handle has not expired   
-                       //Hopefull this doesn't take more than 5 mintues to run :-)
-                       assertTrue("AttributeQueryHandle unexpectedly expired.", (!originalAQH.isExpired()));
-                       //Create a new AQH from the serialized first AQH
-                       AttributeQueryHandle secondAQH =
-                               new AttributeQueryHandle(originalAQH.serialize(), goodKey);
-                       //Ensure that the principal was set correctly
-                       assertEquals("Principal incorrect", "Walter", secondAQH.getPrincipal());
-                       //Test to see that the handle has not expired   
-                       //Hopefull this doesn't take more than 5 mintues to run :-)
-                       assertTrue("AttributeQueryHandle unexpectedly expired.", (!secondAQH.isExpired()));
-                       //Make sure that the handle id matches that of the first object
-                       assertEquals(
-                               "Improper unmarshalling of unique handle id",
-                               cacheHandleID,
-                               secondAQH.getHandleID());
-               } catch (HandleException e) {
-                       fail("Failed to create AttributeQueryHandle" + e);
-               }
-       }
-       /**
-        * Ensure that <code>AttributeQueryHandle</code> objects expire correctly
-        */
-       public void testExpiration() {
-               try {
-                       AttributeQueryHandle aqh = new AttributeQueryHandle("Walter", goodKey, 1l, testHs);
-                       Thread.sleep(50);
-                       assertTrue("AttributeQueryHandle failed to expire appropriately", aqh.isExpired());
-               } catch (InterruptedException e) {
-               } catch (HandleException e) {
-                       fail("Failed to create AttributeQueryHandle" + e);
-               }
-       }
-       /**
-        * Ensure that all of our UUIDs are not identical
-        */
-       public void testDups() {
-               try {
-                       AttributeQueryHandle aqh1 = new AttributeQueryHandle("Walter", goodKey, 1l, testHs);
-                       AttributeQueryHandle aqh2 = new AttributeQueryHandle("Walter", goodKey, 1l, testHs);
-                       assertTrue(
-                               "Reusing a UUID when creating new AQH",
-                               !aqh1.getHandleID().equals(aqh2.getHandleID()));
-               } catch (HandleException e) {
-                       fail("Failed to create AttributeQueryHandle" + e);
-               }
-       }
-       
-       /**
-        * Make sure that it is works to create an AQH where the username contains
-        * the character that is used for field separation during serialization
-        */
-       
-       public void testSeparator() {
-               
-               try {
-                       
-               String userName = "Test||Test";
-               
-               //Create an AQH
-               AttributeQueryHandle originalAQH =
-                       new AttributeQueryHandle(userName, goodKey, 300000l, testHs);
-                       
-               //Ensure that the principal was set correctly
-               assertEquals("Principal incorrect", userName, originalAQH.getPrincipal());
-               
-               //Create a new AQH from the serialized first AQH
-               AttributeQueryHandle secondAQH =
-                       new AttributeQueryHandle(originalAQH.serialize(), goodKey);
-                       
-               //Ensure that the principal was set correctly
-               assertEquals("Principal incorrect", userName, secondAQH.getPrincipal());
-               
-               } catch (HandleException e) {
-                       fail("Failed to create AttributeQueryHandle" + e);
-               }
-               
-               
-       }
-}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/common/AttributeQueryHandle.java b/src/edu/internet2/middleware/shibboleth/common/AttributeQueryHandle.java
deleted file mode 100755 (executable)
index 579e9b1..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-package edu.internet2.middleware.shibboleth.common;
-
-import java.util.StringTokenizer;
-
-import javax.crypto.Cipher;
-import javax.crypto.SecretKey;
-import org.doomdark.uuid.UUID;
-import org.doomdark.uuid.UUIDGenerator;
-
-/**
- * A Shibboleth Attribute Query Handle.
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- *
- */
-
-public class AttributeQueryHandle {
-
-       private String principal;
-       private long creationTime;
-       private long expirationTime;
-       private byte[] cipherTextHandle;
-       private String handleID;
-
-       /**
-        * Unmarshalls an <code>AttributeQueryHandle</code> based on the results of the serialize() method
-        * of an existing <code>AttributeQueryHandle</code>.  Requires a key identical to the one used
-        * in the creation of the original <code>AttributeQueryHandle</code>.
-        * 
-        */
-
-       public AttributeQueryHandle(byte[] handle, SecretKey key)
-               throws HandleException {
-
-               try {
-                       Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
-                       cipher.init(Cipher.DECRYPT_MODE, key);
-                       StringTokenizer tokenizer =
-                               new StringTokenizer(
-                                       new String(cipher.doFinal(Base64.decode(handle)), "UTF-8"),
-                                       "||",
-                                       false);
-                       principal =
-                               new String(
-                                       Base64.decode(tokenizer.nextToken().getBytes("ASCII")),
-                                       "UTF-8");
-                       expirationTime = new Long(tokenizer.nextToken()).longValue();
-                       handleID = tokenizer.nextToken();
-               } catch (Exception e) {
-                       throw new HandleException("Error unmarshalling handle: " + e);
-               }
-
-       }
-
-       /**
-        * Creates a new <code>AttributeQueryHandle</code>
-        * @param principal <code>String</code> representation of user that the handle should reference
-        * @param validityPeriod Time in milliseconds for which the handle should be valid
-        * @param hsLocation URL of the Handle Service used to generate the AQH
-        * @param key Symmetric key used to encrypt the AQH upon serialization
-        * 
-        */
-
-       public AttributeQueryHandle(
-               String principal,
-               SecretKey key,
-               long validityPeriod,
-               String hsLocation)
-               throws HandleException {
-
-               this.principal = principal;
-               this.creationTime = System.currentTimeMillis();
-               this.expirationTime = creationTime + validityPeriod;
-
-               try {
-                       //create a unique id based on the url of the HS and the current time
-                       UUIDGenerator uuidGen = UUIDGenerator.getInstance();
-                       UUID nameSpaceUUID = new UUID(UUID.NAMESPACE_URL);
-                       handleID =
-                               uuidGen.generateNameBasedUUID(nameSpaceUUID, hsLocation)
-                                       + ":"
-                                       + uuidGen.generateTimeBasedUUID();
-
-                       Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
-                       cipher.init(Cipher.ENCRYPT_MODE, key);
-                       cipherTextHandle =
-                               cipher.doFinal(
-                                       (
-                                               new String(
-                                                       Base64.encode(principal.getBytes("UTF-8")),
-                                                       "ASCII")
-                                                       + "||"
-                                                       + expirationTime
-                                                       + "||"
-                                                       + handleID).getBytes(
-                                               "UTF-8"));
-
-               } catch (Exception e) {
-                       throw new HandleException("Error creating handle: " + e);
-
-               }
-
-       }
-
-       /**
-        * Returns a <code>String</code> representation of the user that the handle references.
-        */
-
-       public String getPrincipal() {
-               return principal;
-       }
-
-       /**
-        * Returns bytes of ciphertext representing the <code>AttributeQueryHandle</code> instance.
-        */
-
-       public byte[] serialize() {
-
-               return Base64.encode(cipherTextHandle);
-       }
-
-       /**
-        * Boolean result indicates whether the validity of this <code>AttributeQueryHandle</code> 
-        * has lapsed.
-        */
-
-       public boolean isExpired() {
-
-               if (System.currentTimeMillis() >= expirationTime) {
-                       return true;
-               } else {
-                       return false;
-               }
-
-       }
-
-       /**
-        * Returns a <code>String</code> representation of the unique identifier for this handle.
-        */
-
-       public String getHandleID() {
-               return handleID;
-       }
-
-}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/common/Base64.java b/src/edu/internet2/middleware/shibboleth/common/Base64.java
deleted file mode 100755 (executable)
index 356457e..0000000
+++ /dev/null
@@ -1,277 +0,0 @@
-package edu.internet2.middleware.shibboleth.common;
-
-/**
- * The Bouncy Castle License
- *
- * Copyright (c) 2000 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
- * <p>
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
- * and associated documentation files (the "Software"), to deal in the Software without restriction, 
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- * <p>
- * The above copyright notice and this permission notice shall be included in all copies or substantial
- * portions of the Software.
- * <p>
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-public class Base64
-{
-       private static final byte[] encodingTable =
-               {
-                   (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G',
-            (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N',
-            (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U',
-            (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z',
-                   (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g',
-            (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n',
-            (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u',
-            (byte)'v',
-                   (byte)'w', (byte)'x', (byte)'y', (byte)'z',
-                   (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6',
-            (byte)'7', (byte)'8', (byte)'9',
-                   (byte)'+', (byte)'/'
-               };
-
-       /**
-        * encode the input data producong a base 64 encoded byte array.
-        *
-        * @return a byte array containing the base 64 encoded data.
-        */
-       public static byte[] encode(
-               byte[]  data)
-       {
-               byte[]  bytes;
-               
-               int modulus = data.length % 3;
-               if (modulus == 0)
-               {
-                       bytes = new byte[4 * data.length / 3];
-               }
-               else
-               {
-                       bytes = new byte[4 * ((data.length / 3) + 1)];
-               }
-
-        int dataLength = (data.length - modulus);
-               int a1, a2, a3;
-               for (int i = 0, j = 0; i < dataLength; i += 3, j += 4)
-               {
-                       a1 = data[i] & 0xff;
-                       a2 = data[i + 1] & 0xff;
-                       a3 = data[i + 2] & 0xff;
-
-                       bytes[j] = encodingTable[(a1 >>> 2) & 0x3f];
-                       bytes[j + 1] = encodingTable[((a1 << 4) | (a2 >>> 4)) & 0x3f];
-                       bytes[j + 2] = encodingTable[((a2 << 2) | (a3 >>> 6)) & 0x3f];
-                       bytes[j + 3] = encodingTable[a3 & 0x3f];
-               }
-
-               /*
-                * process the tail end.
-                */
-               int     b1, b2, b3;
-               int     d1, d2;
-
-               switch (modulus)
-               {
-               case 0:         /* nothing left to do */
-                       break;
-               case 1:
-                       d1 = data[data.length - 1] & 0xff;
-                       b1 = (d1 >>> 2) & 0x3f;
-                       b2 = (d1 << 4) & 0x3f;
-
-                       bytes[bytes.length - 4] = encodingTable[b1];
-                       bytes[bytes.length - 3] = encodingTable[b2];
-                       bytes[bytes.length - 2] = (byte)'=';
-                       bytes[bytes.length - 1] = (byte)'=';
-                       break;
-               case 2:
-                       d1 = data[data.length - 2] & 0xff;
-                       d2 = data[data.length - 1] & 0xff;
-
-                       b1 = (d1 >>> 2) & 0x3f;
-                       b2 = ((d1 << 4) | (d2 >>> 4)) & 0x3f;
-                       b3 = (d2 << 2) & 0x3f;
-
-                       bytes[bytes.length - 4] = encodingTable[b1];
-                       bytes[bytes.length - 3] = encodingTable[b2];
-                       bytes[bytes.length - 2] = encodingTable[b3];
-                       bytes[bytes.length - 1] = (byte)'=';
-                       break;
-               }
-
-               return bytes;
-       }
-
-       /*
-        * set up the decoding table.
-        */
-       private static final byte[] decodingTable;
-
-       static
-       {
-               decodingTable = new byte[128];
-
-               for (int i = 'A'; i <= 'Z'; i++)
-               {
-                       decodingTable[i] = (byte)(i - 'A');
-               }
-
-               for (int i = 'a'; i <= 'z'; i++)
-               {
-                       decodingTable[i] = (byte)(i - 'a' + 26);
-               }
-
-               for (int i = '0'; i <= '9'; i++)
-               {
-                       decodingTable[i] = (byte)(i - '0' + 52);
-               }
-
-               decodingTable['+'] = 62;
-               decodingTable['/'] = 63;
-       }
-
-       /**
-        * decode the base 64 encoded input data.
-        *
-        * @return a byte array representing the decoded data.
-        */
-       public static byte[] decode(
-               byte[]  data)
-       {
-               byte[]  bytes;
-               byte    b1, b2, b3, b4;
-
-               if (data[data.length - 2] == '=')
-               {
-                       bytes = new byte[(((data.length / 4) - 1) * 3) + 1];
-               }
-               else if (data[data.length - 1] == '=')
-               {
-                       bytes = new byte[(((data.length / 4) - 1) * 3) + 2];
-               }
-               else
-               {
-                       bytes = new byte[((data.length / 4) * 3)];
-               }
-
-               for (int i = 0, j = 0; i < data.length - 4; i += 4, j += 3)
-               {
-                       b1 = decodingTable[data[i]];
-                       b2 = decodingTable[data[i + 1]];
-                       b3 = decodingTable[data[i + 2]];
-                       b4 = decodingTable[data[i + 3]];
-
-                       bytes[j] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[j + 1] = (byte)((b2 << 4) | (b3 >> 2));
-                       bytes[j + 2] = (byte)((b3 << 6) | b4);
-               }
-
-               if (data[data.length - 2] == '=')
-               {
-                       b1 = decodingTable[data[data.length - 4]];
-                       b2 = decodingTable[data[data.length - 3]];
-
-                       bytes[bytes.length - 1] = (byte)((b1 << 2) | (b2 >> 4));
-               }
-               else if (data[data.length - 1] == '=')
-               {
-                       b1 = decodingTable[data[data.length - 4]];
-                       b2 = decodingTable[data[data.length - 3]];
-                       b3 = decodingTable[data[data.length - 2]];
-
-                       bytes[bytes.length - 2] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[bytes.length - 1] = (byte)((b2 << 4) | (b3 >> 2));
-               }
-               else
-               {
-                       b1 = decodingTable[data[data.length - 4]];
-                       b2 = decodingTable[data[data.length - 3]];
-                       b3 = decodingTable[data[data.length - 2]];
-                       b4 = decodingTable[data[data.length - 1]];
-
-                       bytes[bytes.length - 3] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[bytes.length - 2] = (byte)((b2 << 4) | (b3 >> 2));
-                       bytes[bytes.length - 1] = (byte)((b3 << 6) | b4);
-               }
-
-               return bytes;
-       }
-
-       /**
-        * decode the base 64 encoded String data.
-        *
-        * @return a byte array representing the decoded data.
-        */
-       public static byte[] decode(
-               String  data)
-       {
-               byte[]  bytes;
-               byte    b1, b2, b3, b4;
-
-               if (data.charAt(data.length() - 2) == '=')
-               {
-                       bytes = new byte[(((data.length() / 4) - 1) * 3) + 1];
-               }
-               else if (data.charAt(data.length() - 1) == '=')
-               {
-                       bytes = new byte[(((data.length() / 4) - 1) * 3) + 2];
-               }
-               else
-               {
-                       bytes = new byte[((data.length() / 4) * 3)];
-               }
-
-               for (int i = 0, j = 0; i < data.length() - 4; i += 4, j += 3)
-               {
-                       b1 = decodingTable[data.charAt(i)];
-                       b2 = decodingTable[data.charAt(i + 1)];
-                       b3 = decodingTable[data.charAt(i + 2)];
-                       b4 = decodingTable[data.charAt(i + 3)];
-
-                       bytes[j] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[j + 1] = (byte)((b2 << 4) | (b3 >> 2));
-                       bytes[j + 2] = (byte)((b3 << 6) | b4);
-               }
-
-               if (data.charAt(data.length() - 2) == '=')
-               {
-                       b1 = decodingTable[data.charAt(data.length() - 4)];
-                       b2 = decodingTable[data.charAt(data.length() - 3)];
-
-                       bytes[bytes.length - 1] = (byte)((b1 << 2) | (b2 >> 4));
-               }
-               else if (data.charAt(data.length() - 1) == '=')
-               {
-                       b1 = decodingTable[data.charAt(data.length() - 4)];
-                       b2 = decodingTable[data.charAt(data.length() - 3)];
-                       b3 = decodingTable[data.charAt(data.length() - 2)];
-
-                       bytes[bytes.length - 2] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[bytes.length - 1] = (byte)((b2 << 4) | (b3 >> 2));
-               }
-               else
-               {
-                       b1 = decodingTable[data.charAt(data.length() - 4)];
-                       b2 = decodingTable[data.charAt(data.length() - 3)];
-                       b3 = decodingTable[data.charAt(data.length() - 2)];
-                       b4 = decodingTable[data.charAt(data.length() - 1)];
-
-                       bytes[bytes.length - 3] = (byte)((b1 << 2) | (b2 >> 4));
-                       bytes[bytes.length - 2] = (byte)((b2 << 4) | (b3 >> 2));
-                       bytes[bytes.length - 1] = (byte)((b3 << 6) | b4);
-               }
-
-               return bytes;
-       }
-}