From 8dbe6476f37c7f65947ade4aa155e5e59be0bb14 Mon Sep 17 00:00:00 2001
From: david_page <david_page@localhost>
Date: Thu, 04 Oct 2007 21:31:09 +0000
Subject: [PATCH] Issue 466 (partial) CrytoManager cleanup

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/GetSymmetricKeyExtendedOperationTestCase.java |    5 ++---
 opends/tests/unit-tests-testng/src/server/org/opends/server/types/CryptoManagerTestCase.java                         |    2 +-
 opends/src/server/org/opends/server/types/CryptoManager.java                                                         |   30 +++++++++++++++++-------------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/opends/src/server/org/opends/server/types/CryptoManager.java b/opends/src/server/org/opends/server/types/CryptoManager.java
index 7ac8b8e..617d7e8 100644
--- a/opends/src/server/org/opends/server/types/CryptoManager.java
+++ b/opends/src/server/org/opends/server/types/CryptoManager.java
@@ -359,7 +359,8 @@
     // Construct the attribute list.
     final LinkedHashSet<String> requestedAttributes
             = new LinkedHashSet<String>();
-    requestedAttributes.add(attrPublicKeyCertificate.getNameOrOID());
+    requestedAttributes.add(
+            attrPublicKeyCertificate.getNameOrOID() + ";binary");
 
     // Retrieve the certificate from the entry.
     final InternalClientConnection icc
@@ -369,9 +370,9 @@
       for (int i = 0; i < 2; ++i) {
         try {
           /* If the entry does not exist in the instance's truststore
-             backend, add it (which induces the CryptoManager to
-             create the public-key certificate attribute), then repeat
-             the search. */
+             backend, add it using a special object class that induces
+             the backend to create the public-key certificate
+             attribute, then repeat the search. */
           InternalSearchOperation searchOp = icc.processSearch(
                   entryDN,
                   SearchScope.BASE_OBJECT,
@@ -386,7 +387,6 @@
                the schema */
             certificate = e.getAttributeValue(
                     attrPublicKeyCertificate, BinarySyntax.DECODER);
-            break;
           }
           break;
         }
@@ -551,9 +551,13 @@
                 attrPublicKeyCertificate,
                 ByteStringFactory.create(instanceKeyCertificate));
         certificateValueSet.add(certificateValue);
+        final LinkedHashSet<String> certificateOptions =
+                new LinkedHashSet<String>(1);
+        certificateOptions.add(";binary");
         final Attribute certificateAttr = new Attribute(
                 attrPublicKeyCertificate,
                 attrPublicKeyCertificate.getNameOrOID(),
+                certificateOptions,
                 certificateValueSet);
         e.addAttribute(certificateAttr,
                 new ArrayList<AttributeValue>(0));
@@ -596,10 +600,10 @@
       // Construct the search filter.
       final String FILTER_OC_INSTANCE_KEY
               = new StringBuilder("(objectclass=")
-              .append(ConfigConstants.OC_CRYPTO_INSTANCE_KEY)
+              .append(ocInstanceKey.getNameOrOID())
               .append(")").toString();
       final String FILTER_NOT_COMPROMISED = new StringBuilder("(!(")
-             .append(ConfigConstants.ATTR_CRYPTO_KEY_COMPROMISED_TIME)
+              .append(attrCompromisedTime.getNameOrOID())
               .append("=*))").toString();
       final String searchFilter = new StringBuilder("(&")
               .append(FILTER_OC_INSTANCE_KEY)
@@ -608,9 +612,9 @@
       // Construct the attribute list.
       final LinkedHashSet<String> requestedAttributes
               = new LinkedHashSet<String>();
-      requestedAttributes.add(ConfigConstants.ATTR_CRYPTO_KEY_ID);
+      requestedAttributes.add(attrKeyID.getNameOrOID());
       requestedAttributes.add(
-              attrPublicKeyCertificate.getNameOrOID());
+              attrPublicKeyCertificate.getNameOrOID() + ";binary");
       // Invoke the search operation.
       final InternalClientConnection icc
               = InternalClientConnection.getRootConnection();
@@ -2568,7 +2572,7 @@
               keyLengthBits);
 
       // copy arguments.
-      this.fType = new String(transformation);
+      this.fType = transformation;
       this.fIVLengthBits = -1; /* compute IV length */
     }
 
@@ -2616,7 +2620,7 @@
       super(keyID, secretKey, secretKeyLengthBits, isCompromised);
 
       // copy arguments
-      this.fType = new String(transformation);
+      this.fType = transformation;
       this.fIVLengthBits = ivLengthBits;
     }
 
@@ -3000,7 +3004,7 @@
       super(algorithm, keyLengthBits);
 
       // copy arguments
-      this.fType = new String(algorithm);
+      this.fType = algorithm;
     }
 
     /**
@@ -3032,7 +3036,7 @@
       super(keyID, secretKey, secretKeyLengthBits, isCompromised);
 
       // copy arguments
-      this.fType = new String(algorithm);
+      this.fType = algorithm;
     }
 
 
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/GetSymmetricKeyExtendedOperationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/GetSymmetricKeyExtendedOperationTestCase.java
index 9464bd5..bf7880c 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/GetSymmetricKeyExtendedOperationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/GetSymmetricKeyExtendedOperationTestCase.java
@@ -36,7 +36,6 @@
 import org.opends.server.core.ExtendedOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.util.ServerConstants;
-import org.opends.server.util.TimeThread;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.internal.InternalSearchOperation;
@@ -77,8 +76,8 @@
     cm.publishInstanceKeyEntryInADS();
 
     // Initial encryption ensures a cipher key entry is in ADS.
-    final byte[] cipherText = cm.encrypt(cipherTransformationName,
-            cipherKeyLength, secretMessage.getBytes());
+    cm.encrypt(cipherTransformationName, cipherKeyLength,
+            secretMessage.getBytes());
 
     // Retrieve all uncompromised cipher key entries corresponding to the
     // specified transformation and key length.
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 a07c4be..ff66482 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
@@ -172,7 +172,7 @@
     public String getTransformation() {
       if (null == fAlgorithm) return null; // default
       return (null == fMode)
-              ? new String(fAlgorithm)
+              ? fAlgorithm
               : (new StringBuilder(fAlgorithm)).append("/").append(fMode)
                 .append("/").append(fPadding).toString();
     }

--
Gitblit v1.10.0