Skip to content

Commit

Permalink
Prep for 0.4.0
Browse files Browse the repository at this point in the history
CHANGE: Main.java: -n takes an argument and is mutually exclusive with -f. -n creates a new file while -f reads an existing file
  • Loading branch information
alastair.mccormack@gmail.com committed Jan 17, 2013
1 parent 3b2ada1 commit 8a88814
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.mccnet</groupId>
<artifactId>keyutil</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
Expand Down
4 changes: 2 additions & 2 deletions rpmbuild/SPECS/keyutil.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: keyutil
Version: 0.3.0
Release: 2
Version: 0.4.0
Release: 1
Summary: Java Key Utility
Group: Applications/System
License: BSD
Expand Down
1 change: 0 additions & 1 deletion src/uk/co/mccnet/keyutil/JKSKeyStoreUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.logging.Logger;
Expand Down
39 changes: 24 additions & 15 deletions src/uk/co/mccnet/keyutil/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ public static void main(String[] args) throws Exception {

Options options = new Options();
options.addOption("h", "help", false, "Show help");
options.addOption("F", "force", false, "Force actions");
options.addOption("n", "new", false, "Create new Java Keystore");
options.addOption("F", "force-new-overwrite", false, "force overwrite of existing keystore");

Option passwordOption = new Option("p", "password", true, "Keystore (secret) password");
passwordOption.setRequired(true);
options.addOption(passwordOption);

Option fileOption = new Option("f", "keystore-file", true, "Output keystore filename");
fileOption.setRequired(true);
fileOption.setArgName("keystore");
options.addOption(fileOption);
OptionGroup ogDestination = new OptionGroup();
Option newDestinationFileOption = new Option("n", "new-keystore", true, "Append to new output JSK keystore filename");
newDestinationFileOption.setArgName("jks_file");
Option existingFileOption = new Option("f", "keystore-file", true, "Append to existing output JKS keystore filename");
existingFileOption.setArgName("jks_file");
ogDestination.addOption(newDestinationFileOption);
ogDestination.addOption(existingFileOption);
options.addOptionGroup(ogDestination);

OptionGroup ogLogging = new OptionGroup();
ogLogging.addOption(new Option("q", "quiet", false, "Quiet"));
Expand All @@ -58,6 +61,7 @@ public static void main(String[] args) throws Exception {
ogMode.setRequired(true);
ogMode.addOption(new Option("l", "list", false, "List cert mode"));
ogMode.addOption(new Option("i", "import", false, "Import certs mode"));
ogMode.addOption(new Option("h", "help", false, "Show help"));
options.addOptionGroup(ogMode);

Option pemFileOption = new Option("e", "import-pem-file", true, "PEM import filenames");
Expand Down Expand Up @@ -97,19 +101,24 @@ public static void main(String[] args) throws Exception {
} else if (line.hasOption("debug")) {
logger.setLevel(Level.FINEST);
}

File keyStore = new File(line.getOptionValue("keystore-file"));
String password = line.getOptionValue("password");

File keyStore;

if ( line.hasOption("new") && keyStore.exists() && ! line.hasOption("force")) {
throw new Exception("New Keystore - File already exists. Use --force to overwrite");
} else if (! line.hasOption("new") && ! keyStore.exists()) {
throw new Exception(String.format("%s does not exist. Create it with --new.", keyStore.getPath()));
}
if ( line.hasOption("new-keystore") ) {
keyStore = new File(line.getOptionValue("new-keystore"));
if ( keyStore.exists() && ! line.hasOption("force-new-overwrite") ) {
throw new Exception("New Keystore - File already exists. Use --force-new-overwrite to overwrite");
}
} else {
// Option parsing should ensure line.hasOption("keystore-file") == True
keyStore = new File(line.getOptionValue("keystore-file") );
}

String password = line.getOptionValue("password");

JKSKeyStoreUtil jksKeyStoreUtil;

if (line.hasOption("new") ) {
if (line.hasOption("new-keystore") ) {
jksKeyStoreUtil = new JKSKeyStoreUtil();
} else {
// load existing
Expand Down

0 comments on commit 8a88814

Please sign in to comment.