From 04055a9bc40486950a3288acf610522e767c1e27 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 17 Mar 2016 15:23:34 +0100 Subject: Additional clean-ups for PKCS #12 utilities. The pki_server_external_cert_path has been renamed to pki_server_external_certs_path to match the file name. A default pki_server_external_certs_path has been added to default.cfg. The pki pkcs12-export has been modified to export into existing PKCS #12 file by default. The pki-server instance-cert-export has been modified to accept a list of nicknames to export. https://fedorahosted.org/pki/ticket/1742 --- .../com/netscape/cmstools/pkcs12/PKCS12CertAddCLI.java | 2 +- .../src/com/netscape/cmstools/pkcs12/PKCS12ExportCLI.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'base/java-tools') diff --git a/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12CertAddCLI.java b/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12CertAddCLI.java index c3c5ef489..48e4907cf 100644 --- a/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12CertAddCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12CertAddCLI.java @@ -151,7 +151,7 @@ public class PKCS12CertAddCLI extends CLI { pkcs12 = new PKCS12(); } else { - // otherwise, add into the same file + // otherwise, add into the existing file pkcs12 = util.loadFromFile(filename, password); } diff --git a/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12ExportCLI.java b/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12ExportCLI.java index 52a993125..d42c449b4 100644 --- a/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12ExportCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/pkcs12/PKCS12ExportCLI.java @@ -18,6 +18,7 @@ package com.netscape.cmstools.pkcs12; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,6 +61,7 @@ public class PKCS12ExportCLI extends CLI { option.setArgName("path"); options.addOption(option); + options.addOption(null, "new-file", false, "Create a new PKCS #12 file"); options.addOption(null, "no-trust-flags", false, "Do not include trust flags"); options.addOption("v", "verbose", false, "Run in verbose mode."); @@ -124,14 +126,23 @@ public class PKCS12ExportCLI extends CLI { Password password = new Password(passwordString.toCharArray()); + boolean newFile = cmd.hasOption("new-file"); boolean trustFlagsEnabled = !cmd.hasOption("no-trust-flags"); try { PKCS12Util util = new PKCS12Util(); util.setTrustFlagsEnabled(trustFlagsEnabled); - // overwrite existing file - PKCS12 pkcs12 = new PKCS12(); + PKCS12 pkcs12; + + if (newFile || !new File(filename).exists()) { + // if new file requested or file does not exist, create a new file + pkcs12 = new PKCS12(); + + } else { + // otherwise, export into the existing file + pkcs12 = util.loadFromFile(filename, password); + } if (nicknames.length == 0) { // load all certificates -- cgit