# HG changeset patch # User nolith # Date 1181839305 -7200 # Branch trunk # Node ID f0aa5d9d40e1b509746afb21bd3e4f0977025872 # Parent 2671a2d977f2900c96cf95d8226c7949957c6724 [svn] [FIX] command line password management now works properly [NEW] if no password is provided, a dialog will appear before checking the file diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 INSTALL --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL Thu Jun 14 18:41:45 2007 +0200 @@ -0,0 +1,8 @@ +Before starting remember to downaload dependencies libs + + ant download_deps + +This code uses java6 System.console class +to compile with java5 use + + ant -Djava6=false diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 README --- a/README Thu Jun 14 16:58:03 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -Before starting remember to downaload dependencies libs - - ant download_deps - -This code uses java6 System.console class -to compile with java5 use - - ant -Djava6=false diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 src/org/abisso/PortableNotary/GUI/MainFrame.java --- a/src/org/abisso/PortableNotary/GUI/MainFrame.java Thu Jun 14 16:58:03 2007 +0200 +++ b/src/org/abisso/PortableNotary/GUI/MainFrame.java Thu Jun 14 18:41:45 2007 +0200 @@ -25,11 +25,13 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JPanel; import net.iharder.dnd.FileDrop; import org.abisso.PortableNotary.Notary; +import org.abisso.PortableNotary.Preferences; public class MainFrame extends JFrame { @@ -44,13 +46,14 @@ private JMenu option = null; private JMenuItem preferences = null; - //private Preferences pref = Preferences.getIstance(); + private Preferences pref; /** * This is the default constructor */ public MainFrame() { super(); + pref = Preferences.getIstance(); initialize(); } @@ -71,16 +74,28 @@ d.height += increase; this.setSize(d); setJMenuBar(getMenubar()); + new FileDrop( getImage(), new FileDrop.Listener(){ public void filesDropped( java.io.File[] files ) { MyFrameWithConsole sign; + //check if password is stored + String password = pref.getKeystore_pass(); + System.out.println(password); + if ( password.equals("") ) { + password = PasswordDialog.askPassword(null); + } + System.out.println(password); for( int i=0; i - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -package org.abisso.PortableNotary.GUI; - -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JTextField; - -public class Preferences extends JDialog { - - private static final long serialVersionUID = 1L; - - private JPanel jContentPane = null; - private JLabel warning = null; - private JLabel labelPath = null; - private JTextField textPath = null; - private JLabel labelPassword = null; - private JPasswordField textPassword = null; - private JButton browse = null; - private JButton save = null; - private JButton cancel = null; - - private org.abisso.PortableNotary.Preferences pref; - - /** - * This is the default constructor - */ - public Preferences(org.abisso.PortableNotary.Preferences pref) { - super(); - this.pref = pref; - initialize(); - this.setModal(true); - } - - /** - * This method initializes this - * - * @return void - */ - private void initialize() { - this.setSize(400, 200); - this.setContentPane(getJContentPane()); - this.setTitle("Preferences"); - } - - /** - * This method initializes jContentPane - * - * @return javax.swing.JPanel - */ - private JPanel getJContentPane() { - if (jContentPane == null) { - GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); - gridBagConstraints3.gridx = 2; - gridBagConstraints3.gridy = 1; - GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); - gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; - gridBagConstraints21.gridy = 2; - gridBagConstraints21.weightx = 1.0; - gridBagConstraints21.gridx = 1; - GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); - gridBagConstraints11.gridx = 0; - gridBagConstraints11.gridy = 2; - gridBagConstraints11.anchor = GridBagConstraints.WEST; - labelPassword = new JLabel(); - labelPassword.setText("Keystore's password:"); - labelPassword.setLabelFor(getTextPassword()); - GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); - gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL; - gridBagConstraints2.gridy = 1; - gridBagConstraints2.weightx = 1.0; - gridBagConstraints2.gridx = 1; - GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); - gridBagConstraints1.gridx = 0; - gridBagConstraints1.gridy = 1; - gridBagConstraints1.anchor = GridBagConstraints.WEST; - labelPath = new JLabel(); - labelPath.setText("Keystore path:"); - labelPath.setLabelFor(getTextPath()); - GridBagConstraints gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridwidth = 3; - gridBagConstraints.gridy = 0; - warning = new JLabel(); - warning.setText("WARNING: Password are stored in unsafe way"); - jContentPane = new JPanel(); - jContentPane.setLayout(new GridBagLayout()); - jContentPane.add(warning, gridBagConstraints); - jContentPane.add(labelPath, gridBagConstraints1); - jContentPane.add(getTextPath(), gridBagConstraints2); - jContentPane.add(labelPassword, gridBagConstraints11); - jContentPane.add(getTextPassword(), gridBagConstraints21); - jContentPane.add(getBrowse(), gridBagConstraints3); - GridBagConstraints gridBagConstraints22 = new GridBagConstraints(); - gridBagConstraints22.fill = GridBagConstraints.VERTICAL; - gridBagConstraints22.gridy = 3; - gridBagConstraints22.weightx = 1.0; - gridBagConstraints22.gridx = 1; - gridBagConstraints22.anchor = GridBagConstraints.EAST; - GridBagConstraints gridBagConstraints32 = new GridBagConstraints(); - gridBagConstraints32.gridy = 3; - gridBagConstraints32.gridx = 2; - gridBagConstraints32.anchor = GridBagConstraints.WEST; - jContentPane.add(getSave(), gridBagConstraints22); - jContentPane.add(getCancel(), gridBagConstraints32); - } - return jContentPane; - } - - /** - * This method initializes textPath - * - * @return javax.swing.JTextField - */ - private JTextField getTextPath() { - if (textPath == null) { - textPath = new JTextField(); - textPath.setText(pref.getKeystore_path()); - } - return textPath; - } - - /** - * This method initializes textPassword - * - * @return javax.swing.JPasswordField - */ - private JPasswordField getTextPassword() { - if (textPassword == null) { - textPassword = new JPasswordField(); - textPassword.setText(pref.getKeystore_pass()); - } - return textPassword; - } - - /** - * This method initializes browse - * - * @return javax.swing.JButton - */ - private JButton getBrowse() { - if (browse == null) { - browse = new JButton("Browse"); - //TODO: implement keystore browsing - browse.setEnabled(false); - } - return browse; - } - - /** - * This method initializes save - * - * @return javax.swing.JButton - */ - private JButton getSave() { - if (save == null) { - save = new JButton("Save"); - save.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - pref.setKeystore_pass(textPassword.getPassword().toString()); - pref.setKeystore_path(textPath.getText()); - //TODO: check if this is the correct way - setVisible(false); - } - }); - } - return save; - } - - /** - * This method initializes cancel - * - * @return javax.swing.JButton - */ - private JButton getCancel() { - if (cancel == null) { - cancel = new JButton("Cancel"); - cancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - //TODO: check if this is the correct way - setVisible(false); - } - }); - } - return cancel; - } -} diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 src/org/abisso/PortableNotary/GUI/PreferencesDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/abisso/PortableNotary/GUI/PreferencesDialog.java Thu Jun 14 18:41:45 2007 +0200 @@ -0,0 +1,206 @@ +/** + Copyright 2007 Alessio Caiazza + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package org.abisso.PortableNotary.GUI; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +public class PreferencesDialog extends JDialog { + + private static final long serialVersionUID = 1L; + + private JPanel jContentPane = null; + private JLabel warning = null; + private JLabel labelPath = null; + private JTextField textPath = null; + private JLabel labelPassword = null; + private JPasswordField textPassword = null; + private JButton browse = null; + private JButton save = null; + private JButton cancel = null; + + private org.abisso.PortableNotary.Preferences pref; + + /** + * This is the default constructor + */ + public PreferencesDialog(org.abisso.PortableNotary.Preferences pref) { + super(); + this.pref = pref; + initialize(); + this.setModal(true); + } + + /** + * This method initializes this + * + * @return void + */ + private void initialize() { + this.setSize(400, 200); + this.setContentPane(getJContentPane()); + this.setTitle("Preferences"); + } + + /** + * This method initializes jContentPane + * + * @return javax.swing.JPanel + */ + private JPanel getJContentPane() { + if (jContentPane == null) { + GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); + gridBagConstraints3.gridx = 2; + gridBagConstraints3.gridy = 1; + GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); + gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints21.gridy = 2; + gridBagConstraints21.weightx = 1.0; + gridBagConstraints21.gridx = 1; + GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); + gridBagConstraints11.gridx = 0; + gridBagConstraints11.gridy = 2; + gridBagConstraints11.anchor = GridBagConstraints.WEST; + labelPassword = new JLabel(); + labelPassword.setText("Keystore's password:"); + labelPassword.setLabelFor(getTextPassword()); + GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); + gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints2.gridy = 1; + gridBagConstraints2.weightx = 1.0; + gridBagConstraints2.gridx = 1; + GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); + gridBagConstraints1.gridx = 0; + gridBagConstraints1.gridy = 1; + gridBagConstraints1.anchor = GridBagConstraints.WEST; + labelPath = new JLabel(); + labelPath.setText("Keystore path:"); + labelPath.setLabelFor(getTextPath()); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridwidth = 3; + gridBagConstraints.gridy = 0; + warning = new JLabel(); + warning.setText("WARNING: Password are stored in unsafe way"); + jContentPane = new JPanel(); + jContentPane.setLayout(new GridBagLayout()); + jContentPane.add(warning, gridBagConstraints); + jContentPane.add(labelPath, gridBagConstraints1); + jContentPane.add(getTextPath(), gridBagConstraints2); + jContentPane.add(labelPassword, gridBagConstraints11); + jContentPane.add(getTextPassword(), gridBagConstraints21); + jContentPane.add(getBrowse(), gridBagConstraints3); + GridBagConstraints gridBagConstraints22 = new GridBagConstraints(); + gridBagConstraints22.fill = GridBagConstraints.VERTICAL; + gridBagConstraints22.gridy = 3; + gridBagConstraints22.weightx = 1.0; + gridBagConstraints22.gridx = 1; + gridBagConstraints22.anchor = GridBagConstraints.EAST; + GridBagConstraints gridBagConstraints32 = new GridBagConstraints(); + gridBagConstraints32.gridy = 3; + gridBagConstraints32.gridx = 2; + gridBagConstraints32.anchor = GridBagConstraints.WEST; + jContentPane.add(getSave(), gridBagConstraints22); + jContentPane.add(getCancel(), gridBagConstraints32); + } + return jContentPane; + } + + /** + * This method initializes textPath + * + * @return javax.swing.JTextField + */ + private JTextField getTextPath() { + if (textPath == null) { + textPath = new JTextField(); + textPath.setText(pref.getKeystore_path()); + } + return textPath; + } + + /** + * This method initializes textPassword + * + * @return javax.swing.JPasswordField + */ + private JPasswordField getTextPassword() { + if (textPassword == null) { + textPassword = new JPasswordField(); + textPassword.setText(pref.getKeystore_pass()); + } + return textPassword; + } + + /** + * This method initializes browse + * + * @return javax.swing.JButton + */ + private JButton getBrowse() { + if (browse == null) { + browse = new JButton("Browse"); + //TODO: implement keystore browsing + browse.setEnabled(false); + } + return browse; + } + + /** + * This method initializes save + * + * @return javax.swing.JButton + */ + private JButton getSave() { + if (save == null) { + save = new JButton("Save"); + save.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + pref.setKeystore_pass(new String(textPassword.getPassword())); + pref.setKeystore_path(textPath.getText()); + dispose(); + } + }); + } + return save; + } + + /** + * This method initializes cancel + * + * @return javax.swing.JButton + */ + private JButton getCancel() { + if (cancel == null) { + cancel = new JButton("Cancel"); + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + } + return cancel; + } +} diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 src/org/abisso/PortableNotary/Notary.java --- a/src/org/abisso/PortableNotary/Notary.java Thu Jun 14 16:58:03 2007 +0200 +++ b/src/org/abisso/PortableNotary/Notary.java Thu Jun 14 18:41:45 2007 +0200 @@ -68,12 +68,6 @@ pwOut.printf(str,args); } - public static boolean check(String signed_doc){ - return check(PortableNotary.keystore_path, - signed_doc, - PortableNotary.password.toCharArray(), - PortableNotary.verbose); - } public static boolean check(String certdb, String signed_doc, char[] password, boolean verbose) { KeyStore kall; diff -r 2671a2d977f2900c96cf95d8226c7949957c6724 -r f0aa5d9d40e1b509746afb21bd3e4f0977025872 src/org/abisso/PortableNotary/PortableNotary.java --- a/src/org/abisso/PortableNotary/PortableNotary.java Thu Jun 14 16:58:03 2007 +0200 +++ b/src/org/abisso/PortableNotary/PortableNotary.java Thu Jun 14 18:41:45 2007 +0200 @@ -34,10 +34,6 @@ public static final short WRONG_PARAMS = 3; public static final String VERSION = "0.1alpha"; //$NON-NLS-1$ - static String file_path; - static String keystore_path; - static String password; - static boolean verbose; /** * @param args @@ -72,9 +68,9 @@ Preferences pref = Preferences.getIstance(); //my_usage(usage,options); - file_path = ""; //$NON-NLS-1$ - keystore_path = pref.getKeystore_path(); - password = pref.getKeystore_pass(); + String file_path = ""; //$NON-NLS-1$ + String keystore_path = pref.getKeystore_path(); + String password = pref.getKeystore_pass(); boolean verbose = false; try { // parse the command line arguments @@ -104,17 +100,12 @@ pref.setKeystore_pass(password); } - if (line.hasOption("P") ) { //$NON-NLS-1$ - System.out.println(Messages.getString("PortableNotary.OptionsSaved")); //$NON-NLS-1$ - System.out.println("keystore="+pref.getKeystore_path()); //$NON-NLS-1$ - System.out.println("password="+pref.getKeystore_pass()); //$NON-NLS-1$ - } - if (line.hasOption("p")) { //$NON-NLS-1$ //[ifdef] - password = System.console().readPassword( - Messages.getString("PortableNotary.EnterPassword")) - .toString(); //$NON-NLS-1$ + password = new String(System.console().readPassword( + Messages.getString("PortableNotary.EnterPassword"))); //$NON-NLS-1$ + if (save) + pref.setKeystore_pass(password); //[enddef] /* //[enddef] System.err.println(Messages.getString("PortableNotary.RequireJava6")); //$NON-NLS-1$ @@ -122,6 +113,12 @@ //[ifdef] */ } + if (line.hasOption("P") ) { //$NON-NLS-1$ + System.out.println(Messages.getString("PortableNotary.OptionsSaved")); //$NON-NLS-1$ + System.out.println("keystore="+pref.getKeystore_path()); //$NON-NLS-1$ + System.out.println("password="+pref.getKeystore_pass()); //$NON-NLS-1$ + } + if (!line.hasOption("t")) { MainFrame win = new MainFrame(); win.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); @@ -129,7 +126,8 @@ win.setVisible(true); } - else if (line.getArgs().length != 1 && !line.hasOption("P")) { //$NON-NLS-1$ + else if ( line.getArgs().length != 1 && + !line.hasOption("P") && !line.hasOption("S") ) { //$NON-NLS-1$ my_usage(usage, options); System.exit(WRONG_PARAMS_NUMBER); }else if (line.getArgs().length == 1){