Commits

Anonymous committed 2bcab1f

gui started

Comments (0)

Files changed (18)

build/built-jar.properties

-#Thu, 13 Mar 2014 00:08:31 +1100
+#Mon, 17 Mar 2014 23:22:29 +1100
 
 
 /home/lp1/Desktop/Dropbox/Apps/KeystoreGUI=

build/classes/KeyStore/KeyStoreController.class

Binary file modified.

build/classes/KeyStoreGUI/KeyPanel$1.class

Binary file added.

build/classes/KeyStoreGUI/KeyPanel$2.class

Binary file added.

build/classes/KeyStoreGUI/KeyPanel.class

Binary file added.

build/classes/KeyStoreGUI/MainFrame$1.class

Binary file added.

build/classes/KeyStoreGUI/MainFrame$2.class

Binary file added.

build/classes/KeyStoreGUI/MainFrame$3.class

Binary file added.

build/classes/KeyStoreGUI/MainFrame.class

Binary file added.

build/classes/PackageController.class

Binary file modified.

dist/KeystoreGUI.jar

Binary file modified.

nbproject/project.properties

 jnlp.signing=
 jnlp.signing.alias=
 jnlp.signing.keystore=
-main.class=KeyStoreGUI.KeyStoreGUI
+main.class=PackageController
 manifest.file=manifest.mf
 meta.inf.dir=${src.dir}/META-INF
 mkdist.disabled=false

src/KeyStore/KeyStoreController.java

 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 
 /**
      * Key Constructor with no arg
      * 
      */
-    public KeyStoreController(int bitLength, String keyPassword, String keyPath) throws FileNotFoundException, IOException {
-        //ASSUMES ALL NEW - new keypair and new CSR
-        //new keypair contructor (bitLenght, password, file)
-        KeyStoreController.keyPair = new KeyPair(bitLength, keyPassword, keyPath);
-        KeyStoreController.keyPassword = keyPassword;
+    public KeyStoreController(int bitLength, String keyPassword, String keyPath) {
+        try {
+            //ASSUMES ALL NEW - new keypair and new CSR
+            //new keypair contructor (bitLenght, password, file)
+            KeyStoreController.keyPair = new KeyPair(bitLength, keyPassword, keyPath);
+            KeyStoreController.keyPassword = keyPassword;
+        } catch (FileNotFoundException ex) {
+            Logger.getLogger(KeyStoreController.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IOException ex) {
+            Logger.getLogger(KeyStoreController.class.getName()).log(Level.SEVERE, null, ex);
+        }
     }
 
     /*    
         certificate.writePKCS12(outputPath);
     }
         
-    public String getCSR(String x500Text) throws IOException {
-        return keyPair.getCSR(x500Text);       
+    public String getCSR(String x500Text) {
+        String csrVal = null;
+        try {       
+            csrVal = keyPair.getCSR(x500Text);
+        } catch (IOException ex) {
+            Logger.getLogger(KeyStoreController.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return csrVal;
     }
     
     public String getPrivate() {

src/KeyStoreGUI/KeyPanel.form

+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" alignment="0" attributes="0">
+              <EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="jScrollPane1" min="-2" pref="470" max="-2" attributes="0"/>
+                  <Group type="102" attributes="0">
+                      <Component id="generateNewButton" min="-2" max="-2" attributes="0"/>
+                      <EmptySpace type="separate" max="-2" attributes="0"/>
+                      <Component id="openExistingButton" min="-2" max="-2" attributes="0"/>
+                  </Group>
+              </Group>
+              <EmptySpace pref="452" max="32767" attributes="0"/>
+          </Group>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" alignment="0" attributes="0">
+              <EmptySpace min="-2" pref="57" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="generateNewButton" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="openExistingButton" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace type="separate" max="-2" attributes="0"/>
+              <Component id="jScrollPane1" min="-2" pref="243" max="-2" attributes="0"/>
+              <EmptySpace pref="362" max="32767" attributes="0"/>
+          </Group>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+  <SubComponents>
+    <Component class="javax.swing.JButton" name="generateNewButton">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="Generate new"/>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="generateNewButtonActionPerformed"/>
+      </Events>
+    </Component>
+    <Component class="javax.swing.JToggleButton" name="openExistingButton">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="Open existing"/>
+      </Properties>
+    </Component>
+    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+      <AuxValues>
+        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JTextArea" name="csrTextField">
+          <Properties>
+            <Property name="editable" type="boolean" value="false"/>
+            <Property name="columns" type="int" value="20"/>
+            <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
+              <Font name="Courier New" size="12" style="0"/>
+            </Property>
+            <Property name="rows" type="int" value="5"/>
+            <Property name="autoscrolls" type="boolean" value="false"/>
+          </Properties>
+          <Events>
+            <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="csrTextFieldMouseClicked"/>
+          </Events>
+        </Component>
+      </SubComponents>
+    </Container>
+  </SubComponents>
+</Form>

src/KeyStoreGUI/KeyPanel.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package KeyStoreGUI;
+
+import javax.swing.Box;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPasswordField;
+
+/**
+ *
+ * @author lp1
+ */
+public class KeyPanel extends javax.swing.JPanel {
+    private static Integer bitLength = 2048;
+    /**
+     * Creates new form KeyPanel
+     */
+    public KeyPanel() {
+        initComponents();
+    }
+    
+    private static String getPassword(String message) {
+        JPasswordField jpf = new JPasswordField(24);
+        JLabel jl = new JLabel(message);
+        Box box = Box.createHorizontalBox();
+        box.add(jl);
+        box.add(jpf);
+        // TODO get password input field to pull focus
+        int x = JOptionPane.showConfirmDialog(null, box, "Password Entry", JOptionPane.OK_CANCEL_OPTION);
+        
+        if (x == JOptionPane.OK_OPTION) {
+        //TODO dont store passswords as string, use char[]
+        return  new String (jpf.getPassword());
+    }
+    return null;
+  }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        generateNewButton = new javax.swing.JButton();
+        openExistingButton = new javax.swing.JToggleButton();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        csrTextField = new javax.swing.JTextArea();
+
+        generateNewButton.setText("Generate new");
+        generateNewButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                generateNewButtonActionPerformed(evt);
+            }
+        });
+
+        openExistingButton.setText("Open existing");
+
+        csrTextField.setEditable(false);
+        csrTextField.setColumns(20);
+        csrTextField.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N
+        csrTextField.setRows(5);
+        csrTextField.setAutoscrolls(false);
+        csrTextField.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
+                csrTextFieldMouseClicked(evt);
+            }
+        });
+        jScrollPane1.setViewportView(csrTextField);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addGap(38, 38, 38)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 470, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(generateNewButton)
+                        .addGap(18, 18, 18)
+                        .addComponent(openExistingButton)))
+                .addContainerGap(452, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addGap(57, 57, 57)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(generateNewButton)
+                    .addComponent(openExistingButton))
+                .addGap(18, 18, 18)
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(362, Short.MAX_VALUE))
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void generateNewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateNewButtonActionPerformed
+        String keyPassword = getPassword("Enter new key password: ");
+        String keyPassword2 = getPassword("Confirm password: ");
+        if (keyPassword.equals(keyPassword2)) {
+            String c = JOptionPane.showInputDialog(null, "Enter country code (http://www.digicert.com/ssl-certificate-country-codes.htm for valid options): ","", 1);
+            String o = JOptionPane.showInputDialog(null, "Organisation name: ","", 1);
+            String cn = JOptionPane.showInputDialog(null, "Common name: ","", 1);
+            String email = JOptionPane.showInputDialog(null, "Contact email: ","", 1);
+            String x500Text = "C=" + c + ", O=" + o + ", CN=" + cn + ", EMAILADDRESS=" + email;
+            KeyStore.KeyStoreController newKeySess = new KeyStore.KeyStoreController(bitLength, keyPassword, cn + ".pem");
+            csrTextField.setText(newKeySess.getCSR(x500Text));
+        } else
+             JOptionPane.showMessageDialog(null, "Passwords do not match", "Oops", JOptionPane.INFORMATION_MESSAGE);
+    }//GEN-LAST:event_generateNewButtonActionPerformed
+
+    private void csrTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_csrTextFieldMouseClicked
+        csrTextField.selectAll();
+    }//GEN-LAST:event_csrTextFieldMouseClicked
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JTextArea csrTextField;
+    private javax.swing.JButton generateNewButton;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JToggleButton openExistingButton;
+    // End of variables declaration//GEN-END:variables
+}

src/KeyStoreGUI/KeyStoreGUI.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package KeyStoreGUI;
-
-/**
- *
- * @author Mark Culhane, 2014
- */
-public class KeyStoreGUI {
-
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String[] args) {
-        // TODO code application logic here
-    }
-}

src/KeyStoreGUI/MainFrame.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package KeyStoreGUI;
+
+/**
+ *
+ * @author Mark Culhane
+ */
+/**
+ *
+ * @author Mark Culhane
+ */
+public class MainFrame extends javax.swing.JFrame {
+
+    /** Creates new form MainFrame */
+    public MainFrame() {
+        initComponents();
+    }
+
+    /** This method is called from within the constructor to
+     * initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is
+     * always regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
+    private void initComponents() {
+
+        quitButton = new javax.swing.JButton();
+        mainTabPanel = new javax.swing.JTabbedPane();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
+
+        quitButton.setText("Quit");
+        quitButton.addMouseListener(new java.awt.event.MouseAdapter() {
+            @Override
+            public void mouseReleased(java.awt.event.MouseEvent evt) {
+                quitButtonMouseReleased(evt);
+            }
+        });
+        quitButton.addActionListener(new java.awt.event.ActionListener() {
+            @Override
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                quitButtonActionPerformed(evt);
+            }
+        });
+
+        mainTabPanel.setMaximumSize(new java.awt.Dimension(862, 632));
+        mainTabPanel.addTab("Client SSL", new KeyPanel());
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(1020, Short.MAX_VALUE)
+                .addComponent(quitButton)
+                .addContainerGap())
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(mainTabPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 1071, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(mainTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(quitButton)
+                .addContainerGap())
+        );
+
+        pack();
+    }// </editor-fold>                        
+
+private void quitButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
+    System.exit(0);
+}                                        
+
+private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
+// TODO add your handling code here:
+}                                          
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String args[]) {
+        /* Set the Nimbus look and feel */
+        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
+         */
+        try {
+            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+                if ("Nimbus".equals(info.getName())) {
+                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
+                    break;
+                }
+            }
+        } catch (ClassNotFoundException ex) {
+            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+
+        /* Create and display the form */
+        java.awt.EventQueue.invokeLater(new Runnable() {
+
+            @Override
+            public void run() {
+                new MainFrame().setVisible(true);
+            }
+        });
+    }
+    // Variables declaration - do not modify                     
+    private javax.swing.JTabbedPane mainTabPanel;
+    private javax.swing.JButton quitButton;
+    // End of variables declaration                   
+}

src/PackageController.java

 import KeyStore.KeyStoreController;
+import KeyStoreGUI.MainFrame;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Scanner;
+import javax.swing.JFrame;
 
 /**
  *
     private static String keyPassword = "abc123";
     private static String certPath = "myCert.pem";
     private static String outputPath = "myPKCS12.p12";
-    
-    public static void main(String[] args) throws IOException {
-                //default keystore controller contructer
-
-                Scanner sc = new Scanner(System.in);
-                int i = 9;
-                do {
-                    do {
-                        System.out.println("##################### "
-                            + "\n 0 - Exit"
-                            + "\n 1 - Generate New Key and CSR"
-                            + "\n 2 - Create pfx from existing keypair and certificate"
-                            + "\n Enter option number:");
-                        i = sc.nextInt();
-                    } while (i > 2);
-                    if (i == 1) newKeyAndCSR();
-                    if (i == 2) {
-                        createPFX(certPath);
-                    }
-                } while (i != 0);
-                System.exit(0);
-        } 
-    
-    private static void newKeyAndCSR() throws FileNotFoundException, IOException {
-        KeyStoreController keyStoreController = new KeyStoreController(2048, keyPassword, keyPath);
-        System.out.println(keyStoreController.getCSR(x500Text));
-    }
-    
-    private static void createPFX(String certPath) throws FileNotFoundException, IOException {
-        KeyStoreController keyStoreController = new KeyStoreController(keyPassword, keyPath);
-        keyStoreController.setCert(certPath);
-        keyStoreController.exportPKCS12(outputPath);
-        System.out.println("... Done :D");
-    }
+ 
+    public static void main(String[] args) {
+        JFrame newFrame = new MainFrame();
+        newFrame.setTitle("Simple Client SSL tool");
+        newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        newFrame.setVisible(true);
+    }   
+//    public static void main(String[] args) throws IOException {
+//                //default keystore controller contructer
+//
+//                Scanner sc = new Scanner(System.in);
+//                int i = 9;
+//                do {
+//                    do {
+//                        System.out.println("##################### "
+//                            + "\n 0 - Exit"
+//                            + "\n 1 - Generate New Key and CSR"
+//                            + "\n 2 - Create pfx from existing keypair and certificate"
+//                            + "\n Enter option number:");
+//                        i = sc.nextInt();
+//                    } while (i > 2);
+//                    if (i == 1) newKeyAndCSR();
+//                    if (i == 2) {
+//                        createPFX(certPath);
+//                    }
+//                } while (i != 0);
+//                System.exit(0);
+//        } 
+//    
+//    private static void newKeyAndCSR() throws FileNotFoundException, IOException {
+//        KeyStoreController keyStoreController = new KeyStoreController(2048, keyPassword, keyPath);
+//        System.out.println(keyStoreController.getCSR(x500Text));
+//    }
+//    
+//    private static void createPFX(String certPath) throws FileNotFoundException, IOException {
+//        KeyStoreController keyStoreController = new KeyStoreController(keyPassword, keyPath);
+//        keyStoreController.setCert(certPath);
+//        keyStoreController.exportPKCS12(outputPath);
+//        System.out.println("... Done :D");
+//    }
 }