/** Creates new form ViewStatusFrame. */
public ViewCertificateFrame(final List<X509Certificate> certificates) {
this.certificate = certificates.get(0);
initComponents();
chainList.setModel(new AbstractListModel() {
@Override
public int getSize() {
return certificates.size();
}
@Override
public Object getElementAt(int index) {
return certificates.get(index);
}
});
chainList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
if (value instanceof X509Certificate) {
final X509Certificate cert = (X509Certificate) value;
value = cert.getSubjectDN().getName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
chainList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent evt) {
if (!evt.getValueIsAdjusting()) {
viewCertificate((X509Certificate)
chainList.getSelectedValue());
}
}
});
fieldsList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
if (value instanceof Field) {
value = ((Field) value).getName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
fieldsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent evt) {
if (!evt.getValueIsAdjusting()) {
viewFieldValue((Field) fieldsList.getSelectedValue());
}
}
});
subjectTextArea.setText(certificate.getSubjectDN().getName());
issuerTextArea.setText(certificate.getIssuerDN().getName());
serialNumberLabel.setText(String.valueOf(
certificate.getSerialNumber()));
notBeforeLabel.setText(String.valueOf(certificate.getNotBefore()));
notAfterLabel.setText(String.valueOf(certificate.getNotAfter()));
String fingerprint = "";
try {
fingerprint = calcFingerprint(certificate.getEncoded());
} catch (CertificateEncodingException ex) {
LOG.error("Error calculating certificate fingerprint", ex);
}
fingerprintLabel.setText(fingerprint);
usages = new ArrayList<String>();
boolean[] keyUsages = certificate.getKeyUsage();
// digitalSignature (0),
if (keyUsages[0]) {
usages.add("digitalSignature");
}
// nonRepudiation (1),
if (keyUsages[1]) {
usages.add("nonRepudiation");
}
// keyEncipherment (2),
if (keyUsages[2]) {
usages.add("keyEncipherment");
}
// dataEncipherment (3),
if (keyUsages[3]) {
usages.add("dataEncipherment");
}
// keyAgreement (4),
if (keyUsages[4]) {
usages.add("keyAgreement");
}
// keyCertSign (5),
if (keyUsages[5]) {
usages.add("keyCertSign");
}
// cRLSign (6),
if (keyUsages[6]) {
usages.add("cRLSign");
}
// encipherOnly (7),
if (keyUsages[7]) {
usages.add("encipherOnly");
}
// decipherOnly
if (keyUsages[8]) {
usages.add("decipherOnly");
}
try {
final List<String> eku = certificate.getExtendedKeyUsage();
if (eku != null) {
usages.addAll(eku);
}
} catch (CertificateParsingException ex) {
LOG.error("Error getting extended key usage", ex);
}
usagesList.setModel(new AbstractListModel() {
@Override
public int getSize() {
return usages.size();
}