package edu.internet2.middleware.shibboleth.common;
-import java.net.URL;
import java.util.StringTokenizer;
import javax.crypto.Cipher;
*
*/
- public AttributeQueryHandle(String handle, SecretKey key)
+ public AttributeQueryHandle(byte[] handle, SecretKey key)
throws HandleException {
try {
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) {
/**
* Creates a new <code>AttributeQueryHandle</code>
* @param principal <code>String</code> representation of user that the handle should reference
- * @param ticketLength Time in milliseconds for which the handle should be valid
+ * @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 ticketLength,
- URL hsLocation)
+ long validityPeriod,
+ String hsLocation)
throws HandleException {
this.principal = principal;
this.creationTime = System.currentTimeMillis();
- this.expirationTime = creationTime + ticketLength;
+ 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.toString())+ ":" + 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);
}
/**
- * 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);
}
/**
public boolean isExpired() {
- if (System.currentTimeMillis() > expirationTime) {
+ 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;
}