mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
Add indication that certificate expired or not yet valid in configurable and certificate info panel
This commit is contained in:
@@ -51,8 +51,11 @@ public class CertificateConfigurable implements SearchableConfigurable, Configur
|
||||
myCertificatesList.getEmptyText().setText("No certificates");
|
||||
myCertificatesList.setCellRenderer(new ListCellRendererWrapper<X509Certificate>() {
|
||||
@Override
|
||||
public void customize(JList list, X509Certificate value, int index, boolean selected, boolean hasFocus) {
|
||||
setText(new CertificateWrapper(value).getSubjectField(COMMON_NAME));
|
||||
public void customize(JList list, X509Certificate certificate, int index, boolean selected, boolean hasFocus) {
|
||||
if (!new CertificateWrapper(certificate).isValid()) {
|
||||
setForeground(UIUtil.getLabelDisabledForeground());
|
||||
}
|
||||
setText(new CertificateWrapper(certificate).getSubjectField(COMMON_NAME));
|
||||
}
|
||||
});
|
||||
// fill lower panel with cards
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.intellij.util.net.ssl;
|
||||
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,16 +34,20 @@ public class CertificateInfoPanel extends JPanel {
|
||||
builder = updateBuilderWithTitle(builder, "Issued By");
|
||||
builder = updateBuilderWithPrincipalData(builder, myCertificateWrapper.getIssuerFields());
|
||||
builder = updateBuilderWithTitle(builder, "Validity Period");
|
||||
String notBefore = DATE_FORMAT.format(myCertificateWrapper.getNotBefore());
|
||||
String notAfter = DATE_FORMAT.format(myCertificateWrapper.getNotAfter());
|
||||
builder = builder
|
||||
.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT)
|
||||
.addLabeledComponent("Valid from:", new JBLabel(DATE_FORMAT.format(myCertificateWrapper.getNotBefore())))
|
||||
.addLabeledComponent("Valid until:", new JBLabel(DATE_FORMAT.format(myCertificateWrapper.getNotAfter())));
|
||||
.addLabeledComponent("Valid from:", createColoredComponent(notBefore, "not yet valid", myCertificateWrapper.isNotYetValid()))
|
||||
.addLabeledComponent("Valid until:", createColoredComponent(notAfter, "expired", myCertificateWrapper.isExpired()));
|
||||
builder = builder.setIndent(0);
|
||||
builder = updateBuilderWithTitle(builder, "Fingerprints");
|
||||
builder = builder.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT);
|
||||
builder = builder.addLabeledComponent("SHA-256:", getTextPane(formatHex(myCertificateWrapper.getSha256Fingerprint())));
|
||||
builder = builder.addLabeledComponent("SHA-1:", getTextPane(formatHex(myCertificateWrapper.getSha1Fingerprint())));
|
||||
add(builder.getPanel(), BorderLayout.NORTH);
|
||||
|
||||
SimpleColoredComponent component = new SimpleColoredComponent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -94,4 +97,14 @@ public class CertificateInfoPanel extends JPanel {
|
||||
//Messages.installHyperlinkSupport(pane);
|
||||
return pane;
|
||||
}
|
||||
|
||||
private static JComponent createColoredComponent(String mainText, String errorText, boolean hasError) {
|
||||
SimpleColoredComponent component = new SimpleColoredComponent();
|
||||
if (hasError) {
|
||||
component.append(mainText + " (" + errorText + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.RED));
|
||||
} else {
|
||||
component.append(mainText);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,10 @@ public class CertificateWrapper {
|
||||
|
||||
/**
|
||||
* Check whether certificate is valid. It's considered invalid it it either expired or
|
||||
* not yet legal.
|
||||
* not yet valid.
|
||||
*
|
||||
* @see #isExpired()
|
||||
* @see #isNotYetValid()
|
||||
*/
|
||||
public boolean isValid() {
|
||||
try {
|
||||
@@ -92,6 +95,14 @@ public class CertificateWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return new Date().getTime() > myCertificate.getNotAfter().getTime();
|
||||
}
|
||||
|
||||
public boolean isNotYetValid() {
|
||||
return new Date().getTime() < myCertificate.getNotBefore().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether certificate is self-signed. It's considered self-signed if
|
||||
* its issuer and subject are the same.
|
||||
|
||||
Reference in New Issue
Block a user