Blame SOURCES/pki-core-10.5.1-snapshot-5.patch

2413b1
From b56da71239b10f42a7c0c017eda2f0d63d43031d Mon Sep 17 00:00:00 2001
2413b1
From: "Endi S. Dewata" <edewata@redhat.com>
2413b1
Date: Fri, 9 Feb 2018 01:53:37 +0100
2413b1
Subject: [PATCH 1/7] Disabled failing unit tests.
2413b1
2413b1
Some unit tests have been disabled since they are currently
2413b1
failing. This allows other tests to be enabled later. These
2413b1
failures need to be investigated further.
2413b1
2413b1
https://pagure.io/dogtagpki/issue/2908
2413b1
2413b1
Change-Id: If5aa31c10f89fb8388085b59377347338ae729a1
2413b1
(cherry picked from commit 17fcac5f807cbbf1ee6709a6613d9baa80f1115d)
2413b1
(cherry picked from commit 431ad0ec9f6f8188c1d240ed60966d53a4c6982b)
2413b1
---
2413b1
 base/server/test/CMakeLists.txt | 4 ++--
2413b1
 1 file changed, 2 insertions(+), 2 deletions(-)
2413b1
2413b1
diff --git a/base/server/test/CMakeLists.txt b/base/server/test/CMakeLists.txt
2413b1
index 6534a6c..707493f 100644
2413b1
--- a/base/server/test/CMakeLists.txt
2413b1
+++ b/base/server/test/CMakeLists.txt
2413b1
@@ -61,7 +61,7 @@ add_junit_test(test-pki-server
2413b1
         ${HAMCREST_JAR} ${JUNIT_JAR}
2413b1
         ${CMAKE_BINARY_DIR}/test/classes
2413b1
     TESTS
2413b1
-        com.netscape.cmscore.authentication.AuthTokenTest
2413b1
+        # com.netscape.cmscore.authentication.AuthTokenTest
2413b1
         com.netscape.cmscore.dbs.CertRecordListTest
2413b1
         com.netscape.cmscore.dbs.DBRegistryTest
2413b1
         # com.netscape.cmscore.request.AgentApprovalsTest
2413b1
@@ -69,7 +69,7 @@ add_junit_test(test-pki-server
2413b1
         com.netscape.cmscore.request.ExtDataHashtableTest
2413b1
         com.netscape.cmscore.request.RequestQueueTest
2413b1
         com.netscape.cmscore.request.RequestRecordTest
2413b1
-        com.netscape.cmscore.request.RequestTest
2413b1
+        # com.netscape.cmscore.request.RequestTest
2413b1
     REPORTS_DIR
2413b1
         reports
2413b1
 )
2413b1
-- 
2413b1
1.8.3.1
2413b1
2413b1
2413b1
From 38c6e86e434caf80635b88c2265bb5b6d036bef7 Mon Sep 17 00:00:00 2001
2413b1
From: "Endi S. Dewata" <edewata@redhat.com>
2413b1
Date: Sat, 10 Feb 2018 05:16:41 +0100
2413b1
Subject: [PATCH 4/7] Added Key ID encoder and decoder.
2413b1
2413b1
The following methods have been added to encode and decode NSS key
2413b1
ID properly:
2413b1
 - CryptoUtil.encodeKeyID()
2413b1
 - CryptoUtil.decodeKeyID()
2413b1
2413b1
A unit test has been added to verify the functionality.
2413b1
2413b1
https://pagure.io/dogtagpki/issue/2884
2413b1
2413b1
Change-Id: Ib295bc1cb449f544cd0220bfaea1ed0d71136365
2413b1
(cherry picked from commit c46f53ff6f2fb398600c59410b2afe14fed9dbfa)
2413b1
---
2413b1
 .../com/netscape/cmsutil/crypto/CryptoUtil.java    |  63 +++++-
2413b1
 base/util/test/CMakeLists.txt                      |   2 +
2413b1
 .../netscape/cmsutil/crypto/KeyIDCodecTest.java    | 239 +++++++++++++++++++++
2413b1
 3 files changed, 303 insertions(+), 1 deletion(-)
2413b1
 create mode 100644 base/util/test/com/netscape/cmsutil/crypto/KeyIDCodecTest.java
2413b1
2413b1
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2413b1
index 27ae0de..0742f8e 100644
2413b1
--- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2413b1
+++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2413b1
@@ -54,6 +54,7 @@ import java.util.Map;
2413b1
 import java.util.StringTokenizer;
2413b1
 import java.util.Vector;
2413b1
 
2413b1
+import org.apache.commons.codec.binary.Hex;
2413b1
 import org.apache.commons.lang.ArrayUtils;
2413b1
 import org.apache.commons.lang.StringUtils;
2413b1
 import org.mozilla.jss.CryptoManager;
2413b1
@@ -179,6 +180,8 @@ public class CryptoUtil {
2413b1
         }
2413b1
     }
2413b1
 
2413b1
+    public final static int KEY_ID_LENGTH = 20;
2413b1
+
2413b1
     public final static String INTERNAL_TOKEN_NAME = "internal";
2413b1
     public final static String INTERNAL_TOKEN_FULL_NAME = "Internal Key Storage Token";
2413b1
 
2413b1
@@ -2046,12 +2049,70 @@ public class CryptoUtil {
2413b1
         return false;
2413b1
     }
2413b1
 
2413b1
+    /**
2413b1
+     * Converts any length byte array into a signed, variable-length
2413b1
+     * hexadecimal number.
2413b1
+     */
2413b1
     public static String byte2string(byte id[]) {
2413b1
         return new BigInteger(id).toString(16);
2413b1
     }
2413b1
 
2413b1
+    /**
2413b1
+     * Converts a signed, variable-length hexadecimal number into a byte
2413b1
+     * array, which may not be identical to the original byte array.
2413b1
+     */
2413b1
     public static byte[] string2byte(String id) {
2413b1
-        return (new BigInteger(id, 16)).toByteArray();
2413b1
+        return new BigInteger(id, 16).toByteArray();
2413b1
+    }
2413b1
+
2413b1
+    /**
2413b1
+     * Converts NSS key ID from a 20 byte array into a signed, variable-length
2413b1
+     * hexadecimal number (to maintain compatibility with byte2string()).
2413b1
+     */
2413b1
+    public static String encodeKeyID(byte[] keyID) {
2413b1
+
2413b1
+        if (keyID.length != KEY_ID_LENGTH) {
2413b1
+            throw new IllegalArgumentException(
2413b1
+                    "Unable to encode Key ID: " + Hex.encodeHexString(keyID));
2413b1
+        }
2413b1
+
2413b1
+        return new BigInteger(keyID).toString(16);
2413b1
+    }
2413b1
+
2413b1
+    /**
2413b1
+     * Converts NSS key ID from a signed, variable-length hexadecimal number
2413b1
+     * into a 20 byte array, which will be identical to the original byte array.
2413b1
+     */
2413b1
+    public static byte[] decodeKeyID(String id) {
2413b1
+
2413b1
+        BigInteger value = new BigInteger(id, 16);
2413b1
+        byte[] array = value.toByteArray();
2413b1
+
2413b1
+        if (array.length > KEY_ID_LENGTH) {
2413b1
+            throw new IllegalArgumentException(
2413b1
+                    "Unable to decode Key ID: " + id);
2413b1
+        }
2413b1
+
2413b1
+        if (array.length < KEY_ID_LENGTH) {
2413b1
+
2413b1
+            // extend the array with most significant bit
2413b1
+            byte[] tmp = array;
2413b1
+            array = new byte[KEY_ID_LENGTH];
2413b1
+
2413b1
+            // calculate the extension
2413b1
+            int p = KEY_ID_LENGTH - tmp.length;
2413b1
+
2413b1
+            // create filler byte based op the most significant bit
2413b1
+            byte b = (byte)(value.signum() >= 0 ? 0x00 : 0xff);
2413b1
+
2413b1
+            // fill the extension with the filler byte
2413b1
+            Arrays.fill(array, 0, p, b);
2413b1
+
2413b1
+            // copy the original array
2413b1
+            System.arraycopy(tmp, 0, array, p, tmp.length);
2413b1
+        }
2413b1
+
2413b1
+        return array;
2413b1
     }
2413b1
 
2413b1
     /**
2413b1
diff --git a/base/util/test/CMakeLists.txt b/base/util/test/CMakeLists.txt
2413b1
index eabda2f..cc5c07a 100644
2413b1
--- a/base/util/test/CMakeLists.txt
2413b1
+++ b/base/util/test/CMakeLists.txt
2413b1
@@ -20,11 +20,13 @@ javac(pki-util-test-classes
2413b1
 # TODO: create CMake function to find all JUnit test classes
2413b1
 add_junit_test(test-pki-util
2413b1
     CLASSPATH
2413b1
+        ${SLF4J_API_JAR} ${SLF4J_JDK14_JAR}
2413b1
         ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
2413b1
         ${JSS_JAR} ${LDAPJDK_JAR} ${COMMONS_CODEC_JAR}
2413b1
         ${HAMCREST_JAR} ${JUNIT_JAR}
2413b1
         ${CMAKE_BINARY_DIR}/test/classes
2413b1
     TESTS
2413b1
+        com.netscape.cmsutil.crypto.KeyIDCodecTest
2413b1
         com.netscape.security.util.BMPStringTest
2413b1
         com.netscape.security.util.IA5StringTest
2413b1
         com.netscape.security.util.PrintableStringTest
2413b1
diff --git a/base/util/test/com/netscape/cmsutil/crypto/KeyIDCodecTest.java b/base/util/test/com/netscape/cmsutil/crypto/KeyIDCodecTest.java
2413b1
new file mode 100644
2413b1
index 0000000..e25a431
2413b1
--- /dev/null
2413b1
+++ b/base/util/test/com/netscape/cmsutil/crypto/KeyIDCodecTest.java
2413b1
@@ -0,0 +1,239 @@
2413b1
+// --- BEGIN COPYRIGHT BLOCK ---
2413b1
+// This program is free software; you can redistribute it and/or modify
2413b1
+// it under the terms of the GNU General Public License as published by
2413b1
+// the Free Software Foundation; version 2 of the License.
2413b1
+//
2413b1
+// This program is distributed in the hope that it will be useful,
2413b1
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
2413b1
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2413b1
+// GNU General Public License for more details.
2413b1
+//
2413b1
+// You should have received a copy of the GNU General Public License along
2413b1
+// with this program; if not, write to the Free Software Foundation, Inc.,
2413b1
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2413b1
+//
2413b1
+// (C) 2018 Red Hat, Inc.
2413b1
+// All rights reserved.
2413b1
+// --- END COPYRIGHT BLOCK ---
2413b1
+package com.netscape.cmsutil.crypto;
2413b1
+
2413b1
+import org.junit.Assert;
2413b1
+import org.junit.Test;
2413b1
+
2413b1
+/**
2413b1
+ * Key ID encoder and decoder validation.
2413b1
+ *
2413b1
+ * Key ID in NSS database is a 20 byte array. The key ID is
2413b1
+ * stored in CS.cfg as a signed, variable-length, hexadecimal
2413b1
+ * number.
2413b1
+ *
2413b1
+ * This test verifies that Key ID can be encoded and
2413b1
+ * decoded correctly using the following methods:
2413b1
+ *  - CryptoUtil.encodeKeyID()
2413b1
+ *  - CryptoUtil.decodeKeyID()
2413b1
+ *
2413b1
+ * The test is performed against a set of valid data that
2413b1
+ * covers the entire range of 20 byte array, and some invalid
2413b1
+ * data as well.
2413b1
+ */
2413b1
+public class KeyIDCodecTest {
2413b1
+
2413b1
+    // data #1: zero
2413b1
+    String DATA1_HEX = "0";
2413b1
+
2413b1
+    // 0000000000000000000000000000000000000000
2413b1
+    byte[] DATA1_BYTES = new byte[] {
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
2413b1
+    };
2413b1
+
2413b1
+    // data #2: small positive number (with leading 0x00)
2413b1
+    String DATA2_HEX = "18604db6c7a073ff08338650";
2413b1
+
2413b1
+    // 000000000000000018604db6c7a073ff08338650
2413b1
+    byte[] DATA2_BYTES = new byte[] {
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x18, (byte)0x60, (byte)0x4d, (byte)0xb6,
2413b1
+            (byte)0xc7, (byte)0xa0, (byte)0x73, (byte)0xff,
2413b1
+            (byte)0x08, (byte)0x33, (byte)0x86, (byte)0x50
2413b1
+    };
2413b1
+
2413b1
+    // data #3: large positive number
2413b1
+    String DATA3_HEX = "446ed35d7e811e7f73d0d1f220afc60083deba74";
2413b1
+
2413b1
+    // 446ed35d7e811e7f73d0d1f220afc60083deba74
2413b1
+    byte[] DATA3_BYTES = new byte[] {
2413b1
+            (byte)0x44, (byte)0x6e, (byte)0xd3, (byte)0x5d,
2413b1
+            (byte)0x7e, (byte)0x81, (byte)0x1e, (byte)0x7f,
2413b1
+            (byte)0x73, (byte)0xd0, (byte)0xd1, (byte)0xf2,
2413b1
+            (byte)0x20, (byte)0xaf, (byte)0xc6, (byte)0x00,
2413b1
+            (byte)0x83, (byte)0xde, (byte)0xba, (byte)0x74
2413b1
+    };
2413b1
+
2413b1
+    // data #4: highest 20-byte number
2413b1
+    String DATA4_HEX = "7fffffffffffffffffffffffffffffffffffffff";
2413b1
+
2413b1
+    // 7fffffffffffffffffffffffffffffffffffffff
2413b1
+    byte[] DATA4_BYTES = new byte[] {
2413b1
+            (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff
2413b1
+    };
2413b1
+
2413b1
+    // data #5: negative one
2413b1
+    String DATA5_HEX = "-1";
2413b1
+
2413b1
+    // ffffffffffffffffffffffffffffffffffffffff
2413b1
+    byte[] DATA5_BYTES = new byte[] {
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff
2413b1
+    };
2413b1
+
2413b1
+    // data 6: small negative number (with leading 0xff)
2413b1
+    String DATA6_HEX = "-314bd3fd90753fe3687d358d";
2413b1
+
2413b1
+    // ffffffffffffffffffffceb42c026f8ac01c9782ca73
2413b1
+    byte[] DATA6_BYTES = new byte[] {
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
2413b1
+            (byte)0xce, (byte)0xb4, (byte)0x2c, (byte)0x02,
2413b1
+            (byte)0x6f, (byte)0x8a, (byte)0xc0, (byte)0x1c,
2413b1
+            (byte)0x97, (byte)0x82, (byte)0xca, (byte)0x73
2413b1
+    };
2413b1
+
2413b1
+    // data #7: large negative number
2413b1
+    String DATA7_HEX = "-16e096b561838ac32855acc30a09e6a2d9adc120";
2413b1
+
2413b1
+    // e91f694a9e7c753cd7aa533cf5f6195d26523ee0
2413b1
+    byte[] DATA7_BYTES = new byte[] {
2413b1
+            (byte)0xe9, (byte)0x1f, (byte)0x69, (byte)0x4a,
2413b1
+            (byte)0x9e, (byte)0x7c, (byte)0x75, (byte)0x3c,
2413b1
+            (byte)0xd7, (byte)0xaa, (byte)0x53, (byte)0x3c,
2413b1
+            (byte)0xf5, (byte)0xf6, (byte)0x19, (byte)0x5d,
2413b1
+            (byte)0x26, (byte)0x52, (byte)0x3e, (byte)0xe0
2413b1
+    };
2413b1
+
2413b1
+    // data #8: lowest 20-byte number
2413b1
+    String DATA8_HEX = "-8000000000000000000000000000000000000000";
2413b1
+
2413b1
+    // 8000000000000000000000000000000000000000
2413b1
+    byte[] DATA8_BYTES = new byte[] {
2413b1
+            (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
2413b1
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
2413b1
+    };
2413b1
+
2413b1
+    Object[][] TEST_DATA = {
2413b1
+            new Object[] { DATA1_BYTES, DATA1_HEX },
2413b1
+            new Object[] { DATA2_BYTES, DATA2_HEX },
2413b1
+            new Object[] { DATA3_BYTES, DATA3_HEX },
2413b1
+            new Object[] { DATA4_BYTES, DATA4_HEX },
2413b1
+            new Object[] { DATA5_BYTES, DATA5_HEX },
2413b1
+            new Object[] { DATA6_BYTES, DATA6_HEX },
2413b1
+            new Object[] { DATA7_BYTES, DATA7_HEX },
2413b1
+            new Object[] { DATA8_BYTES, DATA8_HEX }
2413b1
+    };
2413b1
+
2413b1
+    @Test
2413b1
+    public void testEncoder() throws Exception {
2413b1
+
2413b1
+        System.out.println("Testing Key ID encoder with valid data:");
2413b1
+
2413b1
+        for (int i = 0; i < TEST_DATA.length; i++) {
2413b1
+            System.out.println(" - data #" + (i + 1));
2413b1
+
2413b1
+            byte[] bytes = (byte[])TEST_DATA[i][0];
2413b1
+            String hex = (String)TEST_DATA[i][1];
2413b1
+
2413b1
+            String result = CryptoUtil.encodeKeyID(bytes);
2413b1
+            Assert.assertEquals(hex, result);
2413b1
+        }
2413b1
+
2413b1
+        System.out.println("Testing Key ID encoder with invalid data:");
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - null data");
2413b1
+            CryptoUtil.encodeKeyID(null);
2413b1
+            Assert.fail("should throw NullPointerException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof NullPointerException);
2413b1
+        }
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - empty data");
2413b1
+            CryptoUtil.encodeKeyID(new byte[] {});
2413b1
+            Assert.fail("should throw IllegalArgumentException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof IllegalArgumentException);
2413b1
+        }
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - incorrect length data");
2413b1
+            CryptoUtil.encodeKeyID(new byte[] { (byte)0x24, (byte)0xac });
2413b1
+            Assert.fail("should throw IllegalArgumentException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof IllegalArgumentException);
2413b1
+        }
2413b1
+    }
2413b1
+
2413b1
+    @Test
2413b1
+    public void testDecoder() throws Exception {
2413b1
+
2413b1
+        System.out.println("Testing Key ID decoder with valid data:");
2413b1
+
2413b1
+        for (int i = 0; i < TEST_DATA.length; i++) {
2413b1
+            System.out.println(" - data #" + (i + 1));
2413b1
+
2413b1
+            byte[] bytes = (byte[])TEST_DATA[i][0];
2413b1
+            String hex = (String)TEST_DATA[i][1];
2413b1
+
2413b1
+            byte[] result = CryptoUtil.decodeKeyID(hex);
2413b1
+            Assert.assertArrayEquals(bytes, result);
2413b1
+        }
2413b1
+
2413b1
+        System.out.println("Testing Key ID decoder with invalid data:");
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - null data");
2413b1
+            CryptoUtil.decodeKeyID(null);
2413b1
+            Assert.fail("should throw NullPointerException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof NullPointerException);
2413b1
+        }
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - empty data");
2413b1
+            CryptoUtil.decodeKeyID("");
2413b1
+            Assert.fail("should throw IllegalArgumentException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof IllegalArgumentException);
2413b1
+        }
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - incorrect length data");
2413b1
+            CryptoUtil.decodeKeyID("ffffffffffffffffffffffffffffffffffffffffff");
2413b1
+            Assert.fail("should throw IllegalArgumentException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof IllegalArgumentException);
2413b1
+        }
2413b1
+
2413b1
+        try {
2413b1
+            System.out.println(" - garbage data");
2413b1
+            CryptoUtil.decodeKeyID("garbage");
2413b1
+            Assert.fail("should throw NumberFormatException");
2413b1
+        } catch (Exception e) {
2413b1
+            Assert.assertTrue(e instanceof NumberFormatException);
2413b1
+        }
2413b1
+    }
2413b1
+}
2413b1
-- 
2413b1
1.8.3.1
2413b1
2413b1
2413b1
From 13b98e81cfc2c92fe435f0d3b0fa4017cb44c608 Mon Sep 17 00:00:00 2001
2413b1
From: "Endi S. Dewata" <edewata@redhat.com>
2413b1
Date: Mon, 12 Feb 2018 18:20:57 +0100
2413b1
Subject: [PATCH 5/7] Fixed Key ID encoding and decoding.
2413b1
2413b1
The code that encodes and decodes NSS key ID has been changed to
2413b1
use CryptoUtil.encodeKeyID() and decodeKeyID(), respectively.
2413b1
2413b1
https://pagure.io/dogtagpki/issue/2884
2413b1
2413b1
Change-Id: Ic97a9f8ea1ad7819c8f6ff0faf732ee04a2174e8
2413b1
(cherry picked from commit 275b706f0e38288db6c4c900b7116c9816ba82a7)
2413b1
(cherry picked from commit d9969e2c2c5895056d4ecdb04718d5a4473c297d)
2413b1
---
2413b1
 base/ca/src/com/netscape/ca/SigningUnit.java                 |  2 +-
2413b1
 base/java-tools/src/com/netscape/cmstools/CMCRequest.java    |  2 +-
2413b1
 base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java |  2 +-
2413b1
 base/java-tools/src/com/netscape/cmstools/PKCS10Client.java  |  2 +-
2413b1
 base/ocsp/src/com/netscape/ocsp/SigningUnit.java             |  2 +-
2413b1
 .../cms/src/com/netscape/cms/servlet/csadmin/CertUtil.java   |  6 +++---
2413b1
 .../com/netscape/cms/servlet/csadmin/ConfigurationUtils.java | 12 ++++++------
2413b1
 .../src/org/dogtagpki/server/rest/SystemConfigService.java   |  2 +-
2413b1
 8 files changed, 15 insertions(+), 15 deletions(-)
2413b1
2413b1
diff --git a/base/ca/src/com/netscape/ca/SigningUnit.java b/base/ca/src/com/netscape/ca/SigningUnit.java
2413b1
index 7cd0dd4..ecd2a81 100644
2413b1
--- a/base/ca/src/com/netscape/ca/SigningUnit.java
2413b1
+++ b/base/ca/src/com/netscape/ca/SigningUnit.java
2413b1
@@ -190,7 +190,7 @@ public final class SigningUnit implements ISigningUnit {
2413b1
                 throw new CAMissingKeyException(CMS.getUserMessage("CMS_CA_CERT_OBJECT_NOT_FOUND"), e);
2413b1
             }
2413b1
 
2413b1
-            String privateKeyID = CryptoUtil.byte2string(mPrivk.getUniqueID());
2413b1
+            String privateKeyID = CryptoUtil.encodeKeyID(mPrivk.getUniqueID());
2413b1
             CMS.debug("SigningUnit: private key ID: " + privateKeyID);
2413b1
 
2413b1
             mPubk = mCert.getPublicKey();
2413b1
diff --git a/base/java-tools/src/com/netscape/cmstools/CMCRequest.java b/base/java-tools/src/com/netscape/cmstools/CMCRequest.java
2413b1
index 8146cee..4e40143 100644
2413b1
--- a/base/java-tools/src/com/netscape/cmstools/CMCRequest.java
2413b1
+++ b/base/java-tools/src/com/netscape/cmstools/CMCRequest.java
2413b1
@@ -2163,7 +2163,7 @@ public class CMCRequest {
2413b1
                 } else {
2413b1
                     System.out.println("got request privKeyId: " + privKeyId);
2413b1
 
2413b1
-                    byte[] keyIDb = CryptoUtil.string2byte(privKeyId);
2413b1
+                    byte[] keyIDb = CryptoUtil.decodeKeyID(privKeyId);
2413b1
 
2413b1
                     privk = CryptoUtil.findPrivateKeyFromID(keyIDb);
2413b1
 
2413b1
diff --git a/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java b/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java
2413b1
index eadf3a8..bc95983 100644
2413b1
--- a/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java
2413b1
+++ b/base/java-tools/src/com/netscape/cmstools/CRMFPopClient.java
2413b1
@@ -475,7 +475,7 @@ public class CRMFPopClient {
2413b1
             PrivateKey privateKey = (PrivateKey) keyPair.getPrivate();
2413b1
             @SuppressWarnings("deprecation")
2413b1
             byte id[] = privateKey.getUniqueID();
2413b1
-            String kid = CryptoUtil.byte2string(id);
2413b1
+            String kid = CryptoUtil.encodeKeyID(id);
2413b1
             System.out.println("Keypair private key id: " + kid);
2413b1
 
2413b1
             if (hostPort != null) {
2413b1
diff --git a/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java b/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java
2413b1
index d2278b8..9f39430 100644
2413b1
--- a/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java
2413b1
+++ b/base/java-tools/src/com/netscape/cmstools/PKCS10Client.java
2413b1
@@ -303,7 +303,7 @@ public class PKCS10Client {
2413b1
             PrivateKey privateKey = (PrivateKey) pair.getPrivate();
2413b1
             @SuppressWarnings("deprecation")
2413b1
             byte id[] = privateKey.getUniqueID();
2413b1
-            String kid = CryptoUtil.byte2string(id);
2413b1
+            String kid = CryptoUtil.encodeKeyID(id);
2413b1
             System.out.println("Keypair private key id: " + kid);
2413b1
             System.out.println("");
2413b1
 
2413b1
diff --git a/base/ocsp/src/com/netscape/ocsp/SigningUnit.java b/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
2413b1
index 686f1ed..4ed1625 100644
2413b1
--- a/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
2413b1
+++ b/base/ocsp/src/com/netscape/ocsp/SigningUnit.java
2413b1
@@ -159,7 +159,7 @@ public final class SigningUnit implements ISigningUnit {
2413b1
             CMS.debug("SigningUnit: Loading private key");
2413b1
             mPrivk = mManager.findPrivKeyByCert(mCert);
2413b1
 
2413b1
-            String privateKeyID = CryptoUtil.byte2string(mPrivk.getUniqueID());
2413b1
+            String privateKeyID = CryptoUtil.encodeKeyID(mPrivk.getUniqueID());
2413b1
             CMS.debug("SigningUnit: private key ID: " + privateKeyID);
2413b1
 
2413b1
             mPubk = mCert.getPublicKey();
2413b1
diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/CertUtil.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/CertUtil.java
2413b1
index da4f17f..12d4ac1 100644
2413b1
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/CertUtil.java
2413b1
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/CertUtil.java
2413b1
@@ -154,7 +154,7 @@ public class CertUtil {
2413b1
             }
2413b1
             // get private key
2413b1
             String privKeyID = config.getString(prefix + certTag + ".privkey.id");
2413b1
-            byte[] keyIDb = CryptoUtil.string2byte(privKeyID);
2413b1
+            byte[] keyIDb = CryptoUtil.decodeKeyID(privKeyID);
2413b1
 
2413b1
             PrivateKey privk = CryptoUtil.findPrivateKeyFromID(keyIDb);
2413b1
 
2413b1
@@ -546,7 +546,7 @@ public class CertUtil {
2413b1
         PrivateKey caPrik = (PrivateKey) pk;
2413b1
         */
2413b1
         String caPriKeyID = config.getString(prefix + "signing" + ".privkey.id");
2413b1
-        byte[] keyIDb = CryptoUtil.string2byte(caPriKeyID);
2413b1
+        byte[] keyIDb = CryptoUtil.decodeKeyID(caPriKeyID);
2413b1
         PrivateKey caPrik = CryptoUtil.findPrivateKeyFromID(keyIDb);
2413b1
 
2413b1
         if (caPrik == null) {
2413b1
@@ -761,7 +761,7 @@ public class CertUtil {
2413b1
         } else {
2413b1
             String str = "";
2413b1
             try {
2413b1
-                str = CryptoUtil.byte2string(privKey.getUniqueID());
2413b1
+                str = CryptoUtil.encodeKeyID(privKey.getUniqueID());
2413b1
             } catch (Exception e) {
2413b1
                 CMS.debug("CertUtil privateKeyExistsOnToken: encode string Exception: " + e.toString());
2413b1
             }
2413b1
diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
2413b1
index 1d37d73..0a5cd2e 100644
2413b1
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
2413b1
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
2413b1
@@ -2379,7 +2379,7 @@ public class ConfigurationUtils {
2413b1
 
2413b1
         PrivateKey privateKey = (PrivateKey) pair.getPrivate();
2413b1
         byte id[] = privateKey.getUniqueID();
2413b1
-        String kid = CryptoUtil.byte2string(id);
2413b1
+        String kid = CryptoUtil.encodeKeyID(id);
2413b1
         config.putString(PCERT_PREFIX + tag + ".privkey.id", kid);
2413b1
 
2413b1
         String keyAlgo = config.getString(PCERT_PREFIX + tag + ".signingalgorithm");
2413b1
@@ -2439,10 +2439,10 @@ public class ConfigurationUtils {
2413b1
 
2413b1
             // XXX - store curve , w
2413b1
             byte id[] = ((org.mozilla.jss.crypto.PrivateKey) pair.getPrivate()).getUniqueID();
2413b1
-            String kid = CryptoUtil.byte2string(id);
2413b1
+            String kid = CryptoUtil.encodeKeyID(id);
2413b1
 
2413b1
             // try to locate the private key
2413b1
-            org.mozilla.jss.crypto.PrivateKey privk = CryptoUtil.findPrivateKeyFromID(CryptoUtil.string2byte(kid));
2413b1
+            org.mozilla.jss.crypto.PrivateKey privk = CryptoUtil.findPrivateKeyFromID(CryptoUtil.decodeKeyID(kid));
2413b1
             if (privk == null) {
2413b1
                 CMS.debug("Found bad ECC key id " + kid);
2413b1
                 pair = null;
2413b1
@@ -2461,11 +2461,11 @@ public class ConfigurationUtils {
2413b1
         do {
2413b1
             pair = CryptoUtil.generateRSAKeyPair(token, keysize);
2413b1
             byte id[] = ((org.mozilla.jss.crypto.PrivateKey) pair.getPrivate()).getUniqueID();
2413b1
-            String kid = CryptoUtil.byte2string(id);
2413b1
+            String kid = CryptoUtil.encodeKeyID(id);
2413b1
 
2413b1
             // try to locate the private key
2413b1
             org.mozilla.jss.crypto.PrivateKey privk =
2413b1
-                    CryptoUtil.findPrivateKeyFromID(CryptoUtil.string2byte(kid));
2413b1
+                    CryptoUtil.findPrivateKeyFromID(CryptoUtil.decodeKeyID(kid));
2413b1
 
2413b1
             if (privk == null) {
2413b1
                 CMS.debug("Found bad RSA key id " + kid);
2413b1
@@ -3009,7 +3009,7 @@ public class ConfigurationUtils {
2413b1
         String privKeyID = config.getString(PCERT_PREFIX + certTag + ".privkey.id");
2413b1
 
2413b1
         CMS.debug("generateCertRequest: private key ID: " + privKeyID);
2413b1
-        byte[] keyIDb = CryptoUtil.string2byte(privKeyID);
2413b1
+        byte[] keyIDb = CryptoUtil.decodeKeyID(privKeyID);
2413b1
 
2413b1
         PrivateKey privk = CryptoUtil.findPrivateKeyFromID(keyIDb);
2413b1
         if (privk == null) {
2413b1
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
2413b1
index 575f97c..5130a1a 100644
2413b1
--- a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
2413b1
+++ b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
2413b1
@@ -532,7 +532,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
2413b1
 
2413b1
         cs.putString("preop.cert." + tag + ".pubkey.modulus", CryptoUtil.byte2string(modulus));
2413b1
         cs.putString("preop.cert." + tag + ".pubkey.exponent", CryptoUtil.byte2string(exponent));
2413b1
-        cs.putString("preop.cert." + tag + ".privkey.id", CryptoUtil.byte2string(privk.getUniqueID()));
2413b1
+        cs.putString("preop.cert." + tag + ".privkey.id", CryptoUtil.encodeKeyID(privk.getUniqueID()));
2413b1
         cs.putString("preop.cert." + tag + ".keyalgorithm", cdata.getKeyAlgorithm());
2413b1
         cs.putString("preop.cert." + tag + ".keytype", cdata.getKeyType());
2413b1
     }
2413b1
-- 
2413b1
1.8.3.1
2413b1
2413b1
2413b1
From cb17add9f01bb418f567c156c8bcf01113700b83 Mon Sep 17 00:00:00 2001
2413b1
From: "Endi S. Dewata" <edewata@redhat.com>
2413b1
Date: Thu, 15 Feb 2018 20:06:26 +0100
2413b1
Subject: [PATCH 6/7] Fixed SERVER_SIDE_KEYGEN_REQUEST_PROCESSED filter in KRA.
2413b1
2413b1
The filter definition for SERVER_SIDE_KEYGEN_REQUEST_PROCESSED
2413b1
event in KRA's CS.cfg has been updated to fix a typo.
2413b1
2413b1
https://pagure.io/dogtagpki/issue/2656
2413b1
2413b1
Change-Id: I6f2e3d38597355e04b1899aeb324db43caefd4df
2413b1
(cherry picked from commit d7db5fa81f9cda0997779e0ce57a309263669f1f)
2413b1
(cherry picked from commit 6af503a10b95077780c15126e7af8336364854dc)
2413b1
---
2413b1
 base/kra/shared/conf/CS.cfg | 2 +-
2413b1
 1 file changed, 1 insertion(+), 1 deletion(-)
2413b1
2413b1
diff --git a/base/kra/shared/conf/CS.cfg b/base/kra/shared/conf/CS.cfg
2413b1
index 06bd0fe..f314234 100644
2413b1
--- a/base/kra/shared/conf/CS.cfg
2413b1
+++ b/base/kra/shared/conf/CS.cfg
2413b1
@@ -317,7 +317,7 @@ log.instance.SignedAudit.filters.SECURITY_DATA_RECOVERY_REQUEST_PROCESSED=(Outco
2413b1
 log.instance.SignedAudit.filters.SECURITY_DATA_RECOVERY_REQUEST_STATE_CHANGE=(Outcome=Failure)
2413b1
 log.instance.SignedAudit.filters.SELFTESTS_EXECUTION=(Outcome=Failure)
2413b1
 log.instance.SignedAudit.filters.SERVER_SIDE_KEYGEN_REQUEST=(Outcome=Failure)
2413b1
-log.instance.SignedAudit.filters.SERVER_SIDE_KEYGEN_REQUEST=PROCESSED (Outcome=Failure)
2413b1
+log.instance.SignedAudit.filters.SERVER_SIDE_KEYGEN_REQUEST_PROCESSED=(Outcome=Failure)
2413b1
 log.instance.SignedAudit.filters.SYMKEY_GENERATION_REQUEST=(Outcome=Failure)
2413b1
 log.instance.SignedAudit.filters.SYMKEY_GEN_REQUEST_PROCESSED=(Outcome=Failure)
2413b1
 log.instance.SignedAudit.expirationTime=0
2413b1
-- 
2413b1
1.8.3.1
2413b1
2413b1
2413b1
From eda0b35693530a8ad796ac9012f5bee7db6dd9ac Mon Sep 17 00:00:00 2001
2413b1
From: "Endi S. Dewata" <edewata@redhat.com>
2413b1
Date: Fri, 16 Feb 2018 18:00:09 +0100
2413b1
Subject: [PATCH 7/7] Fixed NSSDatabase.add_ca_cert().
2413b1
2413b1
The NSSDatabase.add_ca_cert() has been modified to import CA
2413b1
certificates into internal token instead of HSM since trust
2413b1
validation is done by NSS using internal token.
2413b1
2413b1
https://pagure.io/dogtagpki/issue/2944
2413b1
2413b1
Change-Id: I460cd752d741f3f91306c510ce469a023828343b
2413b1
(cherry picked from commit 2f8fa5bb2d33bf80e8a19f1e30697be3bb5de915)
2413b1
(cherry picked from commit cefae7941c0894a35dbebaf8f076a1941b910d93)
2413b1
---
2413b1
 base/common/python/pki/nssdb.py | 18 ++++++++++++++----
2413b1
 1 file changed, 14 insertions(+), 4 deletions(-)
2413b1
2413b1
diff --git a/base/common/python/pki/nssdb.py b/base/common/python/pki/nssdb.py
2413b1
index 7c2602e..934fe8b 100644
2413b1
--- a/base/common/python/pki/nssdb.py
2413b1
+++ b/base/common/python/pki/nssdb.py
2413b1
@@ -201,15 +201,25 @@ class NSSDatabase(object):
2413b1
             subprocess.check_call(cmd)
2413b1
 
2413b1
     def add_ca_cert(self, cert_file, trust_attributes=None):
2413b1
+
2413b1
+        # Import CA certificate into internal token with automatically
2413b1
+        # assigned nickname.
2413b1
+
2413b1
+        # If the certificate has previously been imported, it will keep
2413b1
+        # the existing nickname. If the certificate has not been imported,
2413b1
+        # JSS will generate a nickname based on root CA's subject DN.
2413b1
+
2413b1
+        # For example, if the root CA's subject DN is "CN=CA Signing
2413b1
+        # Certificate, O=EXAMPLE", the root CA cert's nickname will be
2413b1
+        # "CA Signing Certificate - EXAMPLE". The subordinate CA cert's
2413b1
+        # nickname will be "CA Signing Certificate - EXAMPLE #2".
2413b1
+
2413b1
         cmd = [
2413b1
             'pki',
2413b1
             '-d', self.directory,
2413b1
-            '-C', self.password_file
2413b1
+            '-C', self.internal_password_file
2413b1
         ]
2413b1
 
2413b1
-        if self.token:
2413b1
-            cmd.extend(['--token', self.token])
2413b1
-
2413b1
         cmd.extend([
2413b1
             'client-cert-import',
2413b1
             '--ca-cert', cert_file
2413b1
-- 
2413b1
1.8.3.1
2413b1