[Webfunds-commits] java/webfunds/client/contracts/wizard KeyContract.java KeyPanel.java KeyServer.java KeyTop.java
Edwin Woudt
edwin@cypherpunks.ai
Tue, 15 Aug 2000 20:57:58 -0400 (AST)
edwin 00/08/15 20:57:58
Modified: webfunds/client/contracts/wizard KeyContract.java
KeyPanel.java KeyServer.java KeyTop.java
Log:
Better checks, better error messages.
Revision Changes Path
1.3 +14 -50 java/webfunds/client/contracts/wizard/KeyContract.java
Index: KeyContract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyContract.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KeyContract.java 2000/08/15 23:22:34 1.2
+++ KeyContract.java 2000/08/16 00:57:57 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: KeyContract.java,v 1.2 2000/08/15 23:22:34 edwin Exp $
+ * $Id: KeyContract.java,v 1.3 2000/08/16 00:57:57 edwin Exp $
*
* Copyright (c) Systemics Inc 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -22,7 +22,7 @@
* Panel that asks for the contract key
*
* @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class KeyContract extends KeyPanel
@@ -241,62 +241,26 @@
public boolean next() {
- if (!txtFile.getText().equals("")) {
- try {
- FileInputStream fis = new FileInputStream(txtFile.getText());
- DataInputStream dis = new DataInputStream(fis);
-
- byte[] contr = new byte[fis.available()];
- dis.readFully(contr);
-
- String s = new String(contr,"ISO8859-1");
- data.setPublicContractKey(s);
-
- } catch (IOException ioe) {
- String s;
- if (ioe instanceof FileNotFoundException) {
- s = "File not found";
- } else {
- s = ioe.toString();
- }
- JOptionPane.showMessageDialog(this, "Error opening file: "+s,
- "Error", JOptionPane.ERROR_MESSAGE);
- return false;
- }
+
+ String key = loadAndCheckKey(txtFile.getText(), false);
+
+ if (key != null) {
+ data.setPublicContractKey(key);
} else {
- data.setPublicContractKey("");
return false;
}
- if (!txtFile2.getText().equals("")) {
- try {
- FileInputStream fis = new FileInputStream(txtFile2.getText());
- DataInputStream dis = new DataInputStream(fis);
-
- byte[] contr = new byte[fis.available()];
- dis.readFully(contr);
-
- String s = new String(contr,"ISO8859-1");
- data.setSecretContractKey(s);
-
- return true;
- } catch (IOException ioe) {
- String s;
- if (ioe instanceof FileNotFoundException) {
- s = "File not found";
- } else {
- s = ioe.toString();
- }
- JOptionPane.showMessageDialog(this, "Error opening file: "+s,
- "Error", JOptionPane.ERROR_MESSAGE);
- return false;
- }
+
+ String key2 = loadAndCheckKey(txtFile2.getText(), true);
+
+ if (key2 != null) {
+ data.setSecretContractKey(key2);
+ return true;
} else {
- data.setSecretContractKey("");
return false;
}
}
-}
\ No newline at end of file
+}
1.2 +13 -5 java/webfunds/client/contracts/wizard/KeyPanel.java
Index: KeyPanel.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KeyPanel.java 2000/08/15 23:22:34 1.1
+++ KeyPanel.java 2000/08/16 00:57:57 1.2
@@ -1,5 +1,5 @@
/*
- * $Id: KeyPanel.java,v 1.1 2000/08/15 23:22:34 edwin Exp $
+ * $Id: KeyPanel.java,v 1.2 2000/08/16 00:57:57 edwin Exp $
*
* Copyright (c) Systemics Inc 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -10,6 +10,7 @@
import cryptix.openpgp.PGPException;
import cryptix.openpgp.PGPKeyFactory;
+import cryptix.openpgp.PGPPublicKey;
import cryptix.openpgp.PGPSecretKey;
import cryptix.openpgp.util.PGPArmoury;
@@ -27,12 +28,12 @@
* Abstract superclass for all panels in a wizard.
*
* @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public abstract class KeyPanel extends WizardPanel {
- protected String loadAndCheckKey(String filename) {
+ protected String loadAndCheckKey(String filename, boolean secret) {
if (!filename.equals("")) {
@@ -77,8 +78,15 @@
error("No key found in input file", null);
return null;
} else if (keys.elementAt(0) instanceof PGPSecretKey) {
- error("Secret key found, public key expected", null);
- return null;
+ if (!secret) {
+ error("Secret key found, public key expected", null);
+ return null;
+ }
+ } else if (keys.elementAt(0) instanceof PGPPublicKey) {
+ if (secret) {
+ error("Public key found, secret key expected", null);
+ return null;
+ }
}
} catch (PGPException pe) {
error("Error parsing input file, "+pe, pe);
@@ -94,4 +102,4 @@
}
}
-}
\ No newline at end of file
+}
1.3 +11 -28 java/webfunds/client/contracts/wizard/KeyServer.java
Index: KeyServer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyServer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KeyServer.java 2000/08/15 23:22:34 1.2
+++ KeyServer.java 2000/08/16 00:57:57 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: KeyServer.java,v 1.2 2000/08/15 23:22:34 edwin Exp $
+ * $Id: KeyServer.java,v 1.3 2000/08/16 00:57:57 edwin Exp $
*
* Copyright (c) Systemics Inc 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -22,7 +22,7 @@
* Panel that asks for the server certification key
*
* @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class KeyServer extends KeyPanel
@@ -151,34 +151,17 @@
}
public boolean next() {
- if (!txtFile.getText().equals("")) {
- try {
- FileInputStream fis = new FileInputStream(txtFile.getText());
- DataInputStream dis = new DataInputStream(fis);
-
- byte[] contr = new byte[fis.available()];
- dis.readFully(contr);
-
- String s = new String(contr,"ISO8859-1");
- data.setServerKey(s);
-
- return true;
- } catch (IOException ioe) {
- String s;
- if (ioe instanceof FileNotFoundException) {
- s = "File not found";
- } else {
- s = ioe.toString();
- }
- JOptionPane.showMessageDialog(this, "Error opening file: "+s,
- "Error", JOptionPane.ERROR_MESSAGE);
- return false;
- }
- } else {
- data.setUnsignedContract("");
+
+ String key = loadAndCheckKey(txtFile.getText(), false);
+
+ if (key != null) {
+ data.setServerKey(key);
return true;
+ } else {
+ return false;
}
+
}
-}
\ No newline at end of file
+}
1.3 +4 -4 java/webfunds/client/contracts/wizard/KeyTop.java
Index: KeyTop.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyTop.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KeyTop.java 2000/08/15 23:22:34 1.2
+++ KeyTop.java 2000/08/16 00:57:57 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: KeyTop.java,v 1.2 2000/08/15 23:22:34 edwin Exp $
+ * $Id: KeyTop.java,v 1.3 2000/08/16 00:57:57 edwin Exp $
*
* Copyright (c) Systemics Inc 2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -19,7 +19,7 @@
* Panel that asks for the toplevel certification key
*
* @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class KeyTop extends KeyPanel
@@ -174,7 +174,7 @@
public boolean next() {
- String key = loadAndCheckKey(txtFile.getText());
+ String key = loadAndCheckKey(txtFile.getText(), false);
if (key != null) {
data.setTopLevelKey(key);
@@ -186,4 +186,4 @@
}
-}
\ No newline at end of file
+}