Skip to content

Commit

Permalink
Update pki ca-cert-request-submit
Browse files Browse the repository at this point in the history
The pki ca-cert-request-submit has been updated to get the
subject DN from the PKCS #10 request by default.
  • Loading branch information
edewata committed Jun 7, 2023
1 parent cbeea95 commit e916d58
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.dogtag.util.cert.CertUtil;
import org.dogtagpki.cli.CommandCLI;
import org.mozilla.jss.netscape.security.pkcs.PKCS10;
import org.mozilla.jss.netscape.security.util.Cert;
import org.mozilla.jss.netscape.security.util.Utils;
import org.mozilla.jss.netscape.security.x509.X500Name;
Expand Down Expand Up @@ -193,13 +195,18 @@ public void execute(CommandLine cmd) throws Exception {

String csrFilename = cmd.getOptionValue("csr-file");
String csr = null;
PKCS10 pkcs10 = null;

if (csrFilename != null) {

csr = loadFile(csrFilename);

logger.debug("CSR:\n" + csr);

byte[] bytes = CertUtil.parseCSR(csr);
if ("pkcs10".equals(requestType)) {
pkcs10 = new PKCS10(bytes);
}

for (ProfileInput input : request.getInputs()) {
ProfileAttribute csrAttr = input.getAttribute("cert_request");
if (csrAttr != null) {
Expand All @@ -225,6 +232,14 @@ public void execute(CommandLine cmd) throws Exception {
}

String subjectDN = cmd.getOptionValue("subject");

if (subjectDN == null) {
// if no subject DN provided, get from CSR
if (pkcs10 != null) {
subjectDN = pkcs10.getSubjectName().toLdapDNString();
}
}

if (subjectDN != null) {
DN dn = new DN(subjectDN);
Vector<?> rdns = dn.getRDNs();
Expand Down

0 comments on commit e916d58

Please sign in to comment.