Initial plumbing for improved certificate panel.

fix-message-formatting
Markus Kilås 11 years ago
parent 675b056130
commit e51decb08d

@ -9,8 +9,10 @@
import java.awt.*;
import java.awt.event.*;
import java.security.cert.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.util.*;
@ -54,6 +56,7 @@ class VerifyCertificateDialogImpl
* The certificate to show.
*/
Certificate cert;
java.util.List<X509Certificate> certs;
/**
* A text that describes why the verification failed.
@ -110,7 +113,15 @@ public VerifyCertificateDialogImpl(Certificate[] certs,
R.getI18NString("service.gui.CERT_DIALOG_TITLE"));
setModal(true);
// for now shows only the first certificate from the chain
this.certs = new ArrayList<X509Certificate>();
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.message = message;
@ -224,13 +235,14 @@ private void actionShowCertificate()
return;
}
certPanel.setLayout(new BorderLayout());
certPanel.setLayout(new BorderLayout(5, 5));
certPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
certPanel.add(alwaysTrustCheckBox, BorderLayout.NORTH);
Component certInfoPane = null;
if(cert instanceof X509Certificate)
if (!certs.isEmpty())
{
certInfoPane = new X509CertificatePanel((X509Certificate)cert);
certInfoPane = new X509CertificatePanel(certs);
}
else
{
@ -238,20 +250,21 @@ private void actionShowCertificate()
textArea.setOpaque(false);
textArea.setEditable(false);
textArea.setText(cert.toString());
certInfoPane = textArea;
}
final JScrollPane certScroll = new JScrollPane(certInfoPane);
certScroll.setPreferredSize(new Dimension(300, 300));
certPanel.add(certScroll, BorderLayout.CENTER);
final JScrollPane certScroll = new JScrollPane(certInfoPane);
certScroll.setPreferredSize(new Dimension(300, 300));
SwingUtilities.invokeLater(new Runnable()
{
public void run()
SwingUtilities.invokeLater(new Runnable()
{
certScroll.getVerticalScrollBar().setValue(0);
}
});
public void run()
{
certScroll.getVerticalScrollBar().setValue(0);
}
});
certInfoPane = certScroll;
}
certPanel.add(certInfoPane, BorderLayout.CENTER);
certButton.setText(R.getI18NString("service.gui.HIDE_CERT"));

@ -8,6 +8,7 @@
import java.awt.*;
import java.security.cert.*;
import java.util.Arrays;
import javax.swing.*;
import org.jitsi.service.resources.*;
@ -39,9 +40,9 @@ public class ViewCertificateFrame
private static final int MAX_MSG_PANE_HEIGHT = 800;
/**
* The certificate to show.
* The certificates to show.
*/
Certificate cert;
Certificate[] certs;
/**
* A text that describes why the verification failed.
@ -74,8 +75,7 @@ public ViewCertificateFrame(Certificate[] certs,
setTitle(title != null ? title :
R.getI18NString("service.gui.CERT_DIALOG_TITLE"));
// for now shows only the first certificate from the chain
this.cert = certs[0];
this.certs = certs;
this.message = message;
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
@ -124,16 +124,17 @@ private void init()
this.getContentPane().add(contentPane, BorderLayout.CENTER);
Component certInfoPane;
if(cert instanceof X509Certificate)
if(certs[0] instanceof X509Certificate)
{
certInfoPane = new X509CertificatePanel((X509Certificate)cert);
certInfoPane = new X509CertificatePanel(Arrays.asList((X509Certificate[])certs));
}
else
{
JTextArea textArea = new JTextArea();
textArea.setOpaque(false);
textArea.setEditable(false);
textArea.setText(cert.toString());
// for now shows only the first certificate from the chain
textArea.setText(certs[0].toString());
certInfoPane = textArea;
}

@ -29,11 +29,24 @@ public class X509CertificatePanel
private static final long serialVersionUID = -8368302061995971947L;
/**
* Constructs a X509 certificate panel.
* Constructs a X509 certificate panel from a single certificate.
* If a chain is available instead use the second constructor.
* This constructor is kept for backwards compatibility and for convenience
* when there is only one certificate of interest.
*
* @param certificate <tt>X509Certificate</tt> object
*/
public X509CertificatePanel(X509Certificate certificate)
{
this(Arrays.asList(certificate));
}
/**
* Constructs a X509 certificate panel.
*
* @param certificates <tt>X509Certificate</tt> objects
*/
public X509CertificatePanel(java.util.List<X509Certificate> certificates)
{
ResourceManagementService R = DesktopUtilActivator.getResources();
DateFormat dateFormatter
@ -55,6 +68,7 @@ public X509CertificatePanel(X509Certificate certificate)
constraints.weighty = 0;
constraints.gridy = currentRow++;
X509Certificate certificate = certificates.get(0);
X500Principal issuer = certificate.getIssuerX500Principal();
X500Principal subject = certificate.getSubjectX500Principal();

Loading…
Cancel
Save