diff --git a/src/net/java/sip/communicator/plugin/desktoputil/VerifyCertificateDialogImpl.java b/src/net/java/sip/communicator/plugin/desktoputil/VerifyCertificateDialogImpl.java index 71b6c68ad..ed09959e3 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/VerifyCertificateDialogImpl.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/VerifyCertificateDialogImpl.java @@ -9,7 +9,6 @@ import java.awt.*; import java.awt.event.*; import java.security.cert.*; -import java.util.*; import javax.swing.*; import javax.swing.border.*; @@ -53,10 +52,9 @@ class VerifyCertificateDialogImpl private static final int MAX_MSG_PANE_HEIGHT = 800; /** - * The certificate to show. + * The certificates to show. */ - Certificate cert; - java.util.List certs; + Certificate[] certs; /** * A text that describes why the verification failed. @@ -113,16 +111,7 @@ public VerifyCertificateDialogImpl(Certificate[] certs, R.getI18NString("service.gui.CERT_DIALOG_TITLE")); setModal(true); - this.certs = new ArrayList(); - for (Certificate certificate : certs) - { - if (certificate instanceof X509Certificate) { - this.certs.add((X509Certificate) certificate); - } - } - // for now shows only the first certificate from the chain for - // non X.509 certificates - this.cert = certs[0]; + this.certs = certs; this.message = message; setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); @@ -239,33 +228,7 @@ private void actionShowCertificate() certPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); certPanel.add(alwaysTrustCheckBox, BorderLayout.NORTH); - Component certInfoPane = null; - if (!certs.isEmpty()) - { - certInfoPane = new X509CertificatePanel( - certs.toArray(new X509Certificate[0])); - } - else - { - JTextArea textArea = new JTextArea(); - textArea.setOpaque(false); - textArea.setEditable(false); - textArea.setText(cert.toString()); - - final JScrollPane certScroll = new JScrollPane(certInfoPane); - certScroll.setPreferredSize(new Dimension(300, 300)); - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - certScroll.getVerticalScrollBar().setValue(0); - } - }); - - certInfoPane = certScroll; - } - certPanel.add(certInfoPane, BorderLayout.CENTER); + certPanel.add(new X509CertificatePanel(certs), BorderLayout.CENTER); certButton.setText(R.getI18NString("service.gui.HIDE_CERT")); diff --git a/src/net/java/sip/communicator/plugin/desktoputil/ViewCertificateFrame.java b/src/net/java/sip/communicator/plugin/desktoputil/ViewCertificateFrame.java index 3c2d9d55e..943a20401 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/ViewCertificateFrame.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/ViewCertificateFrame.java @@ -8,7 +8,6 @@ import java.awt.*; import java.security.cert.*; -import java.util.*; import javax.swing.*; import org.jitsi.service.resources.*; @@ -123,41 +122,8 @@ private void init() this.getContentPane().add(contentPane, BorderLayout.CENTER); - Component certInfoPane; - if (certs[0] instanceof X509Certificate) - { - ArrayList x509s = new ArrayList(); - for (Certificate c : certs) - { - if (c instanceof X509Certificate) - { - x509s.add(c); - } - } - certInfoPane = new X509CertificatePanel( - (X509Certificate[]) x509s.toArray(new X509Certificate[0])); - } - else - { - JTextArea textArea = new JTextArea(); - textArea.setOpaque(false); - textArea.setEditable(false); - // for now shows only the first certificate from the chain - textArea.setText(certs[0].toString()); - certInfoPane = textArea; - } - - final JScrollPane certScroll = new JScrollPane(certInfoPane); - certScroll.setPreferredSize(new Dimension(300, 600)); - certPanel.add(certScroll, BorderLayout.CENTER); - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - certScroll.getVerticalScrollBar().setValue(0); - } - }); + certPanel.add(new X509CertificatePanel(certs), BorderLayout.CENTER); + setPreferredSize(null); pack(); diff --git a/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java b/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java index 630487fe4..ff4865113 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java @@ -9,6 +9,7 @@ import java.awt.*; import java.security.*; import java.security.cert.*; +import java.security.cert.Certificate; import java.security.interfaces.*; import java.util.*; @@ -44,9 +45,9 @@ public class X509CertificatePanel * * @param certificate X509Certificate object */ - public X509CertificatePanel(X509Certificate certificate) + public X509CertificatePanel(Certificate certificate) { - this(new X509Certificate[] + this(new Certificate[] { certificate }); @@ -57,7 +58,7 @@ public X509CertificatePanel(X509Certificate certificate) * * @param certificates X509Certificate objects */ - public X509CertificatePanel(X509Certificate[] certificates) + public X509CertificatePanel(Certificate[] certificates) { setLayout(new BorderLayout(5, 5)); @@ -71,7 +72,7 @@ public X509CertificatePanel(X509Certificate[] certificates) DefaultMutableTreeNode previous = top; for (int i = certificates.length - 1; i >= 0; i--) { - X509Certificate cert = certificates[i]; + Certificate cert = certificates[i]; DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert); previous.add(next); previous = next; @@ -100,6 +101,17 @@ public Component getTreeCellRendererComponent(JTree tree, component.setText( getSimplifiedName((X509Certificate) o)); } + else + { + // We don't know how to represent this certificate type, + // let's use the first 20 characters + String text = o.toString(); + if (text.length() > 20) + { + text = text.substring(0, 20); + } + component.setText(text); + } } return component; } @@ -146,13 +158,42 @@ public void valueChanged(TreeSelectionEvent e) add(certScroll, BorderLayout.CENTER); } - private String toString(X509Certificate certificate) + /** + * Creates a String representation of the given object. + * @param certificate to print + * @return the String representation + */ + private String toString(Object certificate) { final StringBuilder sb = new StringBuilder(); + sb.append("\n"); + + if (certificate instanceof X509Certificate) + { + renderX509(sb, (X509Certificate) certificate); + } + else + { + sb.append("
\n");
+            sb.append(certificate.toString());
+            sb.append("
\n"); + } + + sb.append(""); + return sb.toString(); + } + + /** + * Appends an HTML representation of the given X509Certificate. + * @param sb StringBuilder to append to + * @param certificate to print + */ + private void renderX509(StringBuilder sb, X509Certificate certificate) + { X500Principal issuer = certificate.getIssuerX500Principal(); X500Principal subject = certificate.getSubjectX500Principal(); - sb.append("\n"); + sb.append("
\n"); // subject addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO")); @@ -300,9 +341,7 @@ else if(certificate.getPublicKey().getAlgorithm().equals("DSA")) getHex(certificate.getSignature()) })); - sb.append("
"); - - return sb.toString(); + sb.append("\n"); } /** @@ -448,11 +487,7 @@ private void valueChangedPerformed(TreeSelectionEvent e) if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; - if (node.getUserObject() instanceof X509Certificate) - { - infoTextPane.setText( - toString((X509Certificate) node.getUserObject())); - } + infoTextPane.setText(toString(node.getUserObject())); } } }