From e2cc17fc9aaee0c03fe59b83bc22de9ec735cc91 Mon Sep 17 00:00:00 2001
From: david_page <david_page@localhost>
Date: Sun, 14 Oct 2007 00:17:05 +0000
Subject: [PATCH] No issue. CryptoManager Step 2. Factor interface from implementation.

---
 opends/src/server/org/opends/server/crypto/CryptoManager.java                                 |   54 ++-----------
 opends/src/server/org/opends/server/types/CryptoManagerException.java                         |   65 ++++++++++++++++
 opends/src/server/org/opends/server/crypto/CryptoManagerSync.java                             |    8 +-
 opends/tests/unit-tests-testng/src/server/org/opends/server/crypto/CryptoManagerTestCase.java |    2 
 opends/src/server/org/opends/server/backends/jeb/BackupManager.java                           |   14 +--
 opends/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java              |    2 
 opends/src/ads/org/opends/admin/ads/ADSContextHelper.java                                     |    3 
 opends/src/server/org/opends/server/backends/SchemaBackend.java                               |   39 +--------
 8 files changed, 91 insertions(+), 96 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java b/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
index 2292e46..bf3ebd5 100644
--- a/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
+++ b/opends/src/ads/org/opends/admin/ads/ADSContextHelper.java
@@ -51,6 +51,7 @@
 import org.opends.server.admin.std.meta.LDIFBackendCfgDefn;
 import org.opends.server.config.ConfigConstants;
 import org.opends.server.crypto.CryptoManager;
+import org.opends.server.types.CryptoManagerException;
 import org.opends.server.types.DN;
 
 /**
@@ -277,7 +278,7 @@
       throw new ADSContextException(
           ADSContextException.ErrorType.ERROR_UNEXPECTED, ne);
     }
-    catch (CryptoManager.CryptoManagerException cme)
+    catch (CryptoManagerException cme)
     {
       throw new ADSContextException(
           ADSContextException.ErrorType.ERROR_UNEXPECTED, cme);
diff --git a/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opends/src/server/org/opends/server/backends/SchemaBackend.java
index 58f3f4a..77d6c91 100644
--- a/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -80,40 +80,9 @@
 import org.opends.server.schema.MatchingRuleUseSyntax;
 import org.opends.server.schema.NameFormSyntax;
 import org.opends.server.schema.ObjectClassSyntax;
-import org.opends.server.types.Attribute;
-import org.opends.server.types.AttributeType;
-import org.opends.server.types.AttributeValue;
-import org.opends.server.types.BackupConfig;
-import org.opends.server.types.BackupDirectory;
-import org.opends.server.types.BackupInfo;
-import org.opends.server.types.ConditionResult;
-import org.opends.server.types.ConfigChangeResult;
 import org.opends.server.crypto.CryptoManager;
-import org.opends.server.types.DebugLogLevel;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.DITContentRule;
-import org.opends.server.types.DITStructureRule;
-import org.opends.server.types.DN;
-import org.opends.server.types.Entry;
-import org.opends.server.types.ExistingFileBehavior;
-import org.opends.server.types.IndexType;
-import org.opends.server.types.InitializationException;
-import org.opends.server.types.LDIFExportConfig;
-import org.opends.server.types.LDIFImportConfig;
-import org.opends.server.types.LDIFImportResult;
-import org.opends.server.types.MatchingRuleUse;
-import org.opends.server.types.Modification;
-import org.opends.server.types.ModificationType;
-import org.opends.server.types.NameForm;
-import org.opends.server.types.ObjectClass;
-import org.opends.server.types.ObjectClassType;
-import org.opends.server.types.Privilege;
-import org.opends.server.types.RDN;
-import org.opends.server.types.RestoreConfig;
-import org.opends.server.types.ResultCode;
-import org.opends.server.types.Schema;
-import org.opends.server.types.SearchFilter;
-import org.opends.server.types.SearchScope;
+import org.opends.server.types.CryptoManagerException;
+import org.opends.server.types.*;
 import org.opends.server.util.DynamicConstants;
 import org.opends.server.util.LDIFException;
 import org.opends.server.util.LDIFWriter;
@@ -4248,7 +4217,7 @@
         outputStream
                 = cryptoManager.getCipherOutputStream(outputStream);
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         if (debugEnabled())
         {
@@ -4621,7 +4590,7 @@
         inputStream = DirectoryServer.getCryptoManager()
                                          .getCipherInputStream(inputStream);
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         Message message = ERR_SCHEMA_RESTORE_CANNOT_GET_CIPHER.get(
                 backupFile.getPath(), stackTraceToSingleLineString(e));
diff --git a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
index 49f7a84..ef878da 100644
--- a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
+++ b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
@@ -30,12 +30,8 @@
 import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.util.DynamicConstants;
-import org.opends.server.types.BackupConfig;
-import org.opends.server.types.BackupDirectory;
-import org.opends.server.types.BackupInfo;
 import org.opends.server.crypto.CryptoManager;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.RestoreConfig;
+import org.opends.server.types.CryptoManagerException;
 
 import javax.crypto.Mac;
 import java.io.BufferedReader;
@@ -64,7 +60,7 @@
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
-import org.opends.server.types.DebugLogLevel;
+import org.opends.server.types.*;
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import org.opends.server.loggers.debug.DebugTracer;
@@ -347,7 +343,7 @@
         outputStream
                 = cryptoManager.getCipherOutputStream(outputStream);
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         if (debugEnabled())
         {
@@ -976,7 +972,7 @@
       {
         inputStream = cryptoManager.getCipherInputStream(inputStream);
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         if (debugEnabled())
         {
@@ -1305,7 +1301,7 @@
       {
         inputStream = cryptoManager.getCipherInputStream(inputStream);
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         if (debugEnabled())
         {
diff --git a/opends/src/server/org/opends/server/crypto/CryptoManager.java b/opends/src/server/org/opends/server/crypto/CryptoManager.java
index 3abab9a..8ec0244 100644
--- a/opends/src/server/org/opends/server/crypto/CryptoManager.java
+++ b/opends/src/server/org/opends/server/crypto/CryptoManager.java
@@ -475,7 +475,7 @@
    * @throws CryptoManagerException If the certificate cannot be
    * retrieved.
    */
-  public static byte[] getInstanceKeyCertificateFromLocalTruststore()
+  static byte[] getInstanceKeyCertificateFromLocalTruststore()
           throws CryptoManagerException {
     // Construct the key entry DN.
     final AttributeValue distinguishedValue = new AttributeValue(
@@ -566,7 +566,7 @@
    * the instance-key public-key certificate or computing its MD5
    * hash.
    */
-  public String getInstanceKeyID()
+  String getInstanceKeyID()
           throws CryptoManagerException {
     return getInstanceKeyID(
             getInstanceKeyCertificateFromLocalTruststore());
@@ -583,6 +583,9 @@
    * @return The identifier of the supplied instance key.
    * @throws CryptoManagerException If there is a problem computing
    * the identifier from the instance key.
+   *
+   * TODO: make package-private if ADSContextHelper can get keyID from ADS
+   * suffix: Issue https://opends.dev.java.net/issues/show_bug.cgi?id=2442
    */
   public static String getInstanceKeyID(byte[] instanceKeyCertificate)
             throws CryptoManagerException {
@@ -611,7 +614,7 @@
    @throws CryptoManagerException In case there is a problem
    searching for the entry, or, if necessary, adding it.
    */
-  public static void publishInstanceKeyEntryInADS()
+  static void publishInstanceKeyEntryInADS()
           throws CryptoManagerException {
     final byte[] instanceKeyCertificate
             = getInstanceKeyCertificateFromLocalTruststore();
@@ -989,7 +992,7 @@
    * the supplied symmetric key attribute value, unwrapping the
    * embedded secret key, or retrieving the requested public key.
    */
-  public String reencodeSymmetricKeyAttribute(
+  String reencodeSymmetricKeyAttribute(
           final String symmetricKeyAttribute,
           final String requestedInstanceKeyID)
           throws CryptoManagerException {
@@ -1895,7 +1898,7 @@
    *               was not already present but could not
    *               be imported.
    */
-  public void importCipherKeyEntry(Entry entry)
+  void importCipherKeyEntry(Entry entry)
        throws CryptoManagerException
   {
     // Ignore the entry if it does not have the appropriate
@@ -2123,7 +2126,7 @@
    *               was not already present but could not
    *               be imported.
    */
-  public void importMacKeyEntry(Entry entry)
+  void importMacKeyEntry(Entry entry)
        throws CryptoManagerException
   {
     // Ignore the entry if it does not have the appropriate
@@ -3380,43 +3383,4 @@
     // state
     private final String fType;
   }
-
-
-
-  /**
-   * This class defines an exception that is thrown in the case of
-   * problems with encryption key managagment, and is a wrapper for a
-   * variety of other cipher related exceptions.
-   */
-  public static class CryptoManagerException extends OpenDsException
-  {
-    /**
-     * The serial version identifier required to satisfy the compiler
-     * because this class extends <CODE>java.lang.Exception</CODE>,
-     * which implements the <CODE>java.io.Serializable</CODE>
-     * interface. This value was generated using the
-     * <CODE>serialver</CODE> command-line utility included with the
-     * Java SDK.
-     */
-    static final long serialVersionUID = -5890763923778143774L;
-
-    /**
-     * Creates an exception with the given message.
-     * @param message the message message.
-     */
-    public CryptoManagerException(Message message) {
-      super(message);
-     }
-
-    /**
-     * Creates an exception with the given message and underlying
-     * cause.
-     * @param message The message message.
-     * @param cause  The underlying cause.
-     */
-    public CryptoManagerException(Message message, Exception cause) {
-      super(message, cause);
-    }
-  }
 }
-
diff --git a/opends/src/server/org/opends/server/crypto/CryptoManagerSync.java b/opends/src/server/org/opends/server/crypto/CryptoManagerSync.java
index db327aa..728718d 100644
--- a/opends/src/server/org/opends/server/crypto/CryptoManagerSync.java
+++ b/opends/src/server/org/opends/server/crypto/CryptoManagerSync.java
@@ -125,7 +125,7 @@
     try {
       CryptoManager.publishInstanceKeyEntryInADS();
     }
-    catch (CryptoManager.CryptoManagerException ex) {
+    catch (CryptoManagerException ex) {
       throw new InitializationException(ex.getMessageObject());
     }
     DirectoryServer.registerBackendInitializationListener(this);
@@ -270,7 +270,7 @@
           DirectoryServer.getCryptoManager().importMacKeyEntry(searchEntry);
         }
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         throw new DirectoryException(
              DirectoryServer.getServerErrorResultCode(), e);
@@ -483,7 +483,7 @@
           DirectoryServer.getCryptoManager().importMacKeyEntry(entry);
         }
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         Message message = Message.raw("Failed to import key entry: %s",
                                       e.getMessage());
@@ -556,7 +556,7 @@
           DirectoryServer.getCryptoManager().importMacKeyEntry(newEntry);
         }
       }
-      catch (CryptoManager.CryptoManagerException e)
+      catch (CryptoManagerException e)
       {
         Message message = Message.raw("Failed to import modified key entry: %s",
                                       e.getMessage());
diff --git a/opends/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java b/opends/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java
index 7848f96..412be12 100644
--- a/opends/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java
+++ b/opends/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java
@@ -229,7 +229,7 @@
       operation.setResponseValue(new ASN1OctetString(responseSymmetricKey));
       operation.setResultCode(ResultCode.SUCCESS);
     }
-    catch (CryptoManager.CryptoManagerException e)
+    catch (CryptoManagerException e)
     {
       operation.setResultCode(DirectoryServer.getServerErrorResultCode());
       operation.appendErrorMessage(e.getMessageObject());
diff --git a/opends/src/server/org/opends/server/types/CryptoManagerException.java b/opends/src/server/org/opends/server/types/CryptoManagerException.java
new file mode 100644
index 0000000..8867067
--- /dev/null
+++ b/opends/src/server/org/opends/server/types/CryptoManagerException.java
@@ -0,0 +1,65 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+
+package org.opends.server.types;
+
+import org.opends.messages.Message;
+
+/**
+ * This class defines an exception that is thrown in the case of
+ * problems with encryption key managagment, and is a wrapper for a
+ * variety of other cipher related exceptions.
+ */
+public class CryptoManagerException extends OpenDsException {
+  /**
+   * The serial version identifier required to satisfy the compiler
+   * because this class extends <CODE>java.lang.Exception</CODE>,
+   * which implements the <CODE>java.io.Serializable</CODE>
+   * interface. This value was generated using the
+   * <CODE>serialver</CODE> command-line utility included with the
+   * Java SDK.
+   */
+  static final long serialVersionUID = -5890763923778143774L;
+
+  /**
+   * Creates an exception with the given message.
+   * @param message the message message.
+   */
+  public CryptoManagerException(Message message) {
+    super(message);
+   }
+
+  /**
+   * Creates an exception with the given message and underlying
+   * cause.
+   * @param message The message message.
+   * @param cause  The underlying cause.
+   */
+  public CryptoManagerException(Message message, Exception cause) {
+    super(message, cause);
+  }
+}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/crypto/CryptoManagerTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/crypto/CryptoManagerTestCase.java
index 899cfc2..6f6652e 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/crypto/CryptoManagerTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/crypto/CryptoManagerTestCase.java
@@ -447,7 +447,7 @@
     try {
       cm.decrypt(cipherText);
     }
-    catch (CryptoManager.CryptoManagerException ex) {
+    catch (CryptoManagerException ex) {
       // TODO: if reasons are added to CryptoManagerException, check for
       // expected cause.
     }

--
Gitblit v1.10.0