>From ab057e11a61773e230663d382ca8b89d6035871c Mon Sep 17 00:00:00 2001
From: Christina Fu <cfu@redhat.com>
Date: Mon, 26 Oct 2015 18:35:34 +0100
Subject: [PATCH] Ticket #1527 TPS connector always goes to "ca1"

---
 .../server/tps/processor/TPSEnrollProcessor.java   | 22 ++-------------
 .../server/tps/processor/TPSProcessor.java         | 31 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java b/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
index 3045b5844523acdec8e8214280c5063ce7e9c891..2376ea76caa5f086ed349849bfae6adafa9d819e 100644
--- a/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
+++ b/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
@@ -1197,7 +1197,7 @@ public class TPSEnrollProcessor extends TPSProcessor {
                         //Renew and fetch the renewed cert blob.
 
                         CARenewCertResponse certResponse = tps.getEngine().renewCertificate(cert,
-                                cert.getSerialNumber(), selectedTokenType, keyType, getCAConnectorID());
+                                cert.getSerialNumber(), selectedTokenType, keyType, getCAConnectorID("renewal", keyType));
                         cEnrollInfo.setRenewedCertData(certResponse);
 
                         generateCertificate(certsInfo, channel, aInfo, keyType, TPSEngine.ENROLL_MODES.MODE_RENEWAL,
@@ -2004,7 +2004,7 @@ public class TPSEnrollProcessor extends TPSProcessor {
         try {
 
             if (isRecovery == false && isRenewal == false) {
-                String caConnID = getCAConnectorID();
+                String caConnID = getCAConnectorID("keyGen", cEnrollInfo.getKeyType());
                 CARemoteRequestHandler caRH = new CARemoteRequestHandler(caConnID);
                 TPSBuffer encodedParsedPubKey = new TPSBuffer(parsedPubKey_ba);
 
@@ -3067,24 +3067,6 @@ public class TPSEnrollProcessor extends TPSProcessor {
         return keyTypeNum;
     }
 
-    protected String getCAConnectorID() throws TPSException {
-        IConfigStore configStore = CMS.getConfigStore();
-        String id = null;
-
-        String config = "op." + currentTokenOperation + "." + selectedTokenType + ".ca.conn";
-
-        try {
-            id = configStore.getString(config, "ca1");
-        } catch (EBaseException e) {
-            throw new TPSException("TPSEnrollProcessor.getCAConnectorID: Internal error finding config value.");
-
-        }
-
-        CMS.debug("TPSEnrollProcessor.getCAConectorID: returning: " + id);
-
-        return id;
-    }
-
     private TPSBuffer makeKeyIDFromPublicKeyInfo(byte[] publicKeyInfo) throws TPSException {
 
         final String alg = "SHA1";
diff --git a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
index 4a4f05c50af803c469f952486a4c265d36dde230..a9355b9bf58037650d3e1fbc28bbfe8fc74115f0 100644
--- a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
+++ b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
@@ -1344,19 +1344,42 @@ public class TPSProcessor {
     }
 
     protected String getCAConnectorID() throws TPSException {
+        return getCAConnectorID(null, null);
+    }
+
+    /*
+     * @param enrollType "keyGen" or "renewal"
+     * @param keyType e.g. "authentication", "auth", "encryption", or "signing"
+     */
+    protected String getCAConnectorID(String enrollType, String keyType)
+            throws TPSException {
         IConfigStore configStore = CMS.getConfigStore();
         String id = null;
+        String config = null;
+        String method = "TPSProcessor.getCAConnectorID:";
 
-        String config = "op." + currentTokenOperation + "." + selectedTokenType + ".ca.conn";
+        if ((keyType != null) && (enrollType != null)) {
+            config = "op." + currentTokenOperation + "." +
+                selectedTokenType + "." +
+                enrollType + "." +
+                keyType+
+                ".ca.conn";
+            CMS.debug(method + " finding config: " + config);
+        } else {
+            config = "op." + currentTokenOperation + "." +
+                selectedTokenType +
+                ".ca.conn";
+            CMS.debug(method + " finding config: " + config);
+        }
 
         try {
-            id = configStore.getString(config, "ca1");
+            id = configStore.getString(config);
         } catch (EBaseException e) {
-            throw new TPSException("TPSProcessor.getCAConnectorID: Internal error finding config value.");
+            throw new TPSException(method + " Internal error finding config value:" + config);
 
         }
 
-        CMS.debug("TPSProcessor.getCAConectorID: returning: " + id);
+        CMS.debug(method + " returning: " + id);
 
         return id;
     }
-- 
1.8.4.2

