|
From: <pe...@us...> - 2003-12-19 00:31:34
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline
In directory sc8-pr-cvs1:/tmp/cvs-serv19108/src/java/org/neuclear/id/tools/commandline
Modified Files:
BuildAllTopLevel.java CommandLineSigner.java
IdentityCreator.java
Log Message:
Lots of usability changes through out all the passphrase agents and end user tools.
Index: BuildAllTopLevel.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline/BuildAllTopLevel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** BuildAllTopLevel.java 12 Dec 2003 21:13:16 -0000 1.2
--- BuildAllTopLevel.java 19 Dec 2003 00:31:30 -0000 1.3
***************
*** 33,36 ****
--- 33,39 ----
$Id$
$Log$
+ Revision 1.3 2003/12/19 00:31:30 pelle
+ Lots of usability changes through out all the passphrase agents and end user tools.
+
Revision 1.2 2003/12/12 21:13:16 pelle
I have now done manual testing of the SigningServlet et al and am happy releasing it to 0.8
***************
*** 93,103 ****
store.receive(createIdentities("neu://alice@test", testsig, testsig));
! } catch (NeuClearException e) {
! e.printStackTrace();
! } catch (GeneralSecurityException e) {
! e.printStackTrace();
! } catch (FileNotFoundException e) {
! e.printStackTrace();
! } catch (XMLException e) {
e.printStackTrace();
}
--- 96,100 ----
store.receive(createIdentities("neu://alice@test", testsig, testsig));
! } catch (Exception e) {
e.printStackTrace();
}
Index: CommandLineSigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline/CommandLineSigner.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CommandLineSigner.java 18 Dec 2003 17:40:19 -0000 1.4
--- CommandLineSigner.java 19 Dec 2003 00:31:30 -0000 1.5
***************
*** 1,4 ****
--- 1,7 ----
/* $Id$
* $Log$
+ * Revision 1.5 2003/12/19 00:31:30 pelle
+ * Lots of usability changes through out all the passphrase agents and end user tools.
+ *
* Revision 1.4 2003/12/18 17:40:19 pelle
* You can now create keys that get stored with a X509 certificate in the keystore. These can be saved as well.
***************
*** 197,206 ****
import org.neuclear.commons.Utility;
import org.neuclear.commons.crypto.CryptoTools;
! import org.neuclear.commons.crypto.passphraseagents.CommandLineAgent;
import org.neuclear.commons.crypto.signers.DefaultSigner;
import org.neuclear.commons.crypto.signers.Signer;
import org.neuclear.commons.time.TimeTools;
import org.neuclear.id.Identity;
import org.neuclear.id.NSTools;
import org.neuclear.id.builders.NamedObjectBuilder;
import org.neuclear.id.resolver.NSResolver;
--- 200,215 ----
import org.neuclear.commons.Utility;
import org.neuclear.commons.crypto.CryptoTools;
! import org.neuclear.commons.crypto.passphraseagents.ConsoleAgent;
! import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
! import org.neuclear.commons.crypto.passphraseagents.InteractiveAgent;
! import org.neuclear.commons.crypto.passphraseagents.GuiDialogAgent;
import org.neuclear.commons.crypto.signers.DefaultSigner;
import org.neuclear.commons.crypto.signers.Signer;
+ import org.neuclear.commons.crypto.signers.InvalidPassphraseException;
import org.neuclear.commons.time.TimeTools;
import org.neuclear.id.Identity;
import org.neuclear.id.NSTools;
+ import org.neuclear.id.InvalidNamedObjectException;
+ import org.neuclear.id.NameResolutionException;
import org.neuclear.id.builders.NamedObjectBuilder;
import org.neuclear.id.resolver.NSResolver;
***************
*** 210,213 ****
--- 219,226 ----
import java.io.*;
import java.security.GeneralSecurityException;
+ import java.net.URLClassLoader;
+ import java.net.URL;
+ import java.util.regex.Pattern;
+ import java.util.regex.Matcher;
/**
***************
*** 216,226 ****
*/
public class CommandLineSigner {
! public CommandLineSigner(final String[] args) throws ParseException, FileNotFoundException, GeneralSecurityException, NeuClearException {
! CryptoTools.ensureProvider();
options = createOptions();
! final CommandLineParser clparser = CommandLineParserFactory.newParser();
!
! cmd = clparser.parse(options, args);
checkArguments();
if (cmd.hasOption('v')) {
--- 229,239 ----
*/
public class CommandLineSigner {
! private final String EXECUTABLE ;
+ public CommandLineSigner(final String[] args) throws ParseException, UserCancellationException {
+ CryptoTools.ensureProvider();
+ EXECUTABLE=Utility.getExecutable(getClass());
options = createOptions();
! cmd=parseOptions(args);
checkArguments();
if (cmd.hasOption('v')) {
***************
*** 245,249 ****
}
// agent=(PassPhraseAgent)Configuration.getComponent(PassPhraseAgent.class,"neuclear-id");
! sig = new DefaultSigner(new CommandLineAgent());
alias = cmd.getOptionValue("a");
of = cmd.getOptionValue("o");
--- 258,263 ----
}
// agent=(PassPhraseAgent)Configuration.getComponent(PassPhraseAgent.class,"neuclear-id");
! final InteractiveAgent agent = cmd.hasOption('g')?(InteractiveAgent)new GuiDialogAgent():new ConsoleAgent();
! sig = createSigner(agent);
alias = cmd.getOptionValue("a");
of = cmd.getOptionValue("o");
***************
*** 253,260 ****
--- 267,297 ----
}
+ 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();
+ System.exit(1);
+ }
+ return null;
+ }
+
+ private DefaultSigner createSigner(final InteractiveAgent agent) throws UserCancellationException {
+ try {
+ return new DefaultSigner(agent);
+ } catch (InvalidPassphraseException e) {
+ return createSigner(agent);
+ }
+ }
+
public static void main(final String[] args) {
try {
+ System.out.println();
final CommandLineSigner signer = new CommandLineSigner(args);
signer.execute();
+ } catch (UserCancellationException e){
+ System.out.println("Bye");
} catch (Exception e) {
e.printStackTrace();
***************
*** 263,275 ****
public final void checkArguments() {
! if (!hasArguments()) {
! final HelpFormatter help = new HelpFormatter();
! help.printHelp("java " +
! this.getClass().getName() +
! getExtraHelp() + " [--outputfile signed/test.id] ", options);
System.exit(1);
}
}
protected String getExtraHelp() {
return " --inputfile unsigned/test.id";
--- 300,318 ----
public final void checkArguments() {
! if (!hasArguments()||cmd.hasOption('h')) {
! printHelp();
System.exit(1);
}
}
+ private void printHelp() {
+ final HelpFormatter help = new HelpFormatter();
+
+ help.printHelp("\n"+EXECUTABLE +getExtraHelp()+
+ " [--outputfile signed/test.id] \n" +
+ EXECUTABLE+" --verify neu://neuclear.org\n" +
+ EXECUTABLE+" --inputfile jo...@yo... \n" , options);
+ }
+
protected String getExtraHelp() {
return " --inputfile unsigned/test.id";
***************
*** 288,294 ****
if (!Utility.isEmpty(of))
of = subject.getLocalName() + ".xml";
! System.err.println("Key with alias: " + alias + " doesnt exist in our keystore. \nSaving unsigned Identity as: " + of);
} else if(!subject.isSigned()) {
! System.err.println("Signing by " + alias + " ...");
subject.sign(alias, sig);
}
--- 331,337 ----
if (!Utility.isEmpty(of))
of = subject.getLocalName() + ".xml";
! System.out.println("Key with alias: " + alias + " doesnt exist in our keystore. \nSaving unsigned Identity as: " + of);
} else if(!subject.isSigned()) {
! System.out.println("Signing by " + alias + " ...");
subject.sign(alias, sig);
}
***************
*** 300,307 ****
outFile.getParentFile().mkdirs();
dest = new FileOutputStream(of);
! System.err.println("Outputting to: " + of);
}
XMLTools.writeFile(dest, subject.getElement());
System.out.println();
} catch (Exception e) {
System.err.println(e.getMessage());
--- 343,370 ----
outFile.getParentFile().mkdirs();
dest = new FileOutputStream(of);
! System.out.println("Outputting to: " + of);
}
XMLTools.writeFile(dest, subject.getElement());
System.out.println();
+ System.out.println("You now need to copy the file: "+of+ " to your webserver so it is visible at the following location:\n" +
+ NSTools.getRepositoryURL(alias)+NSTools.name2path(subject.getName())+"root.id");
+
+ System.out.println("\nOnce this is done you will be able to verify your new Identity like this:");
+ System.out.println(EXECUTABLE+" -v "+subject.getName());
+ /* We need to be able to send an unsigned object before I can enable this
+ if (!sig.canSignFor(alias)) {
+ System.out.println("Do you wish to send the contract to the signer of "+alias+"?");
+ if (Utility.getAffirmative(true)){
+ try {
+ Identity id=NSResolver.resolveIdentity(alias);
+ id.receive(subject);
+ } catch (NameResolutionException e) {
+ System.err.println(e.getLocalizedMessage());
+ } catch (InvalidNamedObjectException e) {
+ System.err.println(e.getLocalizedMessage());
+ }
+ }
+ }
+ */
} catch (Exception e) {
System.err.println(e.getMessage());
***************
*** 361,374 ****
final Options options = new Options();
! // add t option
! // options.addOption("s", "keystore", true, "specify KeyStore");
! // options.addOption("t", "keystoretype", true, "specify KeyStore Type");
! // options.addOption("j", "keystorepassword", true, "specify KeyStore Password");
! // options.addOption("a", "alias", true, "specify Key Alias in KeyStore");
! // options.addOption("p", "password", true, "specify Alias Password");
! options.addOption("o", "outputfile", true, "specify Output File");
! options.addOption("i", "inputfile", true, "specify Input File");
! options.addOption("v", "verify", true, "Specify NEU ID to verify");
!
getLocalOptions(options);
--- 424,432 ----
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);
***************
*** 382,388 ****
protected final CommandLine cmd;
protected final Options options;
- public final static String keystore = System.getProperty("user.home") + "/.keystore";
protected final Signer sig;
- // protected final PassPhraseAgent agent;
protected String alias;
protected String of;
--- 440,444 ----
Index: IdentityCreator.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/tools/commandline/IdentityCreator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** IdentityCreator.java 18 Dec 2003 17:40:19 -0000 1.4
--- IdentityCreator.java 19 Dec 2003 00:31:30 -0000 1.5
***************
*** 1,4 ****
--- 1,7 ----
/* $Id$
* $Log$
+ * Revision 1.5 2003/12/19 00:31:30 pelle
+ * Lots of usability changes through out all the passphrase agents and end user tools.
+ *
* Revision 1.4 2003/12/18 17:40:19 pelle
* You can now create keys that get stored with a X509 certificate in the keystore. These can be saved as well.
***************
*** 198,206 ****
--- 201,212 ----
import org.apache.commons.cli.Options;
+ import org.apache.commons.cli.ParseException;
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.Utility;
import org.neuclear.commons.crypto.CryptoException;
+ import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
import org.neuclear.commons.crypto.signers.PublicKeySource;
import org.neuclear.id.NSTools;
+ import org.neuclear.id.InvalidNamedObjectException;
import org.neuclear.id.builders.IdentityBuilder;
import org.neuclear.id.builders.NamedObjectBuilder;
***************
*** 214,221 ****
*/
public final class IdentityCreator extends CommandLineSigner {
! public IdentityCreator(final String[] args) throws Exception {
super(args);
! if (!(sig instanceof PublicKeySource))
! throw new NeuClearException("The default signer has to include public keys");
pksource = (PublicKeySource) sig;
identity = cmd.getOptionValue("n");
--- 220,229 ----
*/
public final class IdentityCreator extends CommandLineSigner {
! public IdentityCreator(final String[] args) throws UserCancellationException, ParseException, InvalidNamedObjectException {
super(args);
! if (!(sig instanceof PublicKeySource)) {
! System.err.println("The default signer has to include public keys");
! System.exit(1);
! }
pksource = (PublicKeySource) sig;
identity = cmd.getOptionValue("n");
***************
*** 243,252 ****
}
alias = (isTopLevel) ? identity : NSTools.getSignatoryURI(identity);
! final String allow = Utility.denullString(cmd.getOptionValue("w"), 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(allow)){
System.out.println("You do not currently have a key matching this name. Do you with to create one?");
if (!Utility.getAffirmative(true)) {
--- 251,259 ----
}
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)) {
***************
*** 254,259 ****
System.exit(0);
}
! System.out.print("Generating Keys for "+allow+"... ");
! PublicKey pub=sig.generateKey(allow);
System.out.println("DONE");
System.out.println("STORING Keys");
--- 261,266 ----
System.exit(0);
}
! System.out.println("Generating Keys for "+identity+"... ");
! PublicKey pub=sig.generateKey(identity);
System.out.println("DONE");
System.out.println("STORING Keys");
***************
*** 261,267 ****
}
! final PublicKey newkid = pksource.getPublicKey(allow);
if (newkid == null)
! throw new CryptoException("PublicKey not available for: " + allow);
return new IdentityBuilder(identity, newkid, defaultstore, defaultsigner, defaultlogger, defaultreceiver);
}
--- 268,274 ----
}
! 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);
}
***************
*** 271,282 ****
final IdentityCreator signer = new IdentityCreator(args);
signer.execute();
} catch (Exception e) {
e.printStackTrace();
}
! System.exit(0);
}
protected final String getExtraHelp() {
! return " --name neu://neu/one --receiver mailto:jo...@so... [--allow neuone --repository http://repository.neuclear.org -signer http://localhost:11870/Signer -logger http://logger.neuclear.org ]";
}
--- 278,291 ----
final IdentityCreator signer = new IdentityCreator(args);
signer.execute();
+ } catch (UserCancellationException e){
+ System.out.println("Bye");
} catch (Exception e) {
e.printStackTrace();
}
! // System.exit(0);
}
protected final String getExtraHelp() {
! return " --name neu://neu/one --receiver mailto:jo...@so...";
}
***************
*** 286,295 ****
protected final void getLocalOptions(final Options options) {
! options.addOption("n", "name", true, "specify name of new Identity");
! options.addOption("w", "allow", true, "specify alias in keystore of public key of new Identity");
! options.addOption("r", "repository", true, "Identity's default Repository");
! options.addOption("s", "signer", true, "Identity's default Interactive Signer");
! options.addOption("l", "logger", true, "Identity's default Logging Service");
! options.addOption("b", "receiver", true, "Identity's default Receiver");
}
--- 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... ]");
}
|