Skip to content

Commit 26d5bf7

Browse files
committed
Update pki ca-cert-issue to support CRMF
The pki ca-cert-issue has been modified to support submitting an existing CRMF request, approving the request, and retrieving the issued cert in one step. Some KRA tests have been simplified using this command.
1 parent 0e1c025 commit 26d5bf7

File tree

4 files changed

+47
-72
lines changed

4 files changed

+47
-72
lines changed

.github/workflows/kra-basic-test.yml

+7-19
Original file line numberDiff line numberDiff line change
@@ -357,31 +357,19 @@ jobs:
357357
358358
docker exec pki cat testuser.csr
359359
360-
# submit cert request
361-
# https://github.com/dogtagpki/pki/wiki/Submitting-Certificate-Request-with-Key-Archival
362-
docker exec pki pki \
363-
ca-cert-request-submit \
364-
--request-type crmf \
365-
--csr-file testuser.csr \
366-
--profile caUserCert \
367-
--subject UID=testuser | tee output
368-
369-
REQUEST_ID=$(sed -n "s/^\s*Request ID:\s*\(\S*\)$/\1/p" output)
370-
echo "Request ID: $REQUEST_ID"
371-
372360
# issue cert
361+
# https://github.com/dogtagpki/pki/wiki/Issuing-Certificates
373362
docker exec pki pki \
374363
-u caadmin \
375364
-w Secret.123 \
376-
ca-cert-request-approve \
377-
--force \
378-
$REQUEST_ID | tee output
379-
380-
CERT_ID=$(sed -n "s/^\s*Certificate ID:\s*\(\S*\)$/\1/p" output)
381-
echo "Cert ID: $CERT_ID"
365+
ca-cert-issue \
366+
--request-type crmf \
367+
--profile caUserCert \
368+
--subject UID=testuser \
369+
--csr-file testuser.csr \
370+
--output-file testuser.crt
382371
383372
# import cert into NSS database
384-
docker exec pki pki ca-cert-export --output-file testuser.crt $CERT_ID
385373
docker exec pki pki nss-cert-import --cert testuser.crt testuser
386374
387375
# the cert should match the key (trust flags must be u,u,u)

.github/workflows/kra-container-test.yml

+7-28
Original file line numberDiff line numberDiff line change
@@ -514,42 +514,21 @@ jobs:
514514
515515
docker exec client cat testuser.csr
516516
517-
# submit cert request
518-
# https://github.com/dogtagpki/pki/wiki/Submitting-Certificate-Request-with-Key-Archival
519-
docker exec client pki \
520-
-U https://ca.example.com:8443 \
521-
ca-cert-request-submit \
522-
--request-type crmf \
523-
--csr-file testuser.csr \
524-
--profile caUserCert \
525-
--subject UID=testuser | tee output
526-
527-
REQUEST_ID=$(sed -n "s/^\s*Request ID:\s*\(\S*\)$/\1/p" output)
528-
echo "Request ID: $REQUEST_ID"
529-
echo "$REQUEST_ID" > request.id
530-
531517
- name: Issue cert with key archival
532518
run: |
533-
REQUEST_ID=$(cat request.id)
534-
535519
# issue cert
520+
# https://github.com/dogtagpki/pki/wiki/Issuing-Certificates
536521
docker exec client pki \
537522
-U https://ca.example.com:8443 \
538523
-n admin \
539-
ca-cert-request-approve \
540-
--force \
541-
$REQUEST_ID | tee output
542-
543-
CERT_ID=$(sed -n "s/^\s*Certificate ID:\s*\(\S*\)$/\1/p" output)
544-
echo "Cert ID: $CERT_ID"
524+
ca-cert-issue \
525+
--request-type crmf \
526+
--profile caUserCert \
527+
--subject UID=testuser \
528+
--csr-file testuser.csr \
529+
--output-file testuser.crt
545530
546531
# import cert into NSS database
547-
docker exec client pki \
548-
-U https://ca.example.com:8443 \
549-
ca-cert-export \
550-
--output-file testuser.crt \
551-
$CERT_ID
552-
553532
docker exec client pki nss-cert-import --cert testuser.crt testuser
554533
555534
# the cert should match the key (trust flags must be u,u,u)

.github/workflows/kra-migration-test.yml

+7-19
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,19 @@ jobs:
109109
110110
docker exec pki1 cat testuser.csr
111111
112-
# submit cert request
113-
# https://github.com/dogtagpki/pki/wiki/Submitting-Certificate-Request-with-Key-Archival
114-
docker exec pki1 pki \
115-
ca-cert-request-submit \
116-
--request-type crmf \
117-
--csr-file testuser.csr \
118-
--profile caUserCert \
119-
--subject UID=testuser | tee output
120-
121-
REQUEST_ID=$(sed -n "s/^\s*Request ID:\s*\(\S*\)\s*$/\1/p" output)
122-
echo "Request ID: $REQUEST_ID"
123-
124112
# issue cert
113+
# https://github.com/dogtagpki/pki/wiki/Issuing-Certificates
125114
docker exec pki1 pki \
126115
-u caadmin \
127116
-w Secret.123 \
128-
ca-cert-request-approve \
129-
--force \
130-
$REQUEST_ID | tee output
131-
132-
CERT_ID=$(sed -n "s/^\s*Certificate ID:\s*\(\S*\)\s*$/\1/p" output)
133-
echo "Cert ID: $CERT_ID"
117+
ca-cert-issue \
118+
--request-type crmf \
119+
--profile caUserCert \
120+
--subject UID=testuser \
121+
--csr-file testuser.csr \
122+
--output-file $SHARED/testuser.crt
134123
135124
# import cert into NSS database
136-
docker exec pki1 pki ca-cert-export --output-file $SHARED/testuser.crt $CERT_ID
137125
docker exec pki1 pki nss-cert-import --cert $SHARED/testuser.crt testuser
138126
139127
# the cert should match the key (trust flags must be u,u,u)

base/tools/src/main/java/com/netscape/cmstools/ca/CACertIssueCLI.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ public void createOptions() {
8585
option.setArgName("profile");
8686
options.addOption(option);
8787

88-
option = new Option(null, "request-type", true, "Request type (default: pkcs10)");
88+
option = new Option(null, "request-type", true, "Request type: pkcs10 (default), crmf");
8989
option.setArgName("type");
9090
options.addOption(option);
9191

92+
option = new Option(null, "request-format", true, "Request type: PEM (default), DER");
93+
option.setArgName("format");
94+
options.addOption(option);
95+
9296
option = new Option(null, "renewal", false, "Submit renewal request");
9397
options.addOption(option);
9498

@@ -251,8 +255,6 @@ public byte[] issueCert(
251255
@Override
252256
public void execute(CommandLine cmd) throws Exception {
253257

254-
String[] cmdArgs = cmd.getArgs();
255-
256258
String inputFile = cmd.getOptionValue("input-file");
257259
String profileID = cmd.getOptionValue("profile");
258260

@@ -330,14 +332,32 @@ public void execute(CommandLine cmd) throws Exception {
330332

331333
if (csrFilename != null) {
332334

333-
csr = loadFile(csrFilename);
334-
logger.debug("CSR:\n" + csr);
335+
byte[] bytes = Files.readAllBytes(Paths.get(csrFilename));
336+
337+
String requestFormat = cmd.getOptionValue("request-format");
338+
if (requestFormat == null || "PEM".equalsIgnoreCase(requestFormat)) {
339+
bytes = CertUtil.parseCSR(new String(bytes));
340+
341+
} else if ("DER".equalsIgnoreCase(requestFormat)) {
342+
// nothing to do
343+
344+
} else {
345+
throw new Exception("Unsupported request format: " + requestFormat);
346+
}
335347

336-
byte[] bytes = CertUtil.parseCSR(csr);
337348
if ("pkcs10".equals(requestType)) {
338349
pkcs10 = new PKCS10(bytes);
350+
csr = CertUtil.toPEM(pkcs10);
351+
352+
} else if ("crmf".equals(requestType)) {
353+
csr = CertUtil.encodeCRMF(bytes);
354+
355+
} else {
356+
throw new Exception("Unsupported request type: " + requestType);
339357
}
340358

359+
logger.debug("CSR:\n" + csr);
360+
341361
for (ProfileInput input : request.getInputs()) {
342362
ProfileAttribute csrAttr = input.getAttribute("cert_request");
343363
if (csrAttr != null) {

0 commit comments

Comments
 (0)