From ddc3518c7264b21928a71c0a4a78fcbf03cc9fb5 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 27 Jul 2011 09:59:16 +0000 Subject: [PATCH] Removed unnecessary dialog preventing boolean/check. --- src/net/i2p/itoopie/gui/CertificateGUI.java | 181 +++++++++----------- 1 file changed, 83 insertions(+), 98 deletions(-) diff --git a/src/net/i2p/itoopie/gui/CertificateGUI.java b/src/net/i2p/itoopie/gui/CertificateGUI.java index a1b446240..742b2cb72 100644 --- a/src/net/i2p/itoopie/gui/CertificateGUI.java +++ b/src/net/i2p/itoopie/gui/CertificateGUI.java @@ -14,7 +14,6 @@ import net.i2p.itoopie.security.CertificateHelper; import net.i2p.itoopie.security.CertificateManager; public class CertificateGUI { - private static boolean isVerifying = false; public static void main(String[] args){ System.out.println("Save new cert: " + saveNewCert(null,null)); @@ -22,52 +21,45 @@ public class CertificateGUI { } public static synchronized boolean saveNewCert(String hostname, X509Certificate cert){ - if (!isVerifying){ - isVerifying = true; - JFrame frame = new JFrame(); - frame.setLayout(new BorderLayout()); - JButton bt = new JButton(); - bt.setText("text"); - frame.add(bt, BorderLayout.NORTH); - - String title = Transl._("New remote host detected"); - String hostString = Transl._("Would you like permanently trust the certificate from the remote host " + hostname + "?"); - - String certName = "N/A"; - String certAlgo = "N/A"; - String certSerial = "N/A"; - String certThumb = "N/A"; - if (cert != null){ - certName = cert.getSubjectDN().getName(); - String certString = cert.getPublicKey().toString(); - certAlgo = certString.substring(0,certString.indexOf("\n")); - certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); - certThumb = CertificateHelper.getThumbPrint(cert); - } - String certInfo = ""+Transl._("Certificate info") + "

" + - Transl._("Name: ") + certName + "
" + - Transl._("Algorithm: ") + certAlgo + "
" + - Transl._("Serial: ") + certSerial + "
" + - Transl._("SHA-1 ID-hash: ") + certThumb; - - String textContent = certInfo + "

" + hostString; - - int n = JOptionPane.showConfirmDialog( - frame, - textContent, - title, - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE); - - if (n == JOptionPane.YES_OPTION){ - CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); - updateUI(); - isVerifying = false; - return true; - } else { - isVerifying = false; - return false; - } + JFrame frame = new JFrame(); + frame.setLayout(new BorderLayout()); + JButton bt = new JButton(); + bt.setText("text"); + frame.add(bt, BorderLayout.NORTH); + + String title = Transl._("New remote host detected"); + String hostString = Transl._("Would you like permanently trust the certificate from the remote host " + hostname + "?"); + + String certName = "N/A"; + String certAlgo = "N/A"; + String certSerial = "N/A"; + String certThumb = "N/A"; + if (cert != null){ + certName = cert.getSubjectDN().getName(); + String certString = cert.getPublicKey().toString(); + certAlgo = certString.substring(0,certString.indexOf("\n")); + certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); + certThumb = CertificateHelper.getThumbPrint(cert); + } + String certInfo = ""+Transl._("Certificate info") + "

" + + Transl._("Name: ") + certName + "
" + + Transl._("Algorithm: ") + certAlgo + "
" + + Transl._("Serial: ") + certSerial + "
" + + Transl._("SHA-1 ID-hash: ") + certThumb; + + String textContent = certInfo + "

" + hostString; + + int n = JOptionPane.showConfirmDialog( + frame, + textContent, + title, + JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE); + + if (n == JOptionPane.YES_OPTION){ + CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); + updateUI(); + return true; } else { return false; } @@ -75,61 +67,54 @@ public class CertificateGUI { public static boolean overwriteCert(String hostname, X509Certificate cert){ - if (!isVerifying){ - isVerifying = true; - JFrame frame = new JFrame(); - - String title = Transl._("Warning, new remote host detected"); - String hostString = Transl._("The certificate of " + hostname + " has changed!
" + - "Are you sure you like permanently trust the new certificate from the remote host?"); - - String certName = "N/A"; - String certAlgo = "N/A"; - String certSerial = "N/A"; - String certThumb = "N/A"; - if (cert != null){ - certName = cert.getSubjectDN().getName(); - String certString = cert.getPublicKey().toString(); - certAlgo = certString.substring(0,certString.indexOf("\n")); - certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); - certThumb = CertificateHelper.getThumbPrint(cert); - } - String certInfo = ""+Transl._("Certificate info") + "

" + - Transl._("Name: ") + certName + "
" + - Transl._("Algorithm: ") + certAlgo + "
" + - Transl._("Serial: ") + certSerial + "
" + - Transl._("SHA-1 ID-hash: ") + certThumb; - - String textContent = certInfo + "

" + hostString; - - int n = JOptionPane.showConfirmDialog( - frame, - textContent, - title, - JOptionPane.YES_NO_OPTION, - JOptionPane.WARNING_MESSAGE); - + JFrame frame = new JFrame(); + + String title = Transl._("Warning, new remote host detected"); + String hostString = Transl._("The certificate of " + hostname + " has changed!
" + + "Are you sure you like permanently trust the new certificate from the remote host?"); + + String certName = "N/A"; + String certAlgo = "N/A"; + String certSerial = "N/A"; + String certThumb = "N/A"; + if (cert != null){ + certName = cert.getSubjectDN().getName(); + String certString = cert.getPublicKey().toString(); + certAlgo = certString.substring(0,certString.indexOf("\n")); + certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); + certThumb = CertificateHelper.getThumbPrint(cert); + } + String certInfo = ""+Transl._("Certificate info") + "

" + + Transl._("Name: ") + certName + "
" + + Transl._("Algorithm: ") + certAlgo + "
" + + Transl._("Serial: ") + certSerial + "
" + + Transl._("SHA-1 ID-hash: ") + certThumb; + + String textContent = certInfo + "

" + hostString; + + int n = JOptionPane.showConfirmDialog( + frame, + textContent, + title, + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE); + + if (n == JOptionPane.YES_OPTION){ + n = JOptionPane.showConfirmDialog( + frame, + Transl._("Are you sure that you trust the new certificate?"), + Transl._("Is that you final answer?"), + JOptionPane.YES_NO_OPTION, + JOptionPane.ERROR_MESSAGE); if (n == JOptionPane.YES_OPTION){ - n = JOptionPane.showConfirmDialog( - frame, - Transl._("Are you sure that you trust the new certificate?"), - Transl._("Is that you final answer?"), - JOptionPane.YES_NO_OPTION, - JOptionPane.ERROR_MESSAGE); - if (n == JOptionPane.YES_OPTION){ - CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); - updateUI(); - isVerifying = false; - return true; // Confirmation positive - } else { - isVerifying = false; - return false; // Confirmation negative - } + CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); + updateUI(); + return true; // Confirmation positive } else { - return false; // No + return false; // Confirmation negative } } else { - return false; + return false; // No } }