2a8f41
From 05568960aea79e9e3fb0f243ae3adc68963bcc69 Mon Sep 17 00:00:00 2001
2a8f41
From: Christina Fu <cfu@redhat.com>
2a8f41
Date: Wed, 3 Nov 2021 18:21:53 -0700
2a8f41
Subject: [PATCH 1/4] Bug-2008319-pkispawn EC subCA 2-step failure in FIPS mode
2a8f41
2a8f41
This patch addressed issue reported on failure with EC subCA 2-step
2a8f41
installation in FIPS mode.
2a8f41
My investigation reveals that certutil -R would fail in create_request nssdb.py.
2a8f41
I found two different commits having attempts to fix the same issue:
2a8f41
2a8f41
    f1f32c3
2a8f41
    8bf682a
2a8f41
However, the the resulting code appears to NOT contain the working copy.
2a8f41
2a8f41
I pulled out code in this area in 10.2 as a reference (carefully referenced)
2a8f41
to address the issue. It appears to fix the problem. I was able to create
2a8f41
subCA successfully in the FIPS environment on both soft token and hsm.
2a8f41
2a8f41
Note: The pkispawn parameter "pki_req_ski=DEFAULT" introduced in the two
2a8f41
contradicting commits mentioned above doesn't seem to work with the
2a8f41
source right out of the tip of DOGTAG_10_5_BRANCH;  I tried to touch as
2a8f41
little as possible and not alter the logic involving pki_req_ski, and
2a8f41
the result remains the same error as before this patch.
2a8f41
2a8f41
fixes https://bugzilla.redhat.com/show_bug.cgi?id=2008319
2a8f41
2a8f41
(cherry picked from commit 01b4205efd97c592913f4866885b476f8593dbad)
2a8f41
---
2a8f41
 base/common/python/pki/nssdb.py | 97 ++++++++++++++++++++++++++++++++++++-----
2a8f41
 1 file changed, 87 insertions(+), 10 deletions(-)
2a8f41
2a8f41
diff --git a/base/common/python/pki/nssdb.py b/base/common/python/pki/nssdb.py
2a8f41
index 11509f0..4b427f5 100644
2a8f41
--- a/base/common/python/pki/nssdb.py
2a8f41
+++ b/base/common/python/pki/nssdb.py
2a8f41
@@ -424,7 +424,16 @@ class NSSDatabase(object):
2a8f41
         logger.debug('Command: %s', ' '.join(cmd))
2a8f41
         subprocess.check_call(cmd)
2a8f41
 
2a8f41
-    def create_noise(self, noise_file, size=2048):
2a8f41
+    def create_noise(self, noise_file, size=2048, key_type='rsa'):
2a8f41
+        # Under EC keys, key_size parameter is actually the name of a curve.
2a8f41
+        # This curve maps to a specific size, but EC keys require less entropy
2a8f41
+        # to generate than RSA keys. We can either maintain a mapping of
2a8f41
+        # curve name -> key size (and note that the openssl rand command takes
2a8f41
+        # the number of bytes, not the number of bits), or we can hard-code
2a8f41
+        # some safe value. We choose the latter.
2a8f41
+        if key_type.lower() in ('ec', 'ecc'):
2a8f41
+            size = 1024
2a8f41
+
2a8f41
         cmd = [
2a8f41
             'openssl',
2a8f41
             'rand',
2a8f41
@@ -479,17 +488,20 @@ class NSSDatabase(object):
2a8f41
                 Raw extension data (``bytes``)
2a8f41
 
2a8f41
         """
2a8f41
-        if not cka_id:
2a8f41
-            cka_id = self.generate_key(
2a8f41
-                key_type=key_type, key_size=key_size,
2a8f41
-                curve=curve, noise_file=noise_file)
2a8f41
-        if not isinstance(cka_id, six.text_type):
2a8f41
-            raise TypeError('cka_id must be a text string')
2a8f41
+
2a8f41
+        logger.debug("nssdb.py:create_request starts")
2a8f41
 
2a8f41
         tmpdir = tempfile.mkdtemp()
2a8f41
 
2a8f41
         try:
2a8f41
             if subject_key_id is not None:
2a8f41
+                if not cka_id:
2a8f41
+                    cka_id = self.generate_key(
2a8f41
+                        key_type=key_type, key_size=key_size,
2a8f41
+                        curve=curve, noise_file=noise_file)
2a8f41
+                if not isinstance(cka_id, six.text_type):
2a8f41
+                    raise TypeError('cka_id must be a text string')
2a8f41
+
2a8f41
                 if subject_key_id == 'DEFAULT':
2a8f41
                     # Caller wants a default subject key ID included
2a8f41
                     # in CSR.  To do this we must first generate a
2a8f41
@@ -536,11 +548,25 @@ class NSSDatabase(object):
2a8f41
             if token:
2a8f41
                 cmd.extend(['-h', token])
2a8f41
 
2a8f41
+            if cka_id is not None:
2a8f41
+                key_args = ['-k', cka_id]
2a8f41
+            else:
2a8f41
+                key_args = self.__generate_key_args(
2a8f41
+                    key_type=key_type, key_size=key_size, curve=curve)
2a8f41
+                if noise_file is None:
2a8f41
+                    noise_file = os.path.join(tmpdir, 'noise')
2a8f41
+                    size = key_size if key_size else 2048
2a8f41
+                    self.create_noise(noise_file=noise_file, size=size, key_type=key_type)
2a8f41
+                key_args.extend(['-z', noise_file])
2a8f41
+
2a8f41
+            cmd.extend(key_args)
2a8f41
+
2a8f41
+            if self.password_file:
2a8f41
+                cmd.extend(['-f', self.password_file])
2a8f41
+
2a8f41
             cmd.extend([
2a8f41
-                '-f', self.password_file,
2a8f41
                 '-s', subject_dn,
2a8f41
                 '-o', binary_request_file,
2a8f41
-                '-k', cka_id,
2a8f41
             ])
2a8f41
 
2a8f41
             if hash_alg:
2a8f41
@@ -690,7 +716,7 @@ class NSSDatabase(object):
2a8f41
             fd, noise_file = tempfile.mkstemp()
2a8f41
             os.close(fd)
2a8f41
             size = key_size if key_size else 2048
2a8f41
-            self.create_noise(noise_file=noise_file, size=size)
2a8f41
+            self.create_noise(noise_file=noise_file, size=size, key_type=key_type)
2a8f41
         cmd.extend(['-z', noise_file])
2a8f41
 
2a8f41
         try:
2a8f41
@@ -1334,3 +1360,54 @@ class NSSDatabase(object):
2a8f41
 
2a8f41
         finally:
2a8f41
             shutil.rmtree(tmpdir)
2a8f41
+
2a8f41
+
2a8f41
+    @staticmethod
2a8f41
+    def __generate_key_args(key_type=None, key_size=None, curve=None):
2a8f41
+        """
2a8f41
+        Construct certutil keygen command args.
2a8f41
+
2a8f41
+        """
2a8f41
+        args = []
2a8f41
+        is_ec = key_type and key_type.lower() in ('ec', 'ecc')
2a8f41
+
2a8f41
+        if key_type:
2a8f41
+            # The -k parameter is either a key type or an identifer of a key
2a8f41
+            # to reuse. Make sure to handle ec correctly: the type should be
2a8f41
+            # "ec" not "ecc".
2a8f41
+            if is_ec:
2a8f41
+                args.extend(['-k', 'ec'])
2a8f41
+            else:
2a8f41
+                args.extend(['-k', key_type])
2a8f41
+
2a8f41
+        if is_ec:
2a8f41
+            # This is fix for Bugzilla 1544843
2a8f41
+            args.extend([
2a8f41
+                '--keyOpFlagsOn', 'sign',
2a8f41
+                '--keyOpFlagsOff', 'derive',
2a8f41
+            ])
2a8f41
+
2a8f41
+            # When we want to generate a new EC key, we have to know the curve
2a8f41
+            # we want to use. This is either passed via the curve parameter or
2a8f41
+            # via the key_size parameter. If neither is specified, we have a
2a8f41
+            # problem. If both are specified and differ, we're confused. The
2a8f41
+            # reason is because the curve determines the size of the key;
2a8f41
+            # after that you don't have a choice.
2a8f41
+            if not curve and not key_size:
2a8f41
+                msg = "Must specify the curve to use when generating an "
2a8f41
+                msg += "elliptic curve key."
2a8f41
+                raise ValueError(msg)
2a8f41
+            if curve and key_size and curve != key_size:
2a8f41
+                msg = "Specified both curve (%s) and key size (%s) when "
2a8f41
+                msg += "generating an elliptic curve key, but they differ."
2a8f41
+                raise ValueError(msg % (curve, key_size))
2a8f41
+
2a8f41
+            if curve:
2a8f41
+                args.extend(['-q', str(curve)])
2a8f41
+            else:
2a8f41
+                args.extend(['-q', str(key_size)])
2a8f41
+        else:
2a8f41
+            if key_size:
2a8f41
+                args.extend(['-g', str(key_size)])
2a8f41
+
2a8f41
+        return args
2a8f41
-- 
2a8f41
1.8.3.1
2a8f41
2a8f41
2a8f41
From 304a130418f9b5ed453b31931c635c186147c042 Mon Sep 17 00:00:00 2001
2a8f41
From: Christina Fu <cfu@redhat.com>
2a8f41
Date: Wed, 10 Nov 2021 15:07:14 -0800
2a8f41
Subject: [PATCH 2/4] Bug1998597-TPS-profile-enforce-permitted-agents
2a8f41
2a8f41
this patch addresses additional issues for https://bugzilla.redhat.com/show_bug.cgi?id=1979710
2a8f41
2a8f41
This patch specifically addresses the pki cli "tps-cert-find" option.
2a8f41
e.g. # pki -d /opt/pki/certdb -P https -p 25443 -h localhost -c SECret.123 -n 'TPS_AgentV' tps-cert-find --token 40906145C76224192D11
2a8f41
2a8f41
additional restrictions are added to TokenService.java replaceToken and
2a8f41
removeToken methods
2a8f41
where I do not see direct access to as a "just in case" move.
2a8f41
2a8f41
fixes https://bugzilla.redhat.com/show_bug.cgi?id=1998597
2a8f41
2a8f41
(cherry picked from commit a7ace46d55bb290cc34767fab11bf72736e86342)
2a8f41
---
2a8f41
 .../dogtagpki/server/tps/rest/TPSCertService.java  | 65 ++++++++++++++++++++--
2a8f41
 .../dogtagpki/server/tps/rest/TokenService.java    | 39 ++++++++++++-
2a8f41
 2 files changed, 96 insertions(+), 8 deletions(-)
2a8f41
2a8f41
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TPSCertService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TPSCertService.java
2a8f41
index 95f7a61..f4a1f3c 100644
2a8f41
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TPSCertService.java
2a8f41
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TPSCertService.java
2a8f41
@@ -21,8 +21,10 @@ package org.dogtagpki.server.tps.rest;
2a8f41
 import java.io.UnsupportedEncodingException;
2a8f41
 import java.net.URI;
2a8f41
 import java.net.URLEncoder;
2a8f41
+
2a8f41
 import java.util.HashMap;
2a8f41
 import java.util.Iterator;
2a8f41
+import java.util.List;
2a8f41
 import java.util.Map;
2a8f41
 
2a8f41
 import javax.ws.rs.core.Response;
2a8f41
@@ -32,13 +34,19 @@ import org.dogtagpki.server.tps.dbs.TPSCertDatabase;
2a8f41
 import org.dogtagpki.server.tps.dbs.TPSCertRecord;
2a8f41
 import org.jboss.resteasy.plugins.providers.atom.Link;
2a8f41
 
2a8f41
+import com.netscape.cms.realm.PKIPrincipal;
2a8f41
 import com.netscape.certsrv.apps.CMS;
2a8f41
 import com.netscape.certsrv.base.BadRequestException;
2a8f41
 import com.netscape.certsrv.base.PKIException;
2a8f41
 import com.netscape.certsrv.tps.cert.TPSCertCollection;
2a8f41
 import com.netscape.certsrv.tps.cert.TPSCertData;
2a8f41
 import com.netscape.certsrv.tps.cert.TPSCertResource;
2a8f41
+import org.dogtagpki.server.tps.dbs.TokenDatabase;
2a8f41
+import org.dogtagpki.server.tps.dbs.TokenRecord;
2a8f41
 import com.netscape.cms.servlet.base.PKIService;
2a8f41
+import com.netscape.certsrv.user.UserResource;
2a8f41
+import com.netscape.certsrv.usrgrp.IUGSubsystem;
2a8f41
+import com.netscape.certsrv.usrgrp.IUser;
2a8f41
 
2a8f41
 /**
2a8f41
  * @author Endi S. Dewata
2a8f41
@@ -98,6 +106,8 @@ public class TPSCertService extends PKIService implements TPSCertResource {
2a8f41
 
2a8f41
     @Override
2a8f41
     public Response findCerts(String filter, String tokenID, Integer start, Integer size) {
2a8f41
+        String method = "TPSCertService:findCerts: ";
2a8f41
+        String msg = "";
2a8f41
 
2a8f41
         CMS.debug("TPSCertService.findCerts(" + filter + ", " + tokenID + ", " + start + ", " + size + ")");
2a8f41
 
2a8f41
@@ -116,24 +126,43 @@ public class TPSCertService extends PKIService implements TPSCertResource {
2a8f41
         size = size == null ? DEFAULT_SIZE : size;
2a8f41
 
2a8f41
         try {
2a8f41
+            List<String> authorizedProfiles = getAuthorizedProfiles();
2a8f41
+            if (authorizedProfiles == null) {
2a8f41
+                msg = "authorizedProfiles null";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
2a8f41
+            TokenDatabase tokDatabase = subsystem.getTokenDatabase();
2a8f41
+            TokenRecord record = tokDatabase.getRecord(tokenID);
2a8f41
+            if (record == null) {
2a8f41
+                msg = "Token record not found";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+            String type = record.getType();
2a8f41
+            if ((type != null) && !type.isEmpty() && !authorizedProfiles.contains(UserResource.ALL_PROFILES) && !authorizedProfiles.contains(type))
2a8f41
+                throw new PKIException(method + "Token record restricted");
2a8f41
+
2a8f41
+            // token was from an authorized profile
2a8f41
             TPSCertDatabase database = subsystem.getCertDatabase();
2a8f41
 
2a8f41
-            Iterator<TPSCertRecord> activities = database.findRecords(filter, attributes).iterator();
2a8f41
+            Iterator<TPSCertRecord> certRecs = database.findRecords(filter, attributes).iterator();
2a8f41
 
2a8f41
             TPSCertCollection response = new TPSCertCollection();
2a8f41
             int i = 0;
2a8f41
 
2a8f41
             // skip to the start of the page
2a8f41
-            for ( ; i
2a8f41
+            for ( ; i
2a8f41
 
2a8f41
             // return entries up to the page size
2a8f41
-            for ( ; i
2a8f41
-                response.addEntry(createCertData(activities.next()));
2a8f41
+            for ( ; i
2a8f41
+                response.addEntry(createCertData(certRecs.next()));
2a8f41
             }
2a8f41
 
2a8f41
             // count the total entries
2a8f41
-            for ( ; activities.hasNext(); i++) activities.next();
2a8f41
+            for ( ; certRecs.hasNext(); i++) certRecs.next();
2a8f41
             response.setTotal(i);
2a8f41
 
2a8f41
             if (start > 0) {
2a8f41
@@ -156,14 +185,27 @@ public class TPSCertService extends PKIService implements TPSCertResource {
2a8f41
 
2a8f41
     @Override
2a8f41
     public Response getCert(String certID) {
2a8f41
+       String method = "TPSCertService:getCert: ";
2a8f41
+       String msg = "";
2a8f41
 
2a8f41
         if (certID == null) throw new BadRequestException("Certificate ID is null.");
2a8f41
 
2a8f41
         CMS.debug("TPSCertService.getCert(\"" + certID + "\")");
2a8f41
 
2a8f41
         try {
2a8f41
+            List<String> authorizedProfiles = getAuthorizedProfiles();
2a8f41
+            if (authorizedProfiles == null) {
2a8f41
+                msg = "authorizedProfiles null";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
2a8f41
             TPSCertDatabase database = subsystem.getCertDatabase();
2a8f41
+            TPSCertRecord certRec = database.getRecord(certID);
2a8f41
+            String type = certRec.getKeyType();
2a8f41
+            if ((type != null) && !type.isEmpty() && !authorizedProfiles.contains(UserResource.ALL_PROFILES) && !authorizedProfiles.contains(type))
2a8f41
+                   throw new PKIException(method + "Cert record restricted");
2a8f41
 
2a8f41
             return createOKResponse(createCertData(database.getRecord(certID)));
2a8f41
 
2a8f41
@@ -172,4 +214,17 @@ public class TPSCertService extends PKIService implements TPSCertResource {
2a8f41
             throw new PKIException(e.getMessage());
2a8f41
         }
2a8f41
     }
2a8f41
+
2a8f41
+    /*
2a8f41
+     * returns a list of TPS profiles allowed for the current user
2a8f41
+     */
2a8f41
+    List<String> getAuthorizedProfiles()
2a8f41
+           throws Exception {
2a8f41
+        String method = "TokenService.getAuthorizedProfiles: ";
2a8f41
+
2a8f41
+        PKIPrincipal pkiPrincipal = (PKIPrincipal) servletRequest.getUserPrincipal();
2a8f41
+        IUser user = pkiPrincipal.getUser();
2a8f41
+
2a8f41
+        return user.getTpsProfiles();
2a8f41
+    }
2a8f41
 }
2a8f41
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
2a8f41
index a7a6022..d2a3444 100644
2a8f41
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
2a8f41
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
2a8f41
@@ -394,9 +394,9 @@ public class TokenService extends SubsystemService implements TokenResource {
2a8f41
 
2a8f41
         String method = "TokenService.retrieveTokensWithoutVLV: ";
2a8f41
 
2a8f41
-	List<TokenRecord> tokens = (List<TokenRecord>) database.findRecords(filter);
2a8f41
-	int total = tokens.size();
2a8f41
-	CMS.debug(method + "total: " + total);
2a8f41
+        List<TokenRecord> tokens = (List<TokenRecord>) database.findRecords(filter);
2a8f41
+        int total = tokens.size();
2a8f41
+        CMS.debug(method + "total: " + total);
2a8f41
 
2a8f41
         List<String> authorizedProfiles = getAuthorizedProfiles();
2a8f41
 
2a8f41
@@ -596,9 +596,26 @@ public class TokenService extends SubsystemService implements TokenResource {
2a8f41
         TokenRecord tokenRecord = null;
2a8f41
         String msg = "replace token";
2a8f41
         try {
2a8f41
+            List<String> authorizedProfiles = getAuthorizedProfiles();
2a8f41
+            if (authorizedProfiles == null) {
2a8f41
+                msg = "authorizedProfiles null";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
             TokenDatabase database = subsystem.getTokenDatabase();
2a8f41
 
2a8f41
             tokenRecord = database.getRecord(tokenID);
2a8f41
+            if (tokenRecord == null) {
2a8f41
+                msg = "Token record not found";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
+            String type = tokenRecord.getType();
2a8f41
+            if ((type != null) && !type.isEmpty() && !authorizedProfiles.contains(UserResource.ALL_PROFILES) && !authorizedProfiles.contains(type))
2a8f41
+                   throw new PKIException(method + "Token record restricted");
2a8f41
+
2a8f41
             tokenRecord.setUserID(remoteUser);
2a8f41
             auditModParams.put("userID", remoteUser);
2a8f41
             tokenRecord.setType(tokenData.getType());
2a8f41
@@ -921,8 +938,24 @@ public class TokenService extends SubsystemService implements TokenResource {
2a8f41
         TokenRecord tokenRecord = null;
2a8f41
         String msg = "remove token";
2a8f41
         try {
2a8f41
+            List<String> authorizedProfiles = getAuthorizedProfiles();
2a8f41
+            if (authorizedProfiles == null) {
2a8f41
+                msg = "authorizedProfiles null";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
             TokenDatabase database = subsystem.getTokenDatabase();
2a8f41
             tokenRecord = database.getRecord(tokenID);
2a8f41
+            if (tokenRecord == null) {
2a8f41
+                msg = "Token record not found";
2a8f41
+                CMS.debug(method + msg);
2a8f41
+                throw new PKIException(method + msg);
2a8f41
+            }
2a8f41
+
2a8f41
+            String type = tokenRecord.getType();
2a8f41
+            if ((type != null) && !type.isEmpty() && !authorizedProfiles.contains(UserResource.ALL_PROFILES) && !authorizedProfiles.contains(type))
2a8f41
+                   throw new PKIException(method + "Token record restricted");
2a8f41
 
2a8f41
             //delete all certs associated with this token
2a8f41
             CMS.debug(method + "about to remove all certificates associated with the token first");
2a8f41
-- 
2a8f41
1.8.3.1
2a8f41
2a8f41
2a8f41
From 4c190532fd0fb8ce1b1337a39fb3b3686f4df5a2 Mon Sep 17 00:00:00 2001
2a8f41
From: Christina Fu <cfu@redhat.com>
2a8f41
Date: Tue, 14 Dec 2021 17:25:02 -0800
2a8f41
Subject: [PATCH 3/4] Bug2018608-subCA created with invalid certs (pkispawn
2a8f41
 single step)
2a8f41
2a8f41
This patch takes care of the issue reported in the following bugs
2a8f41
  Bug 2018608 - Invalid certificates with creation of subCA (pkispawn single step)
2a8f41
  Bug 2022071 - KRA subsystem installation pointing to SubCA failed
2a8f41
2a8f41
My investigation reveals that the fix for the following bug contains
2a8f41
a bug where the subject DN of a certificate could be unintentionally
2a8f41
recoded:
2a8f41
Bug 1978017 - PKCS10Client EC Attribute Encoding
2a8f41
2a8f41
fixes https://bugzilla.redhat.com/show_bug.cgi?id=2018608
2a8f41
fixes https://bugzilla.redhat.com/show_bug.cgi?id=2022071
2a8f41
2a8f41
(cherry picked from commit e62ead81cf1e274fd73248d3b4f73d0431792f84)
2a8f41
---
2a8f41
 base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java | 15 ++++++++++-----
2a8f41
 1 file changed, 10 insertions(+), 5 deletions(-)
2a8f41
2a8f41
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2a8f41
index befceed..a10c6aa 100644
2a8f41
--- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2a8f41
+++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
2a8f41
@@ -1757,11 +1757,16 @@ public class CryptoUtil {
2a8f41
             pkcs10 = new PKCS10(key);
2a8f41
         }
2a8f41
 
2a8f41
-        Name n = getJssName(encodeSubj, subjectName);
2a8f41
-        ByteArrayOutputStream subjectEncStream = new ByteArrayOutputStream();
2a8f41
-        n.encode(subjectEncStream);
2a8f41
-        byte[] b = subjectEncStream.toByteArray();
2a8f41
-        X500Name name = new X500Name(b);
2a8f41
+        X500Name name = null;
2a8f41
+        if (!encodeSubj)
2a8f41
+            name = new X500Name(subjectName);
2a8f41
+        else {
2a8f41
+            Name n = getJssName(encodeSubj, subjectName);
2a8f41
+            ByteArrayOutputStream subjectEncStream = new ByteArrayOutputStream();
2a8f41
+            n.encode(subjectEncStream);
2a8f41
+            byte[] b = subjectEncStream.toByteArray();
2a8f41
+            name = new X500Name(b);
2a8f41
+        }
2a8f41
         X500Signer signer = new X500Signer(sig, name);
2a8f41
 
2a8f41
         pkcs10.encodeAndSign(signer);
2a8f41
-- 
2a8f41
1.8.3.1
2a8f41
2a8f41
2a8f41
From b040a99f81d0d56b1186086cf085a458a4de049c Mon Sep 17 00:00:00 2001
2a8f41
From: Christina Fu <cfu@redhat.com>
2a8f41
Date: Tue, 14 Dec 2021 17:36:04 -0800
2a8f41
Subject: [PATCH 4/4] Bug2018608-(profile fix) subCA created with invalid certs
2a8f41
 (pkispawn single step)
2a8f41
2a8f41
While investigating Bug 2018608, I found the CA enrollment profile
2a8f41
caInstallCACert.cfg to have only 2 year validity; Also the
2a8f41
signingAlgsAllowed list is outdated.
2a8f41
This patch addresses the aforementioned issues.
2a8f41
2a8f41
related to https://bugzilla.redhat.com/show_bug.cgi?id=2018608
2a8f41
2a8f41
(cherry picked from commit ca78e499ef474dd0dbeefaef44afbbe3bb4e8d59)
2a8f41
---
2a8f41
 base/ca/shared/profiles/ca/caInstallCACert.cfg | 8 ++++----
2a8f41
 1 file changed, 4 insertions(+), 4 deletions(-)
2a8f41
2a8f41
diff --git a/base/ca/shared/profiles/ca/caInstallCACert.cfg b/base/ca/shared/profiles/ca/caInstallCACert.cfg
2a8f41
index 7c433c0..451c31e 100644
2a8f41
--- a/base/ca/shared/profiles/ca/caInstallCACert.cfg
2a8f41
+++ b/base/ca/shared/profiles/ca/caInstallCACert.cfg
2a8f41
@@ -21,17 +21,17 @@ policyset.caCertSet.1.default.name=Subject Name Default
2a8f41
 policyset.caCertSet.1.default.params.name=
2a8f41
 policyset.caCertSet.2.constraint.class_id=validityConstraintImpl
2a8f41
 policyset.caCertSet.2.constraint.name=Validity Constraint
2a8f41
-policyset.caCertSet.2.constraint.params.range=720
2a8f41
+policyset.caCertSet.2.constraint.params.range=6940
2a8f41
 policyset.caCertSet.2.constraint.params.notBeforeCheck=false
2a8f41
 policyset.caCertSet.2.constraint.params.notAfterCheck=false
2a8f41
 policyset.caCertSet.2.default.class_id=validityDefaultImpl
2a8f41
 policyset.caCertSet.2.default.name=Validity Default
2a8f41
-policyset.caCertSet.2.default.params.range=720
2a8f41
+policyset.caCertSet.2.default.params.range=6940
2a8f41
 policyset.caCertSet.2.default.params.startTime=0
2a8f41
 policyset.caCertSet.3.constraint.class_id=keyConstraintImpl
2a8f41
 policyset.caCertSet.3.constraint.name=Key Constraint
2a8f41
 policyset.caCertSet.3.constraint.params.keyType=-
2a8f41
-policyset.caCertSet.3.constraint.params.keyParameters=1024,2048,3072,4096,nistp256,nistp384,nistp521
2a8f41
+policyset.caCertSet.3.constraint.params.keyParameters=2048,3072,4096,nistp256,nistp384,nistp521
2a8f41
 policyset.caCertSet.3.default.class_id=userKeyDefaultImpl
2a8f41
 policyset.caCertSet.3.default.name=Key Default
2a8f41
 policyset.caCertSet.4.constraint.class_id=noConstraintImpl
2a8f41
@@ -80,7 +80,7 @@ policyset.caCertSet.8.default.name=Subject Key Identifier Extension Default
2a8f41
 policyset.caCertSet.8.default.params.critical=false
2a8f41
 policyset.caCertSet.9.constraint.class_id=signingAlgConstraintImpl
2a8f41
 policyset.caCertSet.9.constraint.name=No Constraint
2a8f41
-policyset.caCertSet.9.constraint.params.signingAlgsAllowed=SHA1withRSA,SHA256withRSA,SHA512withRSA,SHA1withDSA,SHA1withEC,SHA256withEC,SHA384withRSA,SHA384withEC,SHA512withEC,SHA256withRSA/PSS,SHA384withRSA/PSS,SHA512withRSA/PSS
2a8f41
+policyset.caCertSet.9.constraint.params.signingAlgsAllowed=SHA256withRSA,SHA512withRSA,SHA256withEC,SHA384withRSA,SHA384withEC,SHA512withEC,SHA256withRSA/PSS,SHA384withRSA/PSS,SHA512withRSA/PSS
2a8f41
 policyset.caCertSet.9.default.class_id=signingAlgDefaultImpl
2a8f41
 policyset.caCertSet.9.default.name=Signing Alg
2a8f41
 policyset.caCertSet.9.default.params.signingAlg=-
2a8f41
-- 
2a8f41
1.8.3.1
2a8f41