*** empty log message ***
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / common / AttributeQueryHandle.java
index 96b9d6f..579e9b1 100755 (executable)
@@ -29,7 +29,7 @@ public class AttributeQueryHandle {
         * 
         */
 
-       public AttributeQueryHandle(String handle, SecretKey key)
+       public AttributeQueryHandle(byte[] handle, SecretKey key)
                throws HandleException {
 
                try {
@@ -37,10 +37,13 @@ public class AttributeQueryHandle {
                        cipher.init(Cipher.DECRYPT_MODE, key);
                        StringTokenizer tokenizer =
                                new StringTokenizer(
-                                       new String(cipher.doFinal(Base64.decode(handle))),
+                                       new String(cipher.doFinal(Base64.decode(handle)), "UTF-8"),
                                        "||",
                                        false);
-                       principal = tokenizer.nextToken();
+                       principal =
+                               new String(
+                                       Base64.decode(tokenizer.nextToken().getBytes("ASCII")),
+                                       "UTF-8");
                        expirationTime = new Long(tokenizer.nextToken()).longValue();
                        handleID = tokenizer.nextToken();
                } catch (Exception e) {
@@ -70,17 +73,27 @@ public class AttributeQueryHandle {
                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();
-                       
+                               uuidGen.generateNameBasedUUID(nameSpaceUUID, hsLocation)
+                                       + ":"
+                                       + uuidGen.generateTimeBasedUUID();
+
                        Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
                        cipher.init(Cipher.ENCRYPT_MODE, key);
                        cipherTextHandle =
                                cipher.doFinal(
-                                       (principal + "||" + expirationTime + "||" + handleID)
-                                               .getBytes());
+                                       (
+                                               new String(
+                                                       Base64.encode(principal.getBytes("UTF-8")),
+                                                       "ASCII")
+                                                       + "||"
+                                                       + expirationTime
+                                                       + "||"
+                                                       + handleID).getBytes(
+                                               "UTF-8"));
 
                } catch (Exception e) {
                        throw new HandleException("Error creating handle: " + e);
@@ -98,12 +111,12 @@ public class AttributeQueryHandle {
        }
 
        /**
-        * Returns a <code>String</code> of ciphertext representing the <code>AttributeQueryHandle</code> instance.
+        * Returns bytes of ciphertext representing the <code>AttributeQueryHandle</code> instance.
         */
 
-       public String serialize() {
+       public byte[] serialize() {
 
-               return new String(Base64.encode(cipherTextHandle));
+               return Base64.encode(cipherTextHandle);
        }
 
        /**
@@ -113,7 +126,7 @@ public class AttributeQueryHandle {
 
        public boolean isExpired() {
 
-               if (System.currentTimeMillis() > expirationTime) {
+               if (System.currentTimeMillis() >= expirationTime) {
                        return true;
                } else {
                        return false;
@@ -124,7 +137,7 @@ public class AttributeQueryHandle {
        /**
         * Returns a <code>String</code> representation of the unique identifier for this handle.
         */
-       
+
        public String getHandleID() {
                return handleID;
        }