A bit more on the Crypto Handle Repository.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 7 Feb 2003 05:16:03 +0000 (05:16 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 7 Feb 2003 05:16:03 +0000 (05:16 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@456 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/AuthNPrincipal.java
src/edu/internet2/middleware/shibboleth/hs/provider/BaseHandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/provider/CryptoHandleRepository.java

index c0ee9a9..139ebc9 100755 (executable)
@@ -60,6 +60,7 @@ import java.security.Principal;
 
 public class AuthNPrincipal implements Principal, Serializable {
 
+       static final long serialVersionUID = 1L;
        private String principalName;
 
        /**
index 074a069..1986273 100644 (file)
@@ -102,6 +102,8 @@ public abstract class BaseHandleRepository implements HandleRepository {
 }
 
 class HandleEntry implements Serializable {
+
+       static final long serialVersionUID = 1L;
        protected AuthNPrincipal principal;
        protected long expirationTime;
 
index fceff24..3ee14c1 100644 (file)
@@ -56,6 +56,8 @@ import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.security.NoSuchAlgorithmException;
 import java.util.Properties;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
 
 import javax.crypto.Cipher;
 import javax.crypto.KeyGenerator;
@@ -76,18 +78,23 @@ import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
  */
 public class CryptoHandleRepository extends BaseHandleRepository implements HandleRepository {
 
-       SecretKey secret;
+       static SecretKey secret;
 
        public CryptoHandleRepository(Properties properties) throws HandleRepositoryException {
                super(properties);
                KeyGenerator keyGen;
                try {
-                       keyGen = KeyGenerator.getInstance("DESede");
+                       if (secret == null) {
+                               keyGen = KeyGenerator.getInstance("DESede");
+
+                               secret = keyGen.generateKey();
+                       } else {
+                       System.err.println("Already have a key");       
+                       }
                } catch (NoSuchAlgorithmException e) {
                        System.err.println(e);
                        return;
                }
-        secret = keyGen.generateKey();
        }
 
        /**
@@ -95,10 +102,10 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
         */
        public String getHandle(AuthNPrincipal principal) {
                try {
-
                        HandleEntry handleEntry = createHandleEntry(principal);
                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-                       ObjectOutput objectStream = new ObjectOutputStream(outStream);
+                       GZIPOutputStream zipStream = new GZIPOutputStream(outStream);
+                       ObjectOutput objectStream = new ObjectOutputStream(zipStream);
                        objectStream.writeObject(handleEntry);
                        objectStream.flush();
                        objectStream.close();
@@ -120,17 +127,17 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getPrincipal(String)
         */
        public AuthNPrincipal getPrincipal(String handle) {
-               
+
                try {
                        Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
                        cipher.init(Cipher.DECRYPT_MODE, secret);
                        byte[] objectArray = cipher.doFinal(new BASE64Decoder().decodeBuffer(handle));
 
-                       ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(objectArray));
+                       ObjectInputStream objectStream =
+                               new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(objectArray)));
                        HandleEntry handleEntry = (HandleEntry) objectStream.readObject();
-                       System.err.println(handleEntry.principal.getName());
                        return handleEntry.principal;
-                       
+
                } catch (Exception e) {
                        System.err.println(e);
                        return null;