Blame SOURCES/pki-core-HSM-key-changeover-SCP03-support.patch

632623
From af96c3fc7cb41cbe6c14722418e132f5eadd93e1 Mon Sep 17 00:00:00 2001
632623
From: Jack Magne <jmagne@dhcp-16-206.sjc.redhat.com>
632623
Date: Thu, 29 Jun 2017 14:23:47 -0700
632623
Subject: [PATCH] SCP03 support: fix Key Changeover with HSM (RHCS)
632623
632623
Ticket #2764.
632623
632623
This relatively simple fix involves making sure the correct crypto token is being used to search for the master key int the case of symmetric key changover where the master key resides on an HSM.
632623
632623
(cherry picked from commit 7eb8ac9abb06d5a21c9d81d3f7fd08391a2a745e)
632623
---
632623
 .../cms/servlet/tks/SecureChannelProtocol.java     | 29 ++++++++++++++--------
632623
 1 file changed, 18 insertions(+), 11 deletions(-)
632623
632623
diff --git a/base/server/cms/src/com/netscape/cms/servlet/tks/SecureChannelProtocol.java b/base/server/cms/src/com/netscape/cms/servlet/tks/SecureChannelProtocol.java
632623
index 0542470..c3b3952 100644
632623
--- a/base/server/cms/src/com/netscape/cms/servlet/tks/SecureChannelProtocol.java
632623
+++ b/base/server/cms/src/com/netscape/cms/servlet/tks/SecureChannelProtocol.java
632623
@@ -25,12 +25,12 @@ import org.mozilla.jss.crypto.SymmetricKey.NotExtractableException;
632623
 import org.mozilla.jss.crypto.SymmetricKeyDeriver;
632623
 import org.mozilla.jss.crypto.TokenException;
632623
 
632623
+import sun.security.pkcs11.wrapper.PKCS11Constants;
632623
+
632623
 import com.netscape.certsrv.apps.CMS;
632623
 import com.netscape.certsrv.base.EBaseException;
632623
 import com.netscape.cmsutil.crypto.CryptoUtil;
632623
 
632623
-import sun.security.pkcs11.wrapper.PKCS11Constants;
632623
-
632623
 public class SecureChannelProtocol {
632623
 
632623
     static String sharedSecretKeyName = null;
632623
@@ -1874,13 +1874,13 @@ public class SecureChannelProtocol {
632623
                 kekKey = returnDeveloperSymKey(newToken, SecureChannelProtocol.kekType, keySet, null,"DES3");
632623
             } else if (protocol == PROTOCOL_THREE) {
632623
                 CMS.debug(method + " Special case or returning to the dev key set (or ver 1) for DiversifyKey, protocol 3!");
632623
-                encKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, newKeyInfo,
632623
+                encKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, newKeyInfo,
632623
                         SecureChannelProtocol.encType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
-                macKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, newKeyInfo,
632623
+                macKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, newKeyInfo,
632623
                         SecureChannelProtocol.macType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
-                kekKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, newKeyInfo,
632623
+                kekKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, newKeyInfo,
632623
                         SecureChannelProtocol.kekType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
             }
632623
@@ -1916,13 +1916,14 @@ public class SecureChannelProtocol {
632623
             } else { // protocol 3
632623
 
632623
                 CMS.debug(method + " Generating new card keys to upgrade to, protocol 3.");
632623
-                encKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, oldKeyInfo,
632623
+                CMS.debug("tokenName: " + tokenName + " newTokenName: " + newTokenName);
632623
+                encKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, oldKeyInfo,
632623
                         SecureChannelProtocol.encType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
-                macKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, oldKeyInfo,
632623
+                macKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, oldKeyInfo,
632623
                         SecureChannelProtocol.macType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
-                kekKey = this.computeSessionKey_SCP03(tokenName, newMasterKeyName, oldKeyInfo,
632623
+                kekKey = this.computeSessionKey_SCP03(newTokenName, newMasterKeyName, oldKeyInfo,
632623
                         SecureChannelProtocol.kekType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
 
632623
@@ -1931,6 +1932,7 @@ public class SecureChannelProtocol {
632623
                 old_kek_sym_key = this.computeSessionKey_SCP03(tokenName, oldMasterKeyName, oldKeyInfo,
632623
                         SecureChannelProtocol.kekType, kekKeyArray,
632623
                         keySet, CUIDValue, KDD, null, null, transportKeyName, params);
632623
+
632623
             }
632623
 
632623
             if (encKey == null || macKey == null || kekKey == null) {
632623
@@ -2076,9 +2078,14 @@ public class SecureChannelProtocol {
632623
             encrypted_mac_key = this.wrapSessionKey(tokenName, macKey, wrappingKey);
632623
             encrypted_kek_key = this.wrapSessionKey(tokenName, kekKey, wrappingKey);
632623
 
632623
-            keycheck_enc_key = this.computeKeyCheck_SCP03(encKey, tokenName);
632623
-            keycheck_mac_key = this.computeKeyCheck_SCP03(macKey, tokenName);
632623
-            keycheck_kek_key = this.computeKeyCheck_SCP03(kekKey, tokenName);
632623
+            try {
632623
+                keycheck_enc_key = this.computeKeyCheck_SCP03(encKey, encKey.getOwningToken().getName());
632623
+                keycheck_mac_key = this.computeKeyCheck_SCP03(macKey, macKey.getOwningToken().getName());
632623
+                keycheck_kek_key = this.computeKeyCheck_SCP03(kekKey, kekKey.getOwningToken().getName());
632623
+            } catch (TokenException e) {
632623
+                throw new EBaseException(method + e);
632623
+            }
632623
+
632623
 
632623
         } else {
632623
             throw new EBaseException(method + " Invalid SCP version requested!");
632623
-- 
632623
1.8.3.1
632623