|
From: <pe...@us...> - 2003-12-19 18:03:38
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline
In directory sc8-pr-cvs1:/tmp/cvs-serv5310/src/java/org/neuclear/id/tools/commandline
Modified Files:
CommandLineSigner.java IdentityCreator.java
Log Message:
Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
- For most cases the main exception to worry about now is InvalidNamedObjectException.
- Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
runtime exception.
- Source and Store patterns each now have their own exceptions that generalizes the various physical
exceptions that can happen in that area.
Index: CommandLineSigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline/CommandLineSigner.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CommandLineSigner.java 19 Dec 2003 00:31:30 -0000 1.5
--- CommandLineSigner.java 19 Dec 2003 18:03:34 -0000 1.6
***************
*** 1,4 ****
--- 1,12 ----
/* $Id$
* $Log$
+ * Revision 1.6 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.5 2003/12/19 00:31:30 pelle
* Lots of usability changes through out all the passphrase agents and end user tools.
***************
*** 199,202 ****
--- 207,211 ----
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.Utility;
+ import org.neuclear.commons.LowLevelException;
import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.commons.crypto.passphraseagents.ConsoleAgent;
***************
*** 207,210 ****
--- 216,220 ----
import org.neuclear.commons.crypto.signers.Signer;
import org.neuclear.commons.crypto.signers.InvalidPassphraseException;
+ import org.neuclear.commons.crypto.signers.NonExistingSignerException;
import org.neuclear.commons.time.TimeTools;
import org.neuclear.id.Identity;
***************
*** 231,235 ****
private final String EXECUTABLE ;
! public CommandLineSigner(final String[] args) throws ParseException, UserCancellationException {
CryptoTools.ensureProvider();
EXECUTABLE=Utility.getExecutable(getClass());
--- 241,245 ----
private final String EXECUTABLE ;
! public CommandLineSigner(final String[] args) throws UserCancellationException {
CryptoTools.ensureProvider();
EXECUTABLE=Utility.getExecutable(getClass());
***************
*** 267,275 ****
}
! private final CommandLine parseOptions(final String[] args) throws ParseException {
! final CommandLineParser clparser = CommandLineParserFactory.newParser();
try {
return clparser.parse(options, args);
! } catch (UnrecognizedOptionException e) {
System.out.println(e.getLocalizedMessage());
printHelp();
--- 277,285 ----
}
! private final CommandLine parseOptions(final String[] args) {
! final CommandLineParser clparser = new GnuParser();
try {
return clparser.parse(options, args);
! } catch (ParseException e) {
System.out.println(e.getLocalizedMessage());
printHelp();
***************
*** 308,312 ****
private void printHelp() {
final HelpFormatter help = new HelpFormatter();
!
help.printHelp("\n"+EXECUTABLE +getExtraHelp()+
" [--outputfile signed/test.id] \n" +
--- 318,322 ----
private void printHelp() {
final HelpFormatter help = new HelpFormatter();
! help.setDescPadding(10);
help.printHelp("\n"+EXECUTABLE +getExtraHelp()+
" [--outputfile signed/test.id] \n" +
***************
*** 323,331 ****
}
! public final void execute() {
!
! try {
final NamedObjectBuilder subject = build();
if (!sig.canSignFor(alias)) {
if (!Utility.isEmpty(of))
--- 333,340 ----
}
! public final void execute() throws UserCancellationException {
final NamedObjectBuilder subject = build();
+ try {
if (!sig.canSignFor(alias)) {
if (!Utility.isEmpty(of))
***************
*** 367,379 ****
}
*/
! } catch (Exception e) {
! System.err.println(e.getMessage());
! e.printStackTrace(System.err);
}
}
! protected NamedObjectBuilder build() throws Exception {
final String sf = cmd.getOptionValue("i");
try {
InputStream source = System.in;
--- 376,396 ----
}
*/
! } catch (InvalidNamedObjectException e) {
! throw new LowLevelException(e);
! } catch (NonExistingSignerException e) {
! throw new LowLevelException(e);
! } catch (FileNotFoundException e) {
! System.err.println("Couldnt find file: " + of);
! System.exit(1);
! } catch (XMLException e) {
! System.err.println("Error generatoing xml file: " + of + "\n" + e.getLocalizedMessage());
! System.exit(1);
}
}
! protected NamedObjectBuilder build() throws UserCancellationException {
final String sf = cmd.getOptionValue("i");
+ NamedObjectBuilder subject=null;
try {
InputStream source = System.in;
***************
*** 386,394 ****
}
final Document doc = XMLTools.loadDocument(source);
! final NamedObjectBuilder subject = new NamedObjectBuilder(doc);
if (Utility.isEmpty(alias)) {
alias = Utility.denullString(NSTools.isHttpScheme(subject.getName()), NSTools.getSignatoryURI(subject.getName()));
-
}
if (!sig.canSignFor(alias)) {
--- 403,410 ----
}
final Document doc = XMLTools.loadDocument(source);
! subject = new NamedObjectBuilder(doc);
if (Utility.isEmpty(alias)) {
alias = Utility.denullString(NSTools.isHttpScheme(subject.getName()), NSTools.getSignatoryURI(subject.getName()));
}
if (!sig.canSignFor(alias)) {
***************
*** 403,408 ****
System.out.println(subject.asXML());
System.out.print("===================\nAre you shure you wish to sign this? (y/N) ");
! String answer = new jline.ConsoleReader().readLine();
! if (!answer.toLowerCase().equals("y")) {
System.out.println("Aborted Signing Process");
System.exit(0);
--- 419,424 ----
System.out.println(subject.asXML());
System.out.print("===================\nAre you shure you wish to sign this? (y/N) ");
!
! if (!Utility.getAffirmative(false)) {
System.out.println("Aborted Signing Process");
System.exit(0);
***************
*** 410,413 ****
--- 426,432 ----
return subject;
+ } catch (InvalidNamedObjectException e) {
+ System.err.println("The name: "+e.getName()+" is not valid. \nplease check the xml attribute \"neuid:name\" in the xml element: "+ subject.getElement().getQualifiedName()+" in your input file: "+sf);
+ System.exit(1);
} catch (FileNotFoundException e) {
System.err.println("Couldnt find file: " + sf);
***************
*** 423,432 ****
// create Options object
final Options options = new Options();
!
! options.addOption("o", "outputfile", true, "specify output file \n[ --outputfile bob.id ]");
! options.addOption("i", "inputfile", true, "specify Input File \n[ --inputfile bob.xml ]");
! options.addOption("v", "verify", true, "Specify NEU ID to verify \n[ --verify neu://bob@yourdomain.com ]");
! options.addOption("h","help",false,"Help");
! options.addOption("g","gui",false,"Use GUI Passphrase Dialog");
getLocalOptions(options);
--- 442,450 ----
// create Options object
final Options options = new Options();
! options.addOption(new Option("o", "outputfile", true, "specify output file \n[ --outputfile bob.id ]"));
! options.addOption(new Option("i", "inputfile", true, "specify Input File \n[ --inputfile bob.xml ]"));
! options.addOption(new Option("v", "verify", true, "Specify NEU ID to verify \n[ --verify neu://bob@yourdomain.com ]"));
! options.addOption(new Option("h","help",false,"Help"));
! options.addOption(new Option("g","gui",false,"Use GUI Passphrase Dialog"));
getLocalOptions(options);
Index: IdentityCreator.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline/IdentityCreator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** IdentityCreator.java 19 Dec 2003 00:31:30 -0000 1.5
--- IdentityCreator.java 19 Dec 2003 18:03:34 -0000 1.6
***************
*** 1,4 ****
--- 1,12 ----
/* $Id$
* $Log$
+ * Revision 1.6 2003/12/19 18:03:34 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.5 2003/12/19 00:31:30 pelle
* Lots of usability changes through out all the passphrase agents and end user tools.
***************
*** 202,205 ****
--- 210,215 ----
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+ import org.apache.commons.cli.Option;
+ import org.apache.commons.cli.OptionGroup;
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.Utility;
***************
*** 238,242 ****
}
! public final NamedObjectBuilder build() throws Exception {
NamedObjectBuilder subject = null;
if (cmd.hasOption('i')) {//If we have an input file we load that instead of creating a new one
--- 248,252 ----
}
! protected NamedObjectBuilder build() throws UserCancellationException {
NamedObjectBuilder subject = null;
if (cmd.hasOption('i')) {//If we have an input file we load that instead of creating a new one
***************
*** 244,275 ****
identity = subject.getName();
}
! String store = NSTools.isHttpScheme(identity);
! boolean isTopLevel = !Utility.isEmpty(store);
! if (!isTopLevel) {
! // If this isn't a top level we will derive the repository from its parent.
! store = NSTools.isHttpScheme(NSTools.getSignatoryURI(identity));
! }
! alias = (isTopLevel) ? identity : NSTools.getSignatoryURI(identity);
! final String defaultstore = Utility.denullString(cmd.getOptionValue("r"), store);
! final String defaultsigner = Utility.denullString(cmd.getOptionValue("s"), "http://localhost:11870/Signer");
! final String defaultlogger = Utility.denullString(cmd.getOptionValue("l"), LogSender.LOGGER);
! final String defaultreceiver = cmd.getOptionValue("b");
! if (!sig.canSignFor(identity)){
! System.out.println("You do not currently have a key matching this name. Do you with to create one?");
! if (!Utility.getAffirmative(true)) {
! System.out.println("OK, Bye");
! System.exit(0);
}
! System.out.println("Generating Keys for "+identity+"... ");
! PublicKey pub=sig.generateKey(identity);
! System.out.println("DONE");
! System.out.println("STORING Keys");
! sig.save();
}
! final PublicKey newkid = pksource.getPublicKey(identity);
! if (newkid == null)
! throw new CryptoException("PublicKey not available for: " + identity);
! return new IdentityBuilder(identity, newkid, defaultstore, defaultsigner, defaultlogger, defaultreceiver);
}
--- 254,290 ----
identity = subject.getName();
}
! try {
! String store = NSTools.isHttpScheme(identity);
! boolean isTopLevel = !Utility.isEmpty(store);
! if (!isTopLevel) {
! // If this isn't a top level we will derive the repository from its parent.
! store = NSTools.isHttpScheme(NSTools.getSignatoryURI(identity));
}
! alias = (isTopLevel) ? identity : NSTools.getSignatoryURI(identity);
! final String defaultstore = Utility.denullString(cmd.getOptionValue("r"), store);
! final String defaultsigner = Utility.denullString(cmd.getOptionValue("s"), "http://localhost:11870/Signer");
! final String defaultlogger = Utility.denullString(cmd.getOptionValue("l"), LogSender.LOGGER);
! final String defaultreceiver = cmd.getOptionValue("b");
! if (!sig.canSignFor(identity)){
! System.out.println("You do not currently have a key matching this name. Do you with to create one?");
! if (!Utility.getAffirmative(true)) {
! System.out.println("OK, Bye");
! System.exit(0);
! }
! System.out.println("Generating Keys for "+identity+"... ");
! PublicKey pub=sig.generateKey(identity);
! System.out.println("DONE");
! System.out.println("STORING Keys");
! sig.save();
!
! }
! final PublicKey newkid = pksource.getPublicKey(identity);
+ return new IdentityBuilder(identity, newkid, defaultstore, defaultsigner, defaultlogger, defaultreceiver);
+ } catch (InvalidNamedObjectException e) {
+ System.err.println("The name: "+e.getName()+" is not valid. ");
+ System.exit(1);
}
! return null;
}
***************
*** 295,303 ****
protected final void getLocalOptions(final Options options) {
! options.addOption("n", "name", true, "specify name of new Identity \n[ --name neu://bob@yourdomain.com ]");
! options.addOption("r", "repository", true, "Identity's default Repository \n[ --repository http://repository.neuclear.org ] ");
! options.addOption("s", "signer", true, "Identity's default Interactive Signer \n[ --signer http://localhost:11870 ]");
! options.addOption("l", "logger", true, "Identity's default Logging Service \n[ --logger http://logger.neuclear.org ]");
! options.addOption("b", "receiver", true, "Identity's default Receiver \n[ --receiver mailto:bo...@yo... ]");
}
--- 310,318 ----
protected final void getLocalOptions(final Options options) {
! options.addOption(new Option("n", "name", true, "specify name of new Identity \n[ --name neu://bob@yourdomain.com ]"));
! options.addOption(new Option("r", "repository", true, "Identity's default Repository \n[ --repository http://repository.neuclear.org ] "));
! options.addOption(new Option("s", "signer", true, "Identity's default Interactive Signer \n[ --signer http://localhost:11870 ]"));
! options.addOption(new Option("l", "logger", true, "Identity's default Logging Service \n[ --logger http://logger.neuclear.org ]"));
! options.addOption(new Option("b", "receiver", true, "Identity's default Receiver \n[ --receiver mailto:bo...@yo... ]"));
}
|