[Webfunds-commits] java/webfunds/client/contracts/wizard FinishSig.java

Edwin Woudt edwin@cypherpunks.ai
Tue, 29 Aug 2000 04:23:26 -0400 (AST)


edwin       00/08/29 04:23:26

  Modified:    webfunds/client/contracts/wizard FinishSig.java
  Log:
  - Add popup box for passphrase.
  - 'Forget' decrypted key right after using it.
  - Add 'please wait' popup window.

Revision  Changes    Path
1.13      +166 -44   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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FinishSig.java	2000/08/28 17:56:30	1.12
+++ FinishSig.java	2000/08/29 08:23:26	1.13
@@ -1,5 +1,5 @@
 /*
- * $Id: FinishSig.java,v 1.12 2000/08/28 17:56:30 edwin Exp $
+ * $Id: FinishSig.java,v 1.13 2000/08/29 08:23:26 edwin Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -36,7 +36,7 @@
  * Panel that does the actual signing.
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
  */
 
 public class FinishSig extends SignContractWizardPanel
@@ -161,28 +161,6 @@
         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      = 6;      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      = 7;      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. "+
@@ -192,7 +170,7 @@
 
         // Filler, makes sure the whole thing is aligned to the top
         c.gridheight = 1;      c.gridwidth = 2;
-        c.gridy      = 8;      c.gridx     = 0;
+        c.gridy      = 6;      c.gridx     = 0;
         c.weighty    = 1;      c.weightx   = 0;
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.CENTER;
@@ -313,6 +291,38 @@
 
     public boolean next() {
 
+        Dimension d;
+        Point p;
+        
+        Dimension ts = this.getSize();
+        Point tl = this.getLocation();
+        
+        Window parent = SwingUtilities.windowForComponent(this);
+        JDialog passframe = new JDialog((Frame)parent, true);
+        passframe.getContentPane().add(new PasswordPopup(passframe));
+        d = passframe.getPreferredSize();
+        d = new Dimension(d.width + 20, d.height + 20);
+        passframe.setSize(d);
+        p = new Point(tl.x + ((ts.width - d.width)>>1),
+                      tl.y + ((ts.height - d.height)>>1));
+        passframe.setLocation(p);
+                           
+        JFrame waitframe = new JFrame();
+        waitframe.getContentPane().add(new PleaseWaitPopup());
+        d = waitframe.getPreferredSize();
+        d = new Dimension(d.width + 20, d.height + 20);
+        waitframe.setSize(d);
+        p = new Point(tl.x + ((ts.width - d.width)>>1),
+                      tl.y + ((ts.height - d.height)>>1));
+        waitframe.setLocation(p);
+
+
+        passframe.show();
+        
+        waitframe.show();
+        waitframe.repaint();
+
+
         byte[] signedBytes;
 
         // parse the armoured key
@@ -321,9 +331,26 @@
             akey = new PGPArmoury(data.getSecretContractKey());
         } catch (IllegalArgumentException iae) {
             error("Invalid contract key, not armoured?",iae);
+            waitframe.hide();
             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.getOperatorKey();
+        all = all + "\r\n'\r\n\r\n[signatures]\r\n";
+
+        // write the unsigned contract
+        String unsignedName = txtFileUnsigned.getText();
+        all = PGPArmoury.canonicalize(all);
+        tryWriting(unsignedName, "unsigned contract", all);
+
         // get the unarmoured secret key
         PGPKeyFactory factory = new PGPKeyFactory();
         PGPSecretKey skey;
@@ -332,9 +359,11 @@
             Vector keys = factory.decodeKeys(akey.getPayload());
             if (keys.size() > 1) {
                 error("More than one key found in input file", null);
+                waitframe.hide();
                 return false;
             } else if (keys.size() < 1) {
                 error("No key found in input file", null);
+                waitframe.hide();
                 return false;
             }
             skey = (PGPSecretKey)keys.elementAt(0);
@@ -342,34 +371,23 @@
 
         } catch (PGPWrongPassphraseException wpe) {
             error("Wrong passphrase", wpe);
+            waitframe.hide();
             return false;
         } catch (PGPAbstractDataFormatException ape) {
             error("Error parsing contract key", ape);
+            waitframe.hide();
             return false;
         } catch (ClassCastException cce) {
             error("No secret key found",cce);
+            waitframe.hide();
             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.getOperatorKey();
-        all = all + "\r\n'\r\n\r\n[signatures]\r\n";
-
-        // write the unsigned contract
-        String unsignedName = txtFileUnsigned.getText();
-        all = PGPArmoury.canonicalize(all);
-        tryWriting(unsignedName, "unsigned contract", all);
-
         // prepare and sign contract
         String signedContract = PGPMessage.clearSign(all, skey);
+        
+        // forget the decrypted key
+        skey.forgetDecryptedKey();
 
         // Convert line endings to local format and convert the result into
         // bytes.
@@ -388,14 +406,17 @@
         String signedName = txtFile.getText();
         if (!tryWriting(signedName, "Signed Contract", new String(signedBytes)))
         {
-            System.err.println("try a quick sanity check anyway...");
             sanityCheckContract(signedBytes);
+            waitframe.hide();
             return false;
         }
 
-        if (!sanityCheckContract(signedBytes))
+        if (!sanityCheckContract(signedBytes)) {
+            waitframe.hide();
             return false;
+        }
 
+        waitframe.hide();
         return true ;
 
     }
@@ -431,5 +452,106 @@
         return true;
     }
 
+    
+    private class PasswordPopup extends JPanel 
+        implements ActionListener, KeyListener
+    {
+    
+        private JDialog dialog;
+    
+        public PasswordPopup(JDialog dialog) {
+
+            this.dialog = dialog;
+
+            GridBagLayout gridbag = new GridBagLayout();
+            GridBagConstraints c = new GridBagConstraints();
+    
+            JLabel lab;
+            JButton but;
+
+            this.setLayout(gridbag);
+
+            c.gridheight = 1;      c.gridwidth = 2;
+            c.gridy      = 0;      c.gridx     = 0;
+            c.weighty    = 0;      c.weightx   = 1;
+            c.fill       = GridBagConstraints.HORIZONTAL;
+            c.anchor     = GridBagConstraints.WEST;
+            c.insets     = new Insets(15, 15, 10, 15);
+            lab = new JLabel("Enter the passphrase for the contract key:");
+            gridbag.setConstraints(lab,c); this.add(lab);
+
+
+            c.gridheight = 1;      c.gridwidth = 1;
+            c.gridy      = 1;      c.gridx     = 0;
+            c.weighty    = 0;      c.weightx   = 1;
+            c.fill       = GridBagConstraints.HORIZONTAL;
+            c.anchor     = GridBagConstraints.EAST;
+            c.insets     = new Insets(10, 15, 15, 5);
+            txtPass = new JPasswordField("");
+            txtPass.addKeyListener(this);
+            gridbag.setConstraints(txtPass,c); this.add(txtPass);
+
+            c.gridheight = 1;      c.gridwidth = 1;
+            c.gridy      = 1;      c.gridx     = 1;
+            c.weighty    = 0;      c.weightx   = 0;
+            c.fill       = GridBagConstraints.NONE;
+            c.anchor     = GridBagConstraints.WEST;
+            c.insets     = new Insets(10, 5, 15, 15);
+            but = new JButton("Ok");
+            but.addActionListener(this);
+            but.setActionCommand("ok");
+            gridbag.setConstraints(but,c); this.add(but);
+
+        }
+        
+        public void actionPerformed(ActionEvent e) {
+
+            if (e.getActionCommand().equals("ok")) {
+                
+                this.dialog.hide();
+                
+            }
+                      
+        }
+        
+        public void keyTyped(KeyEvent e) {}
+        
+        public void keyPressed(KeyEvent e) {}
+
+        public void keyReleased(KeyEvent e) {
+
+            if (e.getKeyCode() == e.VK_ENTER) {
+                
+                this.dialog.hide();
+                
+            }
+            
+        }
+
+    }
+    
+    private class PleaseWaitPopup extends JPanel {
+    
+        public PleaseWaitPopup() {
+
+            GridBagLayout gridbag = new GridBagLayout();
+            GridBagConstraints c = new GridBagConstraints();
+            
+            JLabel lab;
+    
+            this.setLayout(gridbag);
+
+            c.gridheight = 1;      c.gridwidth = 1;
+            c.gridy      = 0;      c.gridx     = 0;
+            c.weighty    = 0;      c.weightx   = 1;
+            c.fill       = GridBagConstraints.HORIZONTAL;
+            c.anchor     = GridBagConstraints.WEST;
+            c.insets     = new Insets(15, 15, 15, 15);
+            lab = new JLabel("Please wait, your contract is being signed...");
+            gridbag.setConstraints(lab,c); this.add(lab);
+
+        }
+        
+    }
 
 }