Removed unnecessary dialog preventing boolean/check.

This commit is contained in:
dev
2011-07-27 09:59:16 +00:00
parent 5dfe3f9052
commit ddc3518c72

View File

@ -14,7 +14,6 @@ import net.i2p.itoopie.security.CertificateHelper;
import net.i2p.itoopie.security.CertificateManager; import net.i2p.itoopie.security.CertificateManager;
public class CertificateGUI { public class CertificateGUI {
private static boolean isVerifying = false;
public static void main(String[] args){ public static void main(String[] args){
System.out.println("Save new cert: " + saveNewCert(null,null)); 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){ public static synchronized boolean saveNewCert(String hostname, X509Certificate cert){
if (!isVerifying){ JFrame frame = new JFrame();
isVerifying = true; frame.setLayout(new BorderLayout());
JFrame frame = new JFrame(); JButton bt = new JButton();
frame.setLayout(new BorderLayout()); bt.setText("text");
JButton bt = new JButton(); frame.add(bt, BorderLayout.NORTH);
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 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 certName = "N/A"; String certSerial = "N/A";
String certAlgo = "N/A"; String certThumb = "N/A";
String certSerial = "N/A"; if (cert != null){
String certThumb = "N/A"; certName = cert.getSubjectDN().getName();
if (cert != null){ String certString = cert.getPublicKey().toString();
certName = cert.getSubjectDN().getName(); certAlgo = certString.substring(0,certString.indexOf("\n"));
String certString = cert.getPublicKey().toString(); certSerial = String.valueOf(cert.getPublicKey().serialVersionUID);
certAlgo = certString.substring(0,certString.indexOf("\n")); certThumb = CertificateHelper.getThumbPrint(cert);
certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); }
certThumb = CertificateHelper.getThumbPrint(cert); String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" +
} Transl._("Name: ") + certName + "<br>" +
String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" + Transl._("Algorithm: ") + certAlgo + "<br>" +
Transl._("Name: ") + certName + "<br>" + Transl._("Serial: ") + certSerial + "<br>" +
Transl._("Algorithm: ") + certAlgo + "<br>" + Transl._("SHA-1 ID-hash: ") + certThumb;
Transl._("Serial: ") + certSerial + "<br>" +
Transl._("SHA-1 ID-hash: ") + certThumb; String textContent = certInfo + "<br><br>" + hostString;
String textContent = certInfo + "<br><br>" + hostString; int n = JOptionPane.showConfirmDialog(
frame,
int n = JOptionPane.showConfirmDialog( textContent,
frame, title,
textContent, JOptionPane.YES_NO_OPTION,
title, JOptionPane.INFORMATION_MESSAGE);
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE); if (n == JOptionPane.YES_OPTION){
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert));
if (n == JOptionPane.YES_OPTION){ updateUI();
CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert)); return true;
updateUI();
isVerifying = false;
return true;
} else {
isVerifying = false;
return false;
}
} else { } else {
return false; return false;
} }
@ -75,61 +67,54 @@ public class CertificateGUI {
public static boolean overwriteCert(String hostname, X509Certificate cert){ public static boolean overwriteCert(String hostname, X509Certificate cert){
if (!isVerifying){ JFrame frame = new JFrame();
isVerifying = true;
JFrame frame = new JFrame(); String title = Transl._("Warning, new remote host detected");
String hostString = Transl._("The certificate of " + hostname + " has changed! <br>" +
String title = Transl._("Warning, new remote host detected"); "Are you sure you like permanently trust the new certificate from the remote host?");
String hostString = Transl._("The certificate of " + hostname + " has changed! <br>" +
"Are you sure you like permanently trust the new certificate from the remote host?"); String certName = "N/A";
String certAlgo = "N/A";
String certName = "N/A"; String certSerial = "N/A";
String certAlgo = "N/A"; String certThumb = "N/A";
String certSerial = "N/A"; if (cert != null){
String certThumb = "N/A"; certName = cert.getSubjectDN().getName();
if (cert != null){ String certString = cert.getPublicKey().toString();
certName = cert.getSubjectDN().getName(); certAlgo = certString.substring(0,certString.indexOf("\n"));
String certString = cert.getPublicKey().toString(); certSerial = String.valueOf(cert.getPublicKey().serialVersionUID);
certAlgo = certString.substring(0,certString.indexOf("\n")); certThumb = CertificateHelper.getThumbPrint(cert);
certSerial = String.valueOf(cert.getPublicKey().serialVersionUID); }
certThumb = CertificateHelper.getThumbPrint(cert); String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" +
} Transl._("Name: ") + certName + "<br>" +
String certInfo = "<html>"+Transl._("Certificate info") + "<br><br>" + Transl._("Algorithm: ") + certAlgo + "<br>" +
Transl._("Name: ") + certName + "<br>" + Transl._("Serial: ") + certSerial + "<br>" +
Transl._("Algorithm: ") + certAlgo + "<br>" + Transl._("SHA-1 ID-hash: ") + certThumb;
Transl._("Serial: ") + certSerial + "<br>" +
Transl._("SHA-1 ID-hash: ") + certThumb; String textContent = certInfo + "<br><br>" + hostString;
String textContent = certInfo + "<br><br>" + hostString; int n = JOptionPane.showConfirmDialog(
frame,
int n = JOptionPane.showConfirmDialog( textContent,
frame, title,
textContent, JOptionPane.YES_NO_OPTION,
title, JOptionPane.WARNING_MESSAGE);
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){ if (n == JOptionPane.YES_OPTION){
n = JOptionPane.showConfirmDialog( CertificateManager.forcePutServerCert(hostname, CertificateHelper.convert(cert));
frame, updateUI();
Transl._("Are you sure that you trust the new certificate?"), return true; // Confirmation positive
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
}
} else { } else {
return false; // No return false; // Confirmation negative
} }
} else { } else {
return false; return false; // No
} }
} }