[Webfunds-commits] java/webfunds/client/contracts/wizard FinishSig.java
Edwin Woudt
edwin@cypherpunks.ai
Fri, 11 Aug 2000 17:31:28 -0400 (AST)
edwin 00/08/11 17:31:27
Modified: webfunds/client/contracts/wizard FinishSig.java
Log:
Proper support for passphrase protected keys.
Revision Changes Path
1.2 +269 -250 java/webfunds/client/contracts/wizard/FinishSig.java
Index: FinishSig.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/FinishSig.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FinishSig.java 2000/08/08 14:56:52 1.1
+++ FinishSig.java 2000/08/11 21:31:27 1.2
@@ -1,251 +1,270 @@
-/*
- * $Id: FinishSig.java,v 1.1 2000/08/08 14:56:52 edwin Exp $
- *
- * Copyright (c) Systemics Inc 2000 on behalf of
- * the WebFunds Development Team. All Rights Reserved.
- */
-
-package webfunds.client.contracts.wizard;
-
-
-import cryptix.openpgp.PGPException;
-import cryptix.openpgp.PGPMessage;
-import cryptix.openpgp.PGPPublicKey;
-import cryptix.openpgp.PGPSecretKey;
-import cryptix.openpgp.util.PGPArmoury;
-
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-
-/**
- * Panel that does the actual signing.
- *
- * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.1 $
- */
-
-public class FinishSig extends WizardPanel
- implements ActionListener {
-
- JTextField txtFile;
-
- WizardData data;
-
-
- public FinishSig(WizardData data) {
-
- this.data = data;
-
- // GridBagLayout is the most flexible (also the most difficult
- // to use) LayoutManager.
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
-
- setLayout(gridbag);
-
-
- // Define some components we'll use later on.
- JButton but;
- JLabel lab;
-
-
- // Ok, this is where the real dirty work starts. Do not attempt
- // to change it, unless you understand the GridBagLayout and
- // GridBagConstraints, because in case you don't the result
- // will probably be a real f*ck up of the layout.
-
- c.gridheight = 1; c.gridwidth = 2;
- c.gridy = 0; c.gridx = 0;
- c.weighty = 0; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.WEST;
- c.insets = new Insets(5, 5, 5, 5);
- lab = new JLabel("Generating the Signature");
- gridbag.setConstraints(lab,c); add(lab);
-
-
- c.gridheight = 1; c.gridwidth = 2;
- c.gridy = 1; c.gridx = 0;
- c.weighty = 0; c.weightx = 1;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.anchor = GridBagConstraints.WEST;
- c.insets = new Insets(5, 5, 15, 5);
- lab = new JLabel("<html><font size='-1'><b>"+
- "You have now collected all the information that is "+
- "needed to sign the contract. Please specify the "+
- "location where you want the signed contract to be "+
- "stored. "+
- "</b></font></html>");
- gridbag.setConstraints(lab,c); add(lab);
-
-
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 0;
- c.weighty = 0; c.weightx = 1;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.anchor = GridBagConstraints.EAST;
- c.insets = new Insets(5, 5, 5, 5);
- txtFile = new JTextField("");
- gridbag.setConstraints(txtFile,c); add(txtFile);
-
-
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 1;
- c.weighty = 0; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.WEST;
- c.insets = new Insets(5, 5, 5, 5);
- but = new JButton("Browse");
- but.addActionListener(this);
- but.setActionCommand("browse");
- gridbag.setConstraints(but,c); add(but);
-
-
- c.gridheight = 1; c.gridwidth = 2;
- c.gridy = 3; c.gridx = 0;
- c.weighty = 0; c.weightx = 1;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.anchor = GridBagConstraints.WEST;
- c.insets = new Insets(5, 5, 15, 5);
- lab = new JLabel("<html><font size='-1'><b>"+
- "Press next to generate the signature. "+
- "Please note that this process may take a while, "+
- "depending on the speed of your computer. "+
- "</b></font></html>");
- gridbag.setConstraints(lab,c); add(lab);
-
-
- // Filler, makes sure the whole thing is aligned to the top
- c.gridheight = 1; c.gridwidth = 2;
- c.gridy = 4; c.gridx = 0;
- c.weighty = 1; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.CENTER;
- c.insets = new Insets(5, 5, 5, 5);
- lab = new JLabel("");
- gridbag.setConstraints(lab,c); add(lab);
-
- }
-
-
- public void actionPerformed(java.awt.event.ActionEvent e) {
-
- if (e.getActionCommand().equals("browse")) {
-
- JFileChooser fc = new JFileChooser();
-
- fc.setDialogTitle("Open Contract");
- fc.setDialogType(fc.OPEN_DIALOG);
- fc.setFileSelectionMode(fc.FILES_ONLY);
-
- if (fc.showOpenDialog(this) == fc.APPROVE_OPTION) {
-
- try {
- txtFile.setText(fc.getSelectedFile().getCanonicalPath());
- } catch (IOException ioe) { }
-
- }
-
- }
-
- }
-
-
- public void enter() {
- // do nothing
- }
-
- public boolean leave() {
- // do nothing
- return true;
- }
-
- public boolean next() {
-
- // parse the armoured key
- PGPArmoury akey;
- try {
- System.out.println(data.getSecretContractKey());
- akey = new PGPArmoury(data.getSecretContractKey());
- } catch (IllegalArgumentException iae) {
- error("Invalid contract key",iae);
- return false;
- }
-
- ByteArrayInputStream bais = new ByteArrayInputStream(akey.getPayload());
- DataInputStream dis = new DataInputStream(bais);
-
-
- // get the unarmoured secret key
- PGPSecretKey skey = new PGPSecretKey();
- try {
- skey.readKey(dis);
- // ### FIXME: when decryption is implemented, show a dialog box
- // ### for the password.
- // skey.decrypt("hoi");
- } catch (IOException ioe) {
- error("Error parsing contract key",ioe);
- return false;
- } catch (PGPException pe) {
- error("Error parsing contract key",pe);
- return false;
- }
-
-
- // put the contract together
- String all = data.getUnsignedContract();
- all = all + "\r\n[keys]";
- all = all + "\r\n\r\nkeys_contract='\r\n\r\n";
- all = all + data.getPublicContractKey();
- all = all + "\r\n'\r\n\r\nkeys_certification='\r\n\r\n";
- all = all + data.getTopLevelKey();
- all = all + "\r\n'\r\n\r\nkeys_server_certification='\r\n\r\n";
- all = all + data.getServerKey();
- all = all + "\r\n'\r\n\r\n[signatures]\r\n";
-
-
- // prepare and sign contract
- byte[] signedBytes;
-
- try {
- String signedContract = PGPMessage.clearSign(all, skey);
- signedBytes = signedContract.getBytes("ISO8859-1");
- } catch (IOException ioe) {
- error("PANIC: Error signing contract",ioe);
- return false;
- }
-
-
- // write the contract
- try {
- FileOutputStream fos = new FileOutputStream(txtFile.getText());
- DataOutputStream dos = new DataOutputStream(fos);
- dos.write(signedBytes);
- } catch (IOException ioe) {
- error("Error writing contract file",ioe);
- return false;
- }
-
-
- return true;
- }
-
-
- private void error(String message, Exception e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(this, message, "Error",
- JOptionPane.ERROR_MESSAGE);
- }
-
+/*
+ * $Id: FinishSig.java,v 1.2 2000/08/11 21:31:27 edwin Exp $
+ *
+ * Copyright (c) Systemics Inc 2000 on behalf of
+ * the WebFunds Development Team. All Rights Reserved.
+ */
+
+package webfunds.client.contracts.wizard;
+
+
+import cryptix.openpgp.PGPException;
+import cryptix.openpgp.PGPMessage;
+import cryptix.openpgp.PGPPublicKey;
+import cryptix.openpgp.PGPSecretKey;
+import cryptix.openpgp.util.PGPArmoury;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+
+/**
+ * Panel that does the actual signing.
+ *
+ * @author Edwin Woudt <edwin@webfunds.org>
+ * @version $Revision: 1.2 $
+ */
+
+public class FinishSig extends WizardPanel
+ implements ActionListener {
+
+ JTextField txtFile, txtPass;
+
+ WizardData data;
+
+
+ public FinishSig(WizardData data) {
+
+ this.data = data;
+
+ // GridBagLayout is the most flexible (also the most difficult
+ // to use) LayoutManager.
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+
+ setLayout(gridbag);
+
+
+ // Define some components we'll use later on.
+ JButton but;
+ JLabel lab;
+
+
+ // Ok, this is where the real dirty work starts. Do not attempt
+ // to change it, unless you understand the GridBagLayout and
+ // GridBagConstraints, because in case you don't the result
+ // will probably be a real f*ck up of the layout.
+
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 0; c.gridx = 0;
+ c.weighty = 0; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(5, 5, 5, 5);
+ lab = new JLabel("Generating the Signature");
+ gridbag.setConstraints(lab,c); add(lab);
+
+
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 1; c.gridx = 0;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(5, 5, 15, 5);
+ lab = new JLabel("<html><font size='-1'><b>"+
+ "You have now collected all the information that is "+
+ "needed to sign the contract. Please specify the "+
+ "location where you want the signed contract to be "+
+ "stored. "+
+ "</b></font></html>");
+ gridbag.setConstraints(lab,c); add(lab);
+
+
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 0;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.EAST;
+ c.insets = new Insets(5, 5, 5, 5);
+ txtFile = new JTextField("");
+ gridbag.setConstraints(txtFile,c); add(txtFile);
+
+
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 1;
+ c.weighty = 0; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(5, 5, 5, 5);
+ but = new JButton("Browse");
+ but.addActionListener(this);
+ but.setActionCommand("browse");
+ gridbag.setConstraints(but,c); add(but);
+
+
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 3; c.gridx = 0;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(5, 5, 15, 5);
+ lab = new JLabel("<html><font size='-1'><b>"+
+ "Enter the passphrase for the contract key: "+
+ "</b></font></html>");
+ gridbag.setConstraints(lab,c); add(lab);
+
+
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 4; c.gridx = 0;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.EAST;
+ c.insets = new Insets(5, 5, 5, 5);
+ txtPass = new JPasswordField("");
+ gridbag.setConstraints(txtPass,c); add(txtPass);
+
+
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 5; c.gridx = 0;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(5, 5, 15, 5);
+ lab = new JLabel("<html><font size='-1'><b>"+
+ "Press next to generate the signature. "+
+ "Please note that this process may take a while, "+
+ "depending on the speed of your computer. "+
+ "</b></font></html>");
+ gridbag.setConstraints(lab,c); add(lab);
+
+
+ // Filler, makes sure the whole thing is aligned to the top
+ c.gridheight = 1; c.gridwidth = 2;
+ c.gridy = 6; c.gridx = 0;
+ c.weighty = 1; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = new Insets(5, 5, 5, 5);
+ lab = new JLabel("");
+ gridbag.setConstraints(lab,c); add(lab);
+
+ }
+
+
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+
+ if (e.getActionCommand().equals("browse")) {
+
+ JFileChooser fc = new JFileChooser();
+
+ fc.setDialogTitle("Open Contract");
+ fc.setDialogType(fc.OPEN_DIALOG);
+ fc.setFileSelectionMode(fc.FILES_ONLY);
+
+ if (fc.showOpenDialog(this) == fc.APPROVE_OPTION) {
+
+ try {
+ txtFile.setText(fc.getSelectedFile().getCanonicalPath());
+ } catch (IOException ioe) { }
+
+ }
+
+ }
+
+ }
+
+
+ public void enter() {
+ // do nothing
+ }
+
+ public boolean leave() {
+ // do nothing
+ return true;
+ }
+
+ public boolean next() {
+
+ byte[] signedBytes;
+
+ try {
+
+ // parse the armoured key
+ PGPArmoury akey;
+ try {
+ akey = new PGPArmoury(data.getSecretContractKey());
+ } catch (IllegalArgumentException iae) {
+ error("Invalid contract key, not armoured?",iae);
+ return false;
+ }
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(akey.getPayload());
+ DataInputStream dis = new DataInputStream(bais);
+
+
+ // get the unarmoured secret key
+ PGPSecretKey skey = new PGPSecretKey();
+ try {
+ skey.readKey(dis);
+ skey.decrypt(txtPass.getText());
+ } catch (PGPException pe) {
+ error("Error parsing contract key",pe);
+ return false;
+ }
+
+
+ // put the contract together
+ String all = data.getUnsignedContract();
+ all = all + "\r\n[keys]";
+ all = all + "\r\n\r\nkeys_contract='\r\n\r\n";
+ all = all + data.getPublicContractKey();
+ all = all + "\r\n'\r\n\r\nkeys_certification='\r\n\r\n";
+ all = all + data.getTopLevelKey();
+ all = all + "\r\n'\r\n\r\nkeys_server_certification='\r\n\r\n";
+ all = all + data.getServerKey();
+ all = all + "\r\n'\r\n\r\n[signatures]\r\n";
+
+
+ // prepare and sign contract
+ String signedContract = PGPMessage.clearSign(all, skey);
+ signedBytes = signedContract.getBytes("ISO8859-1");
+
+ } catch (IOException ioe) {
+ throw new InternalError("IOException in "+
+ "ByteArray[In|Out]putStream");
+ }
+
+
+ // write the contract
+ try {
+ FileOutputStream fos = new FileOutputStream(txtFile.getText());
+ DataOutputStream dos = new DataOutputStream(fos);
+ dos.write(signedBytes);
+ } catch (IOException ioe) {
+ error("Error writing contract file",ioe);
+ return false;
+ }
+
+
+ return true;
+
+ }
+
+
+ private void error(String message, Exception e) {
+ e.printStackTrace();
+ JOptionPane.showMessageDialog(this, message, "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+
}