blautenb    2003/11/13 20:55:02

  Modified:    src/org/apache/xml/security/encryption XMLCipher.java
               src/org/apache/xml/security/keys KeyInfo.java
               src_unitTests/org/apache/xml/security/test/encryption
                        BaltimoreEncTest.java XMLCipherTester.java
  Log:
  XMLCipher instance no longer a global static (i.e. separate instances are now 
created)
  
  Revision  Changes    Path
  1.10      +15 -16    
xml-security/src/org/apache/xml/security/encryption/XMLCipher.java
  
  Index: XMLCipher.java
  ===================================================================
  RCS file: 
/home/cvs/xml-security/src/org/apache/xml/security/encryption/XMLCipher.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLCipher.java    13 Nov 2003 23:03:26 -0000      1.9
  +++ XMLCipher.java    14 Nov 2003 04:55:02 -0000      1.10
  @@ -170,7 +170,6 @@
       public static final int UNWRAP_MODE  = Cipher.UNWRAP_MODE;
       public static final int WRAP_MODE    = Cipher.WRAP_MODE;
   
  -    private static XMLCipher instance = null;
       private static final String ENC_ALGORITHMS = TRIPLEDES + "\n" +
           AES_128 + "\n" + AES_256 + "\n" + AES_192 + "\n" + RSA_v1dot5 + "\n" 
+
           RSA_OAEP + "\n" + TRIPLEDES_KeyWrap + "\n" + AES_128_KeyWrap + "\n" +
  @@ -284,9 +283,7 @@
           if(!isValidEncryptionAlgorithm(transformation))
               logger.error("Alogorithm unvalid, expected one of " + 
ENC_ALGORITHMS);
   
  -        if (null == instance) {
  -            instance = new XMLCipher();
  -        }
  +             XMLCipher instance = new XMLCipher();
   
           instance.algorithm = transformation;
                instance.localKey = null;
  @@ -330,9 +327,7 @@
           if(!isValidEncryptionAlgorithm(transformation))
               logger.error("Alogorithm unvalid, expected one of " + 
ENC_ALGORITHMS);
   
  -        if (null == instance) {
  -            instance = new XMLCipher();
  -        }
  +             XMLCipher instance = new XMLCipher();
   
           instance.algorithm = transformation;
                instance.requestedJCEProvider = provider;
  @@ -608,7 +603,7 @@
           if(null == source)
               logger.error("Source document unexpectedly null...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
   
           Document result = null;
   
  @@ -648,7 +643,7 @@
           if(null == element)
               logger.error("Source element unexpectedly null...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
   
           Document result = null;
   
  @@ -690,7 +685,7 @@
           if(null == element)
               logger.error("Source element unexpectedly null...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
   
           Document result = null;
   
  @@ -784,7 +779,7 @@
           if(cipherMode != ENCRYPT_MODE)
               logger.error("XMLCipher unexpectedly not in ENCRYPT_MODE...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
   
           String serializedOctets = serializer.serialize(element);
           logger.debug("Serialized octets:\n" + serializedOctets);
  @@ -849,7 +844,7 @@
           if(cipherMode != DECRYPT_MODE)
               logger.error("XMLCipher unexpectedly not in DECRYPT_MODE...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
           EncryptedData encryptedData = factory.newEncryptedData(element);
   
                return (encryptedData);
  @@ -872,10 +867,10 @@
               logger.error("Context document unexpectedly null...");
           if(null == element)
               logger.error("Element unexpectedly null...");
  -        if(cipherMode != DECRYPT_MODE)
  -            logger.error("XMLCipher unexpectedly not in DECRYPT_MODE...");
  +        if(cipherMode != UNWRAP_MODE && cipherMode != DECRYPT_MODE)
  +            logger.error("XMLCipher unexpectedly not in UNWRAP_MODE or 
DECRYPT_MODE...");
   
  -        instance.contextDocument = context;
  +        contextDocument = context;
           EncryptedKey encryptedKey = factory.newEncryptedKey(element);
   
                return (encryptedKey);
  @@ -910,11 +905,12 @@
       /**
        * Encrypts a key to an EncryptedKey structure
         *
  +      * @param doc the Context document that will be used to general DOM
         * @param key Key to encrypt (will use previously set KEK to 
         * perform encryption
        */
   
  -    public EncryptedKey encryptKey(Key key) throws
  +    public EncryptedKey encryptKey(Document doc, Key key) throws
               XMLEncryptionException {
   
           logger.debug("Encrypting key ...");
  @@ -924,6 +920,8 @@
           if(cipherMode != WRAP_MODE)
               logger.error("XMLCipher unexpectedly not in WRAP_MODE...");
   
  +             contextDocument = doc;
  +
           byte[] encryptedBytes = null;
                // Now create the working cipher
   
  @@ -1276,6 +1274,7 @@
        * </EncryptedData>
        * -->
        */
  +
       private EncryptedData createEncryptedData(int type, String value) throws
               XMLEncryptionException {
           EncryptedData result = null;
  
  
  
  1.14      +2 -1      
xml-security/src/org/apache/xml/security/keys/KeyInfo.java
  
  Index: KeyInfo.java
  ===================================================================
  RCS file: 
/home/cvs/xml-security/src/org/apache/xml/security/keys/KeyInfo.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- KeyInfo.java      13 Nov 2003 09:28:55 -0000      1.13
  +++ KeyInfo.java      14 Nov 2003 04:55:02 -0000      1.14
  @@ -609,6 +609,7 @@
   
                if (e != null) {
                        XMLCipher cipher = 
XMLCipher.getInstance(XMLCipher.TRIPLEDES);
  +                     cipher.init(XMLCipher.UNWRAP_MODE, null);
                        return cipher.loadEncryptedKey(e);
                }
                else {
  
  
  
  1.5       +1 -0      
xml-security/src_unitTests/org/apache/xml/security/test/encryption/BaltimoreEncTest.java
  
  Index: BaltimoreEncTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-security/src_unitTests/org/apache/xml/security/test/encryption/BaltimoreEncTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaltimoreEncTest.java     13 Nov 2003 09:28:08 -0000      1.4
  +++ BaltimoreEncTest.java     14 Nov 2003 04:55:02 -0000      1.5
  @@ -278,6 +278,7 @@
                // Need to pre-load the Encrypted Data so we can get the key 
info
   
                ee = (Element) 
doc.getElementsByTagName("EncryptedData").item(0);
  +             cipher.init(XMLCipher.DECRYPT_MODE, null);
                EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);
                KeyInfo ki = encryptedData.getKeyInfo();
      
  
  
  
  1.5       +11 -2     
xml-security/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java
  
  Index: XMLCipherTester.java
  ===================================================================
  RCS file: 
/home/cvs/xml-security/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLCipherTester.java      13 Nov 2003 23:06:48 -0000      1.4
  +++ XMLCipherTester.java      14 Nov 2003 04:55:02 -0000      1.5
  @@ -178,12 +178,12 @@
   
               cipher = XMLCipher.getInstance(XMLCipher.AES_192_KeyWrap);
                        cipher.init(XMLCipher.WRAP_MODE, kek);
  -                     EncryptedKey encryptedKey = cipher.encryptKey(key);
  -                     cipher.addEncryptedKey(encryptedKey);
  +                     EncryptedKey encryptedKey = cipher.encryptKey(d, key);
   
               // encrypt
               cipher = XMLCipher.getInstance(XMLCipher.AES_128);
               cipher.init(XMLCipher.ENCRYPT_MODE, key);
  +                     cipher.addEncryptedKey(encryptedKey);
               ed = cipher.doFinal(d, e);
   
               //decrypt
  @@ -192,6 +192,13 @@
               cipher = XMLCipher.getInstance(XMLCipher.AES_128);
               cipher.init(XMLCipher.DECRYPT_MODE, null);
                        EncryptedData encryptedData = 
cipher.loadEncryptedData(ed, ee);
  +
  +                     if(encryptedData == null) {
  +                             System.out.println("ed is null");
  +                     }
  +                     else if (encryptedData.getKeyInfo() == null) {
  +                             System.out.println("ki is null");
  +                     }
                        EncryptedKey ek = 
encryptedData.getKeyInfo().itemEncryptedKey(0);
   
                        if (ek != null) {
  @@ -202,6 +209,8 @@
                        }
   
               cipher.init(XMLCipher.DECRYPT_MODE, key);
  +                     XMLCipher cipher3 = 
XMLCipher.getInstance(XMLCipher.AES_128);
  +                     cipher3.init(XMLCipher.WRAP_MODE, null);
               dd = cipher.doFinal(ed, ee);
   
               target = toString(dd);
  
  
  

Reply via email to