From 00423180cc2fcfa97a6d9ca515588d703d7235ab Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 11 Oct 2013 11:41:53 -0400 Subject: Renamed client commands. The client-{action}-cert commands have been renamed into client-cert-{action} for consistency. --- .../com/netscape/cmstools/client/ClientCLI.java | 6 +- .../cmstools/client/ClientCertFindCLI.java | 87 +++++++++++++++ .../cmstools/client/ClientCertImportCLI.java | 122 +++++++++++++++++++++ .../cmstools/client/ClientCertRemoveCLI.java | 68 ++++++++++++ .../cmstools/client/ClientFindCertCLI.java | 87 --------------- .../cmstools/client/ClientImportCertCLI.java | 122 --------------------- .../cmstools/client/ClientRemoveCertCLI.java | 68 ------------ 7 files changed, 280 insertions(+), 280 deletions(-) create mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientCertFindCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientCertImportCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientCertRemoveCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientFindCertCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientImportCertCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/client/ClientRemoveCertCLI.java (limited to 'base/java-tools') diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientCLI.java index c22786150..fe0d001ac 100644 --- a/base/java-tools/src/com/netscape/cmstools/client/ClientCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/client/ClientCLI.java @@ -32,9 +32,9 @@ public class ClientCLI extends CLI { public ClientCLI(CLI parent) { super("client", "Client management commands", parent); - addModule(new ClientFindCertCLI(this)); - addModule(new ClientImportCertCLI(this)); - addModule(new ClientRemoveCertCLI(this)); + addModule(new ClientCertFindCLI(this)); + addModule(new ClientCertImportCLI(this)); + addModule(new ClientCertRemoveCLI(this)); } public String getFullName() { diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientCertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientCertFindCLI.java new file mode 100644 index 000000000..874a897a5 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/client/ClientCertFindCLI.java @@ -0,0 +1,87 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.client; + +import org.apache.commons.cli.CommandLine; +import org.mozilla.jss.crypto.X509Certificate; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ClientCertFindCLI extends CLI { + + public ClientCLI clientCLI; + + public ClientCertFindCLI(ClientCLI clientCLI) { + super("cert-find", "Find certificates in client security database", clientCLI); + this.clientCLI = clientCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS]", options); + } + + public void execute(String[] args) throws Exception { + + options.addOption(null, "ca", false, "Find CA certificates only"); + + CommandLine cmd = null; + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + client = parent.getClient(); + + X509Certificate[] certs; + if (cmd.hasOption("ca")) { + certs = client.getCACerts(); + } else { + certs = client.getCerts(); + } + + if (certs == null || certs.length == 0) { + MainCLI.printMessage("No certificates found"); + System.exit(0); // valid result + } + + MainCLI.printMessage(certs.length + " certificate(s) found"); + + boolean first = true; + + for (X509Certificate cert : certs) { + if (first) { + first = false; + } else { + System.out.println(); + } + + ClientCLI.printCertInfo(cert); + } + + MainCLI.printMessage("Number of entries returned " + certs.length); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientCertImportCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientCertImportCLI.java new file mode 100644 index 000000000..1ced6727f --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/client/ClientCertImportCLI.java @@ -0,0 +1,122 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.client; + +import java.io.File; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.io.FileUtils; +import org.mozilla.jss.crypto.X509Certificate; + +import com.netscape.certsrv.client.ClientConfig; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ClientCertImportCLI extends CLI { + + public ClientCLI clientCLI; + + public ClientCertImportCLI(ClientCLI clientCLI) { + super("cert-import", "Import certificate into client security database", clientCLI); + this.clientCLI = clientCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "cert", true, "Import certificate file"); + option.setArgName("path"); + options.addOption(option); + + option = new Option(null, "ca-cert", true, "Import CA certificate file"); + option.setArgName("path"); + options.addOption(option); + + options.addOption(null, "ca-server", false, "Import CA certificate from CA server"); + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + client = parent.getClient(); + + byte[] bytes = null; + X509Certificate cert = null; + + String certPath = cmd.getOptionValue("cert"); + String caCertPath = cmd.getOptionValue("ca-cert"); + boolean importFromCAServer = cmd.hasOption("ca-server"); + + boolean isCACert = false; + + // load the certificate + if (certPath != null) { + if (verbose) System.out.println("Loading certificate from " + certPath + "."); + bytes = FileUtils.readFileToByteArray(new File(certPath)); + + + } else if (caCertPath != null) { + if (verbose) System.out.println("Loading CA certificate from " + caCertPath + "."); + bytes = FileUtils.readFileToByteArray(new File(caCertPath)); + + isCACert = true; + + } else if (importFromCAServer) { + ClientConfig config = client.getConfig(); + String caServerURI = "http://" + config.getServerURI().getHost() + ":8080/ca"; + + if (verbose) System.out.println("Downloading CA certificate from " + caServerURI + "."); + bytes = client.downloadCACertChain(caServerURI); + + isCACert = true; + + } else { + System.err.println("Error: Missing certificate to import"); + printHelp(); + System.exit(1); + } + + // import the certificate + if (isCACert) { + if (verbose) System.out.println("Importing CA certificate."); + cert = client.importCACertPackage(bytes); + + } else { + if (verbose) System.out.println("Importing certificate."); + cert = client.importCertPackage(bytes, client.config.getCertNickname()); + } + + MainCLI.printMessage("Imported certificate \"" + cert.getNickname() + "\""); + ClientCLI.printCertInfo(cert); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientCertRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientCertRemoveCLI.java new file mode 100644 index 000000000..7549647be --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/client/ClientCertRemoveCLI.java @@ -0,0 +1,68 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.client; + +import org.apache.commons.cli.CommandLine; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ClientCertRemoveCLI extends CLI { + + public ClientCLI clientCLI; + + public ClientCertRemoveCLI(ClientCLI clientCLI) { + super("cert-remove", "Remove certificate from client security database", clientCLI); + this.clientCLI = clientCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + + CommandLine cmd = null; + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 1) { + printHelp(); + System.exit(1); + } + + client = parent.getClient(); + + String nickname = cmdArgs[0]; + client.removeCert(nickname); + + MainCLI.printMessage("Removed certificate \"" + nickname + "\""); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientFindCertCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientFindCertCLI.java deleted file mode 100644 index f4057c67a..000000000 --- a/base/java-tools/src/com/netscape/cmstools/client/ClientFindCertCLI.java +++ /dev/null @@ -1,87 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.client; - -import org.apache.commons.cli.CommandLine; -import org.mozilla.jss.crypto.X509Certificate; - -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ClientFindCertCLI extends CLI { - - public ClientCLI clientCLI; - - public ClientFindCertCLI(ClientCLI clientCLI) { - super("find-cert", "Find certificates in client security database", clientCLI); - this.clientCLI = clientCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS]", options); - } - - public void execute(String[] args) throws Exception { - - client = clientCLI.getClient(); - - options.addOption(null, "ca", false, "Find CA certificates only"); - - CommandLine cmd = null; - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(1); - } - - X509Certificate[] certs; - if (cmd.hasOption("ca")) { - certs = client.getCACerts(); - } else { - certs = client.getCerts(); - } - - if (certs == null || certs.length == 0) { - MainCLI.printMessage("No certificates found"); - System.exit(0); // valid result - } - - MainCLI.printMessage(certs.length + " certificate(s) found"); - - boolean first = true; - - for (X509Certificate cert : certs) { - if (first) { - first = false; - } else { - System.out.println(); - } - - ClientCLI.printCertInfo(cert); - } - - MainCLI.printMessage("Number of entries returned " + certs.length); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientImportCertCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientImportCertCLI.java deleted file mode 100644 index cbd55079a..000000000 --- a/base/java-tools/src/com/netscape/cmstools/client/ClientImportCertCLI.java +++ /dev/null @@ -1,122 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.client; - -import java.io.File; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.io.FileUtils; -import org.mozilla.jss.crypto.X509Certificate; - -import com.netscape.certsrv.client.ClientConfig; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ClientImportCertCLI extends CLI { - - public ClientCLI clientCLI; - - public ClientImportCertCLI(ClientCLI clientCLI) { - super("import-cert", "Import certificate into client security database", clientCLI); - this.clientCLI = clientCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS]", options); - } - - public void execute(String[] args) throws Exception { - - client = clientCLI.getClient(); - - Option option = new Option(null, "cert", true, "Import certificate file"); - option.setArgName("path"); - options.addOption(option); - - option = new Option(null, "ca-cert", true, "Import CA certificate file"); - option.setArgName("path"); - options.addOption(option); - - options.addOption(null, "ca-server", false, "Import CA certificate from CA server"); - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(1); - } - - byte[] bytes = null; - X509Certificate cert = null; - - String certPath = cmd.getOptionValue("cert"); - String caCertPath = cmd.getOptionValue("ca-cert"); - boolean importFromCAServer = cmd.hasOption("ca-server"); - - boolean isCACert = false; - - // load the certificate - if (certPath != null) { - if (verbose) System.out.println("Loading certificate from " + certPath + "."); - bytes = FileUtils.readFileToByteArray(new File(certPath)); - - - } else if (caCertPath != null) { - if (verbose) System.out.println("Loading CA certificate from " + caCertPath + "."); - bytes = FileUtils.readFileToByteArray(new File(caCertPath)); - - isCACert = true; - - } else if (importFromCAServer) { - ClientConfig config = client.getConfig(); - String caServerURI = "http://" + config.getServerURI().getHost() + ":8080/ca"; - - if (verbose) System.out.println("Downloading CA certificate from " + caServerURI + "."); - bytes = client.downloadCACertChain(caServerURI); - - isCACert = true; - - } else { - System.err.println("Error: Missing certificate to import"); - printHelp(); - System.exit(1); - } - - // import the certificate - if (isCACert) { - if (verbose) System.out.println("Importing CA certificate."); - cert = client.importCACertPackage(bytes); - - } else { - if (verbose) System.out.println("Importing certificate."); - cert = client.importCertPackage(bytes, client.config.getCertNickname()); - } - - MainCLI.printMessage("Imported certificate \"" + cert.getNickname() + "\""); - ClientCLI.printCertInfo(cert); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/client/ClientRemoveCertCLI.java b/base/java-tools/src/com/netscape/cmstools/client/ClientRemoveCertCLI.java deleted file mode 100644 index be4456115..000000000 --- a/base/java-tools/src/com/netscape/cmstools/client/ClientRemoveCertCLI.java +++ /dev/null @@ -1,68 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.client; - -import org.apache.commons.cli.CommandLine; - -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ClientRemoveCertCLI extends CLI { - - public ClientCLI clientCLI; - - public ClientRemoveCertCLI(ClientCLI clientCLI) { - super("remove-cert", "Remove certificate from client security database", clientCLI); - this.clientCLI = clientCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " ", options); - } - - public void execute(String[] args) throws Exception { - - CommandLine cmd = null; - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(1); - } - - String[] cmdArgs = cmd.getArgs(); - - if (cmdArgs.length != 1) { - printHelp(); - System.exit(1); - } - - client = clientCLI.getClient(); - - String nickname = cmdArgs[0]; - client.removeCert(nickname); - - MainCLI.printMessage("Removed certificate \"" + nickname + "\""); - } -} -- cgit