mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Move all certificate related classes in com.intellij.util.net.ssl package. Update appearance of certificate warning dialog.
This commit is contained in:
-169
@@ -1,169 +0,0 @@
|
||||
package com.intellij.util.net;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.openapi.util.Pair.create;
|
||||
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
public class UntrustedCertificateWarningDialog extends DialogWrapper {
|
||||
private static final Logger LOG = Logger.getInstance(UntrustedCertificateWarningDialog.class);
|
||||
private static DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||
|
||||
private static final Map<String, String> FIELD_ABBREVIATIONS = ContainerUtil.newHashMap(
|
||||
create("CN", "Common Name"),
|
||||
create("O", "Organization"),
|
||||
create("OU", "Organizational Unit"),
|
||||
create("L", "Location"),
|
||||
create("C", "Country"),
|
||||
create("ST", "State")
|
||||
);
|
||||
|
||||
private JPanel myRootPanel;
|
||||
private JLabel myWarningSign;
|
||||
private JPanel myCertificateInfoPanel;
|
||||
private JTextPane myNoticePane;
|
||||
private final X509Certificate myCertificate;
|
||||
private final String myPath, myPassword;
|
||||
|
||||
public UntrustedCertificateWarningDialog(@NotNull X509Certificate certificate, @NotNull String storePath, @NotNull String password) {
|
||||
super((Project)null, false);
|
||||
|
||||
myCertificate = certificate;
|
||||
myPath = FileUtil.toCanonicalPath(storePath);
|
||||
|
||||
myPassword = password;
|
||||
|
||||
FormBuilder builder = FormBuilder.createFormBuilder();
|
||||
|
||||
// I'm not using separate panels and form builders to preserve alignment of labels
|
||||
builder = updateBuilderWithTitle(builder, "Issued To");
|
||||
builder = updateBuilderWithPrincipalData(builder, myCertificate.getSubjectX500Principal());
|
||||
builder = updateBuilderWithTitle(builder, "Issued By");
|
||||
builder = updateBuilderWithPrincipalData(builder, myCertificate.getIssuerX500Principal());
|
||||
builder = updateBuilderWithTitle(builder, "Validity Period");
|
||||
builder = builder
|
||||
.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT)
|
||||
.addLabeledComponent("Valid from:", new JBLabel(DATE_FORMAT.format(myCertificate.getNotBefore())))
|
||||
.addLabeledComponent("Valid until:", new JBLabel(DATE_FORMAT.format(myCertificate.getNotAfter())));
|
||||
builder = builder.setIndent(0);
|
||||
builder = updateBuilderWithTitle(builder, "Fingerprints");
|
||||
builder = builder.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT);
|
||||
builder = builder.addLabeledComponent("SHA-256:", getTextPane(getSHA256FingerPrint(certificate)));
|
||||
builder = builder.addLabeledComponent("SHA-1:", getTextPane(getSHA1FingerPrint(certificate)));
|
||||
myCertificateInfoPanel.add(builder.getPanel(), BorderLayout.CENTER);
|
||||
|
||||
setTitle("Untrusted Server's Certificate");
|
||||
setOKButtonText("Accept");
|
||||
setCancelButtonText("Reject");
|
||||
myWarningSign.setIcon(AllIcons.General.WarningDialog);
|
||||
|
||||
Messages.installHyperlinkSupport(myNoticePane);
|
||||
// myNoticePane.setFont(myNoticePane.getFont().deriveFont((float)FontSize.SMALL.getSize()));
|
||||
myNoticePane.setText(
|
||||
String.format("<html><p><small>" +
|
||||
"Accepted certificate will be saved in truststore <code>%s</code> with password <code>%s</code>" +
|
||||
"</small></p><html>",
|
||||
myPath, myPassword));
|
||||
|
||||
init();
|
||||
LOG.debug("Preferred size: " + getPreferredSize());
|
||||
}
|
||||
|
||||
private static String getSHA1FingerPrint(X509Certificate certificate) {
|
||||
try {
|
||||
return formatHex(DigestUtils.sha1Hex(certificate.getEncoded()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSHA256FingerPrint(X509Certificate certificate) {
|
||||
try {
|
||||
return formatHex(DigestUtils.sha256Hex(certificate.getEncoded()));
|
||||
}
|
||||
catch (CertificateEncodingException e) {
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String formatHex(@NotNull String hex) {
|
||||
StringBuilder builder = new StringBuilder((int)(hex.length() * 1.5));
|
||||
for (int i = 0; i < hex.length(); i += 2) {
|
||||
builder.append(hex.substring(i, i + 2));
|
||||
builder.append(' ');
|
||||
if (builder.length() % 60 == 0) {
|
||||
builder.append('\n');
|
||||
}
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
|
||||
private static JComponent getTextPane(String text) {
|
||||
JTextPane pane = new JTextPane();
|
||||
pane.setOpaque(false);
|
||||
pane.setEditable(false);
|
||||
pane.setContentType("text/plain");
|
||||
pane.setText(text);
|
||||
//Messages.installHyperlinkSupport(pane);
|
||||
return pane;
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
private FormBuilder updateBuilderWithPrincipalData(FormBuilder builder, X500Principal principal) {
|
||||
builder = builder.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT);
|
||||
for (String field : principal.getName().split(",")) {
|
||||
field = field.trim();
|
||||
String[] parts = field.split("=", 2);
|
||||
if (parts.length != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = parts[0];
|
||||
String value = parts[1];
|
||||
|
||||
String longName = FIELD_ABBREVIATIONS.get(name.toUpperCase());
|
||||
if (longName == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
builder = builder.addLabeledComponent(String.format("<html>%s (<b>%s</b>)</html>", longName, name), new JBLabel(value));
|
||||
}
|
||||
return builder.setIndent(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
private FormBuilder updateBuilderWithTitle(FormBuilder builder, String title) {
|
||||
return builder.addComponent(new TitledSeparator(title), IdeBorderFactory.TITLED_BORDER_TOP_INSET);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myRootPanel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.net.ssl.CertificateInfo">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.intellij.util.net.ssl;
|
||||
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.util.net.ssl.CertificateWrapper.CommonField;
|
||||
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
public class CertificateInfo {
|
||||
private static DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
|
||||
private JPanel myPanel;
|
||||
private final CertificateWrapper myCertificateWrapper;
|
||||
|
||||
public CertificateInfo(@NotNull X509Certificate certificate) {
|
||||
myCertificateWrapper = new CertificateWrapper(certificate);
|
||||
|
||||
FormBuilder builder = FormBuilder.createFormBuilder();
|
||||
|
||||
// I'm not using separate panels and form builders to preserve alignment of labels
|
||||
builder = updateBuilderWithTitle(builder, "Issued To");
|
||||
builder = updateBuilderWithPrincipalData(builder, myCertificateWrapper.getSubjectFields());
|
||||
builder = updateBuilderWithTitle(builder, "Issued By");
|
||||
builder = updateBuilderWithPrincipalData(builder, myCertificateWrapper.getIssuerFields());
|
||||
builder = updateBuilderWithTitle(builder, "Validity Period");
|
||||
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())));
|
||||
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())));
|
||||
myPanel.add(builder.getPanel(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String formatHex(@NotNull String hex) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < hex.length(); i += 2) {
|
||||
// split at 16th byte
|
||||
if (i == 32) {
|
||||
builder.append('\n');
|
||||
}
|
||||
builder.append(hex.substring(i, i + 2));
|
||||
builder.append(' ');
|
||||
}
|
||||
if (hex.length() > 0) {
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public X509Certificate getCertificate() {
|
||||
return myCertificateWrapper.getCertificate();
|
||||
}
|
||||
|
||||
private static FormBuilder updateBuilderWithPrincipalData(FormBuilder builder, Map<String, String> fields) {
|
||||
builder = builder.setIndent(IdeBorderFactory.TITLED_BORDER_INDENT);
|
||||
for (CommonField field : CommonField.values()) {
|
||||
String value = fields.get(field.getShortName());
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String label = String.format("<html>%s (<b>%s</b>)</html>", field.getShortName(), field.getLongName());
|
||||
builder = builder.addLabeledComponent(label, new JBLabel(value));
|
||||
}
|
||||
return builder.setIndent(0);
|
||||
}
|
||||
|
||||
private static FormBuilder updateBuilderWithTitle(FormBuilder builder, String title) {
|
||||
return builder.addComponent(new TitledSeparator(title), IdeBorderFactory.TITLED_BORDER_TOP_INSET);
|
||||
}
|
||||
|
||||
private static JComponent getTextPane(String text) {
|
||||
JTextPane pane = new JTextPane();
|
||||
pane.setOpaque(false);
|
||||
pane.setEditable(false);
|
||||
pane.setContentType("text/plain");
|
||||
pane.setText(text);
|
||||
//Messages.installHyperlinkSupport(pane);
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
+27
-37
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.net.UntrustedCertificateWarningDialog">
|
||||
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.net.ssl.CertificateWarningDialog">
|
||||
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="10" bottom="0" right="10"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="224"/>
|
||||
@@ -8,43 +8,13 @@
|
||||
<properties>
|
||||
<minimumSize width="-1" height="-1"/>
|
||||
<opaque value="false"/>
|
||||
<preferredSize width="400" height="550"/>
|
||||
<preferredSize width="550" height="650"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="d0af6" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="61118" class="javax.swing.JTextPane">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="400" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<contentType value="text/plain"/>
|
||||
<opaque value="false"/>
|
||||
<text value="Server's certificate is untrusted and appears to be self-signed"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7dcbe" class="javax.swing.JLabel" binding="myWarningSign">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ccf25" binding="myCertificateInfoPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="2" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="empty">
|
||||
@@ -65,7 +35,7 @@
|
||||
<grid id="7551" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -79,16 +49,36 @@
|
||||
<properties>
|
||||
<contentType value="text/html"/>
|
||||
<opaque value="false"/>
|
||||
<text value="<html> <head> </head> <body> <p style="margin-top: 0"> </p> </body> </html> "/>
|
||||
<text value="<html> <head> </head> <body> </body> </html> "/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="d6d14">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="7dcbe" class="javax.swing.JLabel" binding="myWarningSign">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="192db" class="javax.swing.JTextPane" binding="myMessagePane">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<contentType value="text/html"/>
|
||||
<editable value="false"/>
|
||||
<opaque value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.intellij.util.net.ssl;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
public class CertificateWarningDialog extends DialogWrapper {
|
||||
private static final Logger LOG = Logger.getInstance(CertificateWarningDialog.class);
|
||||
|
||||
public static CertificateWarningDialog createSelfSignedCertificateWarning(@NotNull X509Certificate certificate) {
|
||||
return new CertificateWarningDialog(certificate,
|
||||
"Self-signed Server's Certificate",
|
||||
"Server's certificate is untrusted and appears to be self-signed");
|
||||
}
|
||||
|
||||
public static CertificateWarningDialog createExpiredCertificateWarning(@NotNull X509Certificate certificate) {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
public static CertificateWarningDialog createWrongHostnameCertificateWarning(@NotNull X509Certificate certificate) {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
private JPanel myRootPanel;
|
||||
private JLabel myWarningSign;
|
||||
private JPanel myCertificateInfoPanel;
|
||||
private JTextPane myNoticePane;
|
||||
private JTextPane myMessagePane;
|
||||
private final X509Certificate myCertificate;
|
||||
|
||||
public CertificateWarningDialog(@NotNull X509Certificate certificate, @NotNull String title, @NotNull String message) {
|
||||
super((Project)null, false);
|
||||
|
||||
myCertificate = certificate;
|
||||
|
||||
CertificatesManager manager = CertificatesManager.getInstance();
|
||||
setTitle(title);
|
||||
myMessagePane.setText(String.format("<html><body><p><b>%s</b></p></body></html>", message));
|
||||
myMessagePane.setBackground(UIUtil.getPanelBackground());
|
||||
setOKButtonText("Accept");
|
||||
setCancelButtonText("Reject");
|
||||
myWarningSign.setIcon(AllIcons.General.WarningDialog);
|
||||
|
||||
Messages.installHyperlinkSupport(myNoticePane);
|
||||
// myNoticePane.setFont(myNoticePane.getFont().deriveFont((float)FontSize.SMALL.getSize()));
|
||||
|
||||
String path = FileUtil.toCanonicalPath(manager.getCacertsPath());
|
||||
String password = manager.getPassword();
|
||||
|
||||
myNoticePane.setText(
|
||||
String.format("<html><p>" +
|
||||
"Accepted certificate will be saved in truststore <code>%s</code> with password <code>%s</code>" +
|
||||
"</p><html>",
|
||||
path, password
|
||||
)
|
||||
);
|
||||
myCertificateInfoPanel.add(new CertificateInfo(certificate).getPanel(), BorderLayout.CENTER);
|
||||
setResizable(false);
|
||||
init();
|
||||
LOG.debug("Preferred size: " + getPreferredSize());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myRootPanel;
|
||||
}
|
||||
}
|
||||
+43
-17
@@ -1,4 +1,4 @@
|
||||
package com.intellij.util.net;
|
||||
package com.intellij.util.net.ssl;
|
||||
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
@@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -27,12 +29,20 @@ public class CertificateWrapper {
|
||||
mySubjectFields = extractFields(certificate.getSubjectX500Principal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name - Common name of desired issuer field
|
||||
* @return field value of {@link #NOT_AVAILABLE}. if it doesn't exist
|
||||
*/
|
||||
@NotNull
|
||||
public String getIssuerField(@NotNull CommonField name) {
|
||||
String field = myIssuerFields.get(name.getShortName());
|
||||
return field == null ? NOT_AVAILABLE : field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name - Common name of desired subject field
|
||||
* @return field value of {@link #NOT_AVAILABLE}, if it doesn't exist
|
||||
*/
|
||||
@NotNull
|
||||
public String getSubjectField(@NotNull CommonField name) {
|
||||
String field = mySubjectFields.get(name.getShortName());
|
||||
@@ -41,14 +51,13 @@ public class CertificateWrapper {
|
||||
|
||||
/**
|
||||
* Returns SHA-256 fingerprint of the certificate.
|
||||
* Returned string is in upper case and octets are delimited by spaces.
|
||||
*
|
||||
* @return SHA-256 fingerprint or {@link #NOT_AVAILABLE} in case of any error
|
||||
*/
|
||||
@NotNull
|
||||
public String getSha256Fingerprint() {
|
||||
try {
|
||||
return formatHex(DigestUtils.sha256Hex(myCertificate.getEncoded()));
|
||||
return DigestUtils.sha256Hex(myCertificate.getEncoded());
|
||||
}
|
||||
catch (CertificateEncodingException e) {
|
||||
return NOT_AVAILABLE;
|
||||
@@ -57,13 +66,12 @@ public class CertificateWrapper {
|
||||
|
||||
/**
|
||||
* Returns SHA-1 fingerprint of the certificate.
|
||||
* Returned string is in upper case and octets are delimited by spaces.
|
||||
*
|
||||
* @return SHA-1 fingerprint or {@link #NOT_AVAILABLE} in case of any error
|
||||
*/
|
||||
private static String getSha1Fingerprint(X509Certificate certificate) {
|
||||
public String getSha1Fingerprint() {
|
||||
try {
|
||||
return formatHex(DigestUtils.sha1Hex(certificate.getEncoded()));
|
||||
return DigestUtils.sha1Hex(myCertificate.getEncoded());
|
||||
}
|
||||
catch (Exception e) {
|
||||
return NOT_AVAILABLE;
|
||||
@@ -101,6 +109,34 @@ public class CertificateWrapper {
|
||||
return myCertificate.getSerialNumber().toString();
|
||||
}
|
||||
|
||||
public X509Certificate getCertificate() {
|
||||
return myCertificate;
|
||||
}
|
||||
|
||||
public X500Principal getIssuerX500Principal() {
|
||||
return myCertificate.getIssuerX500Principal();
|
||||
}
|
||||
|
||||
public X500Principal getSubjectX500Principal() {
|
||||
return myCertificate.getSubjectX500Principal();
|
||||
}
|
||||
|
||||
public Date getNotBefore() {
|
||||
return myCertificate.getNotBefore();
|
||||
}
|
||||
|
||||
public Date getNotAfter() {
|
||||
return myCertificate.getNotAfter();
|
||||
}
|
||||
|
||||
public Map<String, String> getIssuerFields() {
|
||||
return myIssuerFields;
|
||||
}
|
||||
|
||||
public Map<String, String> getSubjectFields() {
|
||||
return mySubjectFields;
|
||||
}
|
||||
|
||||
private static Map<String, String> extractFields(X500Principal principal) {
|
||||
Map<String, String> fields = new HashMap<String, String>();
|
||||
for (String field : principal.getName().split(",")) {
|
||||
@@ -111,17 +147,7 @@ public class CertificateWrapper {
|
||||
}
|
||||
fields.put(parts[0], parts[1]);
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String formatHex(@NotNull String hex) {
|
||||
StringBuilder builder = new StringBuilder((int)(hex.length() * 1.5));
|
||||
for (int i = 0; i < hex.length(); i += 2) {
|
||||
builder.append(hex.substring(i, i + 2));
|
||||
builder.append(' ');
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
return Collections.unmodifiableMap(fields);
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1,4 +1,4 @@
|
||||
package com.intellij.util.net;
|
||||
package com.intellij.util.net.ssl;
|
||||
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -237,8 +237,7 @@ public class CertificatesManager implements ApplicationComponent {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UntrustedCertificateWarningDialog dialog =
|
||||
new UntrustedCertificateWarningDialog(certificate, myCustomManager.myPath, myCustomManager.myPassword);
|
||||
CertificateWarningDialog dialog = CertificateWarningDialog.createSelfSignedCertificateWarning(certificate);
|
||||
accepted.set(dialog.showAndGet());
|
||||
if (accepted.get()) {
|
||||
LOG.debug("Certificate was accepted");
|
||||
@@ -254,7 +253,7 @@ public class CertificatesManager implements ApplicationComponent {
|
||||
proceeded.await();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
LOG.error("Interrupted", e);
|
||||
}
|
||||
return accepted.get();
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathUtilRt;
|
||||
import com.intellij.util.Url;
|
||||
import com.intellij.util.io.UrlConnectionUtil;
|
||||
import com.intellij.util.net.CertificatesManager;
|
||||
import com.intellij.util.net.ssl.CertificatesManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<implementation-class>com.intellij.util.net.CertificatesManager</implementation-class>
|
||||
<implementation-class>com.intellij.util.net.ssl.CertificatesManager</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.util.net.UntrustedCertificateWarningDialog;
|
||||
import com.intellij.util.net.ssl.CertificateWarningDialog;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
@@ -27,8 +27,8 @@ public class ShowCertificateInfoAction extends AnAction {
|
||||
try {
|
||||
final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(stream, "changeit".toCharArray());
|
||||
UntrustedCertificateWarningDialog dialog =
|
||||
new UntrustedCertificateWarningDialog((X509Certificate)keyStore.getCertificate("mykey"), "", "");
|
||||
X509Certificate certificate = (X509Certificate)keyStore.getCertificate("mykey");
|
||||
CertificateWarningDialog dialog = CertificateWarningDialog.createSelfSignedCertificateWarning(certificate);
|
||||
LOG.debug("Accepted: " + dialog.showAndGet());
|
||||
}
|
||||
finally {
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@ import com.intellij.tasks.TaskRepositoryType;
|
||||
import com.intellij.tasks.config.TaskSettings;
|
||||
import com.intellij.tasks.impl.BaseRepository;
|
||||
import com.intellij.tasks.impl.TaskUtil;
|
||||
import com.intellij.util.net.CertificatesManager;
|
||||
import com.intellij.util.net.HttpConfigurable;
|
||||
import com.intellij.util.net.ssl.CertificatesManager;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
|
||||
Reference in New Issue
Block a user