From d0f590f8d3d9568664c032196ae403ceda1db88a Mon Sep 17 00:00:00 2001
From: david_page <david_page@localhost>
Date: Mon, 08 Oct 2007 19:53:28 +0000
Subject: [PATCH] issue 466 (partial) CryptoManager some more i18n changes maybe fix unit test failures on Linux / Java 6

---
 opends/src/messages/messages/core.properties                                                 |   14 ++++++-
 opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java |   12 ++++--
 opends/src/server/org/opends/server/types/CryptoManager.java                                 |   43 +++++++++------------
 3 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/opends/src/messages/messages/core.properties b/opends/src/messages/messages/core.properties
index 2253e8e..18c604a 100644
--- a/opends/src/messages/messages/core.properties
+++ b/opends/src/messages/messages/core.properties
@@ -1689,7 +1689,17 @@
  failed to retrieve entry "%s" (the instance-key-pair public-key certificate):  %s
 SEVERE_ERR_CRYPTOMGR_FAILED_TO_COMPUTE_INSTANCE_KEY_IDENTIFIER_667=CryptoManager \
  failed to compute an instance key identifier:  %s
-SEVERE_ERR_CRYPTOMGR_FAILED_TO_ADD_INSTANCE_KEY_ENTRY_TO_ADS_668=CryptoManager \
- failed to add entry "%s"
+SEVERE_ERR_CRYPTOMGR_FAILED_TO_ADD_INSTANCE_KEY_ENTRY_TO_ADS_668=Failed \
+ to add entry "%s"
 SEVERE_ERR_CRYPTOMGR_FAILED_TO_PUBLISH_INSTANCE_KEY_ENTRY_669=CryptoManager \
  failed to publish the instance-key-pair public-key-certificate entry in ADS:  %s
+SEVERE_ERR_CRYPTOMGR_FAILED_TO_RETRIEVE_ADS_TRUSTSTORE_CERTS_670=CryptoManager \
+ failed to retrieve the collection of instance-key-pair public-key-certificates \
+ from ADS container \"%s\":  %s
+SEVERE_ERR_CRYPTOMGR_FAILED_TO_ENCODE_SYMMETRIC_KEY_ATTRIBUTE_671=CryptoManager \
+ failed to encode symmetric key attribute value:  %s
+SEVERE_ERR_CRYPTOMGR_PARSE_SYMMETRIC_KEY_ATTRIBUTE_FIELD_COUNT_672=CryptoManager \
+ symmetric key attribute value \"%s\" syntax is invalid: incorrect number of fields
+SEVERE_ERR_CRYPTOMGR_PARSE_SYMMETRIC_KEY_ATTRIBUTE_SYNTAX_673=CryptoManager \
+ symmetric key attribute value \"%s\" syntax is invalid. Parsing failed in field \
+ \"%s\" at offset \"%d\"
diff --git a/opends/src/server/org/opends/server/types/CryptoManager.java b/opends/src/server/org/opends/server/types/CryptoManager.java
index 89f57cb..ee2d5f1 100644
--- a/opends/src/server/org/opends/server/types/CryptoManager.java
+++ b/opends/src/server/org/opends/server/types/CryptoManager.java
@@ -420,7 +420,7 @@
       }
       throw new CryptoManagerException(
             ERR_CRYPTOMGR_FAILED_TO_RETRIEVE_INSTANCE_CERTIFICATE.get(
-                    getExceptionMessage(ex), entryDN.toString()), ex);
+                    entryDN.toString(), getExceptionMessage(ex)), ex);
     }
     return(certificate);
   }
@@ -648,11 +648,9 @@
         TRACER.debugCaught(DebugLogLevel.ERROR, ex);
       }
       throw new CryptoManagerException(
-              // TODO: i18n
-              Message.raw("Error retrieving instance-key public key"
-                      + " certificates from ADS container %s:  "
-                      + getExceptionMessage(ex).toString(),
-                      instanceKeysDN.toString()), ex);
+            ERR_CRYPTOMGR_FAILED_TO_RETRIEVE_ADS_TRUSTSTORE_CERTS.get(
+                    instanceKeysDN.toString(),
+                    getExceptionMessage(ex)), ex);
     }
     return(certificateMap);
   }
@@ -717,9 +715,8 @@
         TRACER.debugCaught(DebugLogLevel.ERROR, ex);
       }
       throw new CryptoManagerException(
-              // TODO: i18n
-              Message.raw("Failed to wrap secret key: " +
-              getExceptionMessage(ex)), ex);
+           ERR_CRYPTOMGR_FAILED_TO_ENCODE_SYMMETRIC_KEY_ATTRIBUTE.get(
+                   getExceptionMessage(ex)), ex);
     }
 
     // Compose ds-cfg-symmetric-key value.
@@ -754,6 +751,14 @@
           final String symmetricKeyAttribute)
           throws CryptoManagerException {
     // Initial decomposition.
+    String[] elements = symmetricKeyAttribute.split(":", 0);
+    if (5 != elements.length) {
+      throw new CryptoManagerException(
+          ERR_CRYPTOMGR_PARSE_SYMMETRIC_KEY_ATTRIBUTE_FIELD_COUNT.get(
+                  symmetricKeyAttribute));
+     }
+
+    // Parse individual fields.
     String wrappingKeyIDElement;
     String wrappingTransformationElement;
     String wrappedKeyAlgorithmElement;
@@ -761,13 +766,6 @@
     byte[] wrappedKeyCipherTextElement;
     String fieldName = null;
     try {
-      String[] elements = symmetricKeyAttribute.split(":", 0);
-      if (5 != elements.length) {
-        throw new ParseException(
-                // TODO: i18n
-                Message.raw("Incorrect number of fields.").toString(),
-                0);
-      }
       fieldName = "instance key identifier";
       wrappingKeyIDElement = elements[0];
       fieldName = "key wrapping transformation";
@@ -799,15 +797,10 @@
       if (debugEnabled()) {
         TRACER.debugCaught(DebugLogLevel.ERROR, ex);
       }
-      throw new CryptoManagerException(((null == fieldName)
-              // TODO: i18n
-              ? Message.raw("The syntax of the symmetric key" +
-              " attribute value \"%s\" is invalid:",
-              symmetricKeyAttribute)
-              : Message.raw("The syntax of the symmetric key" +
-              " attribute value \"%s\" is invalid. Parsing failed" +
-              " in field: %s, offset %d.", symmetricKeyAttribute,
-              fieldName, ex.getErrorOffset())), ex);
+      throw new CryptoManagerException(
+              ERR_CRYPTOMGR_PARSE_SYMMETRIC_KEY_ATTRIBUTE_SYNTAX.get(
+                      symmetricKeyAttribute, fieldName,
+                      ex.getErrorOffset()), ex);
     }
 
     // Confirm key can be unwrapped at this instance.
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java
index 0577bf3..faa2262 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java
@@ -36,6 +36,7 @@
 import org.opends.server.config.ConfigConstants;
 import org.opends.server.util.StaticUtils;
 import org.opends.server.util.TimeThread;
+import org.opends.server.util.EmbeddedUtils;
 
 import org.opends.server.core.DirectoryServer;
 import org.opends.admin.ads.util.ConnectionUtils;
@@ -85,7 +86,8 @@
    */
   @AfterClass()
   public void CleanUp() throws Exception {
-    // TODO: remove at least secret key entries added in this exercise.
+    // Removes at least secret keys added in this test case.
+    TestCaseUtils.restartServer();
   }
 
 
@@ -323,7 +325,7 @@
 
    @throws Exception  In case an error occurs in the encryption routine.
    */
-  @Test(enabled=true)
+  @Test()
   public void testKeyPersistence()
         throws Exception {
     final CryptoManager cm = DirectoryServer.getCryptoManager();
@@ -334,8 +336,10 @@
     final byte[] cipherText2 = cm.encrypt("RC4", 104,
             secretMessage.getBytes());
 
-    DirectoryServer.restart(this.getClass().getName(),
-            Message.raw("CryptoManager: testing persistent secret keys."));
+    EmbeddedUtils.restartServer(
+            this.getClass().getName(),
+            Message.raw("CryptoManager: testing persistent secret keys."),
+            DirectoryServer.getEnvironmentConfig());
 
     byte[] plainText = cm.decrypt(cipherText);
     assertEquals((new String(plainText)), secretMessage);

--
Gitblit v1.10.0