From 9a2f79f9fb4dce130d1495450e7a680e04648626 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 29 Sep 2015 11:17:21 -0400 Subject: Lightweight CAs: implement deletion API and CLI Implement lightweight authority deletion including CLI command. To be deleted an authority must be disabled and have no sub-CAs. Fixes: https://fedorahosted.org/pki/ticket/1324 --- .../netscape/cmstools/authority/AuthorityCLI.java | 1 + .../cmstools/authority/AuthorityRemoveCLI.java | 72 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 base/java-tools/src/com/netscape/cmstools/authority/AuthorityRemoveCLI.java (limited to 'base/java-tools/src/com') diff --git a/base/java-tools/src/com/netscape/cmstools/authority/AuthorityCLI.java b/base/java-tools/src/com/netscape/cmstools/authority/AuthorityCLI.java index 99d38ad1b..4fbcfef76 100644 --- a/base/java-tools/src/com/netscape/cmstools/authority/AuthorityCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/authority/AuthorityCLI.java @@ -17,6 +17,7 @@ public class AuthorityCLI extends CLI { addModule(new AuthorityCreateCLI(this)); addModule(new AuthorityDisableCLI(this)); addModule(new AuthorityEnableCLI(this)); + addModule(new AuthorityRemoveCLI(this)); } public String getFullName() { diff --git a/base/java-tools/src/com/netscape/cmstools/authority/AuthorityRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/authority/AuthorityRemoveCLI.java new file mode 100644 index 000000000..42265b180 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/authority/AuthorityRemoveCLI.java @@ -0,0 +1,72 @@ +package com.netscape.cmstools.authority; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.ParseException; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +public class AuthorityRemoveCLI extends CLI { + + public AuthorityCLI authorityCLI; + + public AuthorityRemoveCLI(AuthorityCLI authorityCLI) { + super("del", "Delete Authority", authorityCLI); + this.authorityCLI = authorityCLI; + + options.addOption(null, "force", false, "Force delete"); + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + } catch (ParseException e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + if (cmdArgs.length != 1) { + if (cmdArgs.length < 1) + System.err.println("No ID specified."); + else + System.err.println("Too many arguments."); + printHelp(); + System.exit(-1); + } + + if (!cmd.hasOption("force")) { + System.out.print("Are you sure (Y/N)? "); + System.out.flush(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String line = reader.readLine(); + if (!line.equalsIgnoreCase("Y")) { + System.exit(-1); + } + } + + String aidString = cmdArgs[0]; + authorityCLI.authorityClient.deleteCA(aidString); + MainCLI.printMessage("Deleted authority \"" + aidString + "\""); + } + +} -- cgit