Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSusan Franklin2009-10-02 00:58:34 +0000
committerSusan Franklin2009-10-02 00:58:34 +0000
commitf9303a10e035c1059144e950d022e1915cec1a11 (patch)
treea5894d5a16a49f6296d478feb283c019f0789462 /bundles
parent556838cd82368e25c1dd1d62563aaf5f7b58a95d (diff)
downloadrt.equinox.p2-f9303a10e035c1059144e950d022e1915cec1a11.tar.gz
rt.equinox.p2-f9303a10e035c1059144e950d022e1915cec1a11.tar.xz
rt.equinox.p2-f9303a10e035c1059144e950d022e1915cec1a11.zip
Bug 290984 - [core] merge IServiceUI and IServiceUICheckUnsigned
Bug 291049 - [ui] IServiceUI declaration using ds causes test failures in N20090930
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/IServiceUI.java67
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java86
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/CertificateCheckerTest.java33
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AuthTest.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/HttpStatusTest.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/TimeoutTest.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/TimeoutTest.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/AbstractTestServerClientCase.java22
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ValidationDialogServiceUI.java96
11 files changed, 231 insertions, 142 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/IServiceUI.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/IServiceUI.java
index 3f3cf1000..120473ab3 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/IServiceUI.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/IServiceUI.java
@@ -51,6 +51,54 @@ public interface IServiceUI {
}
/**
+ * Trust information returned from a trust request. *
+ */
+ public static class TrustInfo {
+ private final Certificate[] trustedCertificates;
+ private final boolean saveTrustedCertificates;
+ private final boolean trustUnsigned;
+
+ public TrustInfo(Certificate[] trusted, boolean save, boolean trustUnsigned) {
+ this.trustedCertificates = trusted;
+ this.saveTrustedCertificates = save;
+ this.trustUnsigned = trustUnsigned;
+ }
+
+ /**
+ * Return an array of the certificates that should be trusted for the
+ * requested operation.
+ *
+ * @return the trusted certificates, or <code>null</code> if there are
+ * no certificates that were verified as trusted.
+ */
+ public Certificate[] getTrustedCertificates() {
+ return trustedCertificates;
+ }
+
+ /**
+ * Return a boolean indicating whether the trusted certificates should
+ * be persisted for future operations.
+ *
+ * @return <code>true</code> if the trusted certificates should be persisted, <code>false</code> if
+ * the trust only applies for this request.
+ */
+ public boolean persistTrust() {
+ return saveTrustedCertificates;
+ }
+
+ /**
+ * Return a boolean indicating whether the unsigned content should be trusted
+ * during this operation.
+ *
+ * @return <code>true</code> if the unsigned content should be trusted, or if there was no unsigned content,
+ * and <code>false</code> if there was unsigned content and should not be trusted.
+ */
+ public boolean trustUnsignedContent() {
+ return trustUnsigned;
+ }
+ }
+
+ /**
* Opens a UI prompt for authentication details
*
* @param location - the location requiring login details, may be <code>null</code>.
@@ -69,17 +117,14 @@ public interface IServiceUI {
public AuthenticationInfo getUsernamePassword(String location, AuthenticationInfo previousInfo);
/**
- * Displays a list of certificates to the user.
+ * Opens a UI prompt to capture information about trusted content.
*
- * @param certificates - a list of certificates to display to the user
- * @return An array of certificates that have been accepted.
- */
- public Certificate[] showCertificates(Certificate[][] certificates);
-
- /**
- * Prompts the user that they are installing unsigned content.
- * @param details Detailed information about the items that have unsigned content.
- * @return <code>true</code> if the installation should proceed, and <code>false</code> otherwise.
+ * @param certificates - an array of certificate chains for which there is no current trust anchor. May be
+ * <code>null</code>, which means there are no untrusted certificate chains.
+ * @param unsignedDetail - an array of strings, where each String describes content that is not signed.
+ * May be <code>null</code>, which means there is no unsigned content
+ * @return the TrustInfo that describes the user's choices for trusting certificates and
+ * unsigned content.
*/
- public boolean promptForUnsignedContent(String[] details);
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail);
}
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java
index ddb66f839..8d049b9f9 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/provisional/p2/engine/CertificateChecker.java
@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.engine.EngineActivator;
import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI;
+import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI.TrustInfo;
import org.eclipse.osgi.service.security.TrustEngine;
import org.eclipse.osgi.signedcontent.*;
import org.eclipse.osgi.util.NLS;
@@ -81,25 +82,58 @@ public class CertificateChecker {
}
}
}
- status = checkUnsigned(serviceUI, unsigned);
- if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.CANCEL)
- return status;
- if (!untrusted.isEmpty()) {
- Certificate[][] certificates;
- certificates = new Certificate[untrustedChain.size()][];
- for (int i = 0; i < untrustedChain.size(); i++) {
- certificates[i] = (Certificate[]) untrustedChain.get(i);
+ String policy = getUnsignedContentPolicy();
+ //if there is unsigned content and we should never allow it, then fail without further checking certificates
+ if (!unsigned.isEmpty() && EngineActivator.UNSIGNED_FAIL.equals(policy))
+ return new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.CertificateChecker_UnsignedNotAllowed, unsigned));
+
+ String[] details;
+ // If we always allow unsigned content, or we don't have any, we don't prompt the user about it
+ if (EngineActivator.UNSIGNED_ALLOW.equals(policy) || unsigned.isEmpty())
+ details = null;
+ else {
+ details = new String[unsigned.size()];
+ for (int i = 0; i < details.length; i++) {
+ details[i] = unsigned.get(i).toString();
}
- Certificate[] trustedCertificates = serviceUI.showCertificates(certificates);
- if (trustedCertificates == null) {
- return new Status(IStatus.CANCEL, EngineActivator.ID, Messages.CertificateChecker_CertificateRejected);
+ }
+ Certificate[][] unTrustedCertificateChains;
+ if (untrusted.isEmpty()) {
+ unTrustedCertificateChains = null;
+ } else {
+ unTrustedCertificateChains = new Certificate[untrustedChain.size()][];
+ for (int i = 0; i < untrustedChain.size(); i++) {
+ unTrustedCertificateChains[i] = (Certificate[]) untrustedChain.get(i);
}
+ }
+
+ // If there was no unsigned content, and nothing untrusted, no need to prompt.
+ if (details == null && unTrustedCertificateChains == null)
+ return status;
+
+ TrustInfo trustInfo = serviceUI.getTrustInfo(unTrustedCertificateChains, details);
+
+ // If user doesn't trust unsigned content, cancel the operation
+ if (!trustInfo.trustUnsignedContent())
+ return Status.CANCEL_STATUS;
+
+ Certificate[] trustedCertificates = trustInfo.getTrustedCertificates();
+ // If we had untrusted chains and nothing was trusted, cancel the operation
+ if (unTrustedCertificateChains != null && trustedCertificates == null) {
+ return new Status(IStatus.CANCEL, EngineActivator.ID, Messages.CertificateChecker_CertificateRejected);
+ }
+ // Anything that was trusted should be removed from the untrusted list
+ if (trustedCertificates != null) {
for (int i = 0; i < trustedCertificates.length; i++) {
untrusted.remove(trustedCertificates[i]);
}
- if (untrusted.size() > 0)
- return new Status(IStatus.CANCEL, EngineActivator.ID, Messages.CertificateChecker_CertificateRejected);
- // add newly trusted certificates to trust engine
+ }
+
+ // If there is still untrusted content, cancel the operation
+ if (untrusted.size() > 0)
+ return new Status(IStatus.CANCEL, EngineActivator.ID, Messages.CertificateChecker_CertificateRejected);
+ // If we should persist the trusted certificates, add them to the trust engine
+ if (trustInfo.persistTrust()) {
for (int i = 0; i < trustedCertificates.length; i++) {
try {
trustEngine.addTrustAnchor(trustedCertificates[i], trustedCertificates[i].toString());
@@ -116,26 +150,14 @@ public class CertificateChecker {
}
/**
- * Perform necessary checks on unsigned content.
+ * Return the policy on unsigned content.
*/
- private IStatus checkUnsigned(IServiceUI serviceUI, ArrayList unsigned) {
- if (unsigned.isEmpty())
- return Status.OK_STATUS;
+ private String getUnsignedContentPolicy() {
String policy = EngineActivator.getContext().getProperty(EngineActivator.PROP_UNSIGNED_POLICY);
- //if the policy says we should always allow it, there is nothing more to do
- if (EngineActivator.UNSIGNED_ALLOW.equals(policy))
- return Status.OK_STATUS;
- //if the policy says we should never allow unsigned, then fail
- if (EngineActivator.UNSIGNED_FAIL.equals(policy))
- return new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.CertificateChecker_UnsignedNotAllowed, unsigned));
- //default policy is to prompt for confirmation if possible
- String[] details = new String[unsigned.size()];
- for (int i = 0; i < details.length; i++) {
- details[i] = unsigned.get(i).toString();
- }
- if (serviceUI != null && !serviceUI.promptForUnsignedContent(details))
- return Status.CANCEL_STATUS;
- return Status.OK_STATUS;
+ if (policy == null)
+ policy = EngineActivator.UNSIGNED_PROMPT;
+ return policy;
+
}
public void add(File toAdd) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/CertificateCheckerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/CertificateCheckerTest.java
index 81ff48ca3..5e3d14e6f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/CertificateCheckerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/CertificateCheckerTest.java
@@ -38,13 +38,9 @@ public class CertificateCheckerTest extends AbstractProvisioningTest {
return null;
}
- public boolean promptForUnsignedContent(String[] details) {
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
wasPrompted = true;
- return unsignedReturnValue;
- }
-
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
+ return new TrustInfo(null, false, unsignedReturnValue);
}
}
@@ -150,4 +146,29 @@ public class CertificateCheckerTest extends AbstractProvisioningTest {
System.getProperties().remove(EngineActivator.PROP_UNSIGNED_POLICY);
}
}
+
+ /**
+ * Tests that trust checks that occur in a headless environment are properly treated
+ * as permissive, but not persistent, the same way as it would be if the service registration
+ * were not there.
+ */
+ public void testBug291049() {
+ try {
+
+ // Intentionally unregister our service so that we get whatever the default (or null) service is
+ // in an SDK configuration.
+ if (serviceReg != null) {
+ serviceReg.unregister();
+ serviceReg = null;
+ }
+ checker.add(unsigned);
+ // TODO need to add some untrusted files here, too. To prove that we treated them as trusted temporarily
+
+ System.getProperties().setProperty(EngineActivator.PROP_UNSIGNED_POLICY, EngineActivator.UNSIGNED_PROMPT);
+ IStatus result = checker.start();
+ assertTrue("1.0", result.isOK());
+ } finally {
+ System.getProperties().remove(EngineActivator.PROP_UNSIGNED_POLICY);
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
index 02ceda810..3eaff84b3 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
@@ -182,18 +182,10 @@ public class AllServerTests extends TestCase {
}
/**
- * No need to implement
- */
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- /**
* Not used
*/
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
-
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AuthTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AuthTest.java
index b4c1b9fcc..6da986266 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AuthTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AuthTest.java
@@ -99,13 +99,11 @@ public class AuthTest extends ServerBasedTestCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
- }
-
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/HttpStatusTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/HttpStatusTest.java
index bccd83c60..e05f0fb08 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/HttpStatusTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/HttpStatusTest.java
@@ -189,13 +189,11 @@ public class HttpStatusTest extends ServerBasedTestCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
- }
-
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/TimeoutTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/TimeoutTest.java
index 0cab9cf05..e5e267130 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/TimeoutTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/TimeoutTest.java
@@ -174,12 +174,11 @@ public class TimeoutTest extends ServerBasedTestCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/TimeoutTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/TimeoutTest.java
index 9d60d68c4..b7a98d8bf 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/TimeoutTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/TimeoutTest.java
@@ -226,12 +226,11 @@ public class TimeoutTest extends AbstractTestServerClientCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/AbstractTestServerClientCase.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/AbstractTestServerClientCase.java
index ce14e91a7..e1f59af8c 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/AbstractTestServerClientCase.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/AbstractTestServerClientCase.java
@@ -115,12 +115,11 @@ public class AbstractTestServerClientCase extends TestCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
}
@@ -142,12 +141,11 @@ public class AbstractTestServerClientCase extends TestCase {
return previousInfo;
}
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ /**
+ * Not used
+ */
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
index a7ce95417..621716753 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
@@ -154,15 +154,10 @@ public class TestServerController {
}
/**
- * No need to implement
+ * Not used
*/
- public Certificate[] showCertificates(Certificate[][] certificates) {
- return null;
- }
-
- public boolean promptForUnsignedContent(String[] details) {
- return true;
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) {
+ return new TrustInfo(null, false, true);
}
-
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ValidationDialogServiceUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ValidationDialogServiceUI.java
index 438240df5..b83e7c36d 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ValidationDialogServiceUI.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/ValidationDialogServiceUI.java
@@ -60,7 +60,7 @@ public class ValidationDialogServiceUI implements IServiceUI {
public AuthenticationInfo getUsernamePassword(final String location) {
final AuthenticationInfo[] result = new AuthenticationInfo[1];
- if (!suppressAuthentication()) {
+ if (!suppressAuthentication() && !isHeadless()) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
Shell shell = ProvUI.getDefaultParentShell();
@@ -88,24 +88,59 @@ public class ValidationDialogServiceUI implements IServiceUI {
* (non-Javadoc)
* @see org.eclipse.equinox.internal.provisional.p2.core.IServiceUI#showCertificates(java.lang.Object)
*/
- public Certificate[] showCertificates(final Certificate[][] certificates) {
- final Object[] result = new Object[1];
- final TreeNode[] input = createTreeNodes(certificates);
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
- public void run() {
- Shell shell = ProvUI.getDefaultParentShell();
- ILabelProvider labelProvider = new CertificateLabelProvider();
- TreeNodeContentProvider contentProvider = new TreeNodeContentProvider();
- TrustCertificateDialog trustCertificateDialog = new TrustCertificateDialog(shell, input, labelProvider, contentProvider);
- trustCertificateDialog.open();
- Certificate[] values = new Certificate[trustCertificateDialog.getResult() == null ? 0 : trustCertificateDialog.getResult().length];
- for (int i = 0; i < values.length; i++) {
- values[i] = (Certificate) ((TreeNode) trustCertificateDialog.getResult()[i]).getValue();
+ public TrustInfo getTrustInfo(Certificate[][] untrustedChains, final String[] unsignedDetail) {
+ boolean trustUnsigned = true;
+ boolean persistTrust = false;
+ Certificate[] trusted = new Certificate[0];
+ // Some day we may summarize all of this in one UI, or perhaps we'll have a preference to honor regarding
+ // unsigned content. For now we prompt separately first as to whether unsigned detail should be trusted
+ if (!isHeadless() && unsignedDetail != null && unsignedDetail.length > 0) {
+ final boolean[] result = new boolean[] {false};
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ Shell shell = ProvUI.getDefaultParentShell();
+ OkCancelErrorDialog dialog = new OkCancelErrorDialog(shell, ProvUIMessages.ServiceUI_warning_title, null, createStatus(), IStatus.WARNING);
+ result[0] = dialog.open() == IDialogConstants.OK_ID;
}
- result[0] = values;
- }
- });
- return (Certificate[]) result[0];
+
+ private IStatus createStatus() {
+ MultiStatus parent = new MultiStatus(ProvUIActivator.PLUGIN_ID, 0, ProvUIMessages.ServiceUI_unsigned_message, null);
+ for (int i = 0; i < unsignedDetail.length; i++) {
+ parent.add(new Status(IStatus.WARNING, ProvUIActivator.PLUGIN_ID, unsignedDetail[i]));
+ }
+ return parent;
+ }
+ });
+ trustUnsigned = result[0];
+ }
+ // For now, there is no need to show certificates if there was unsigned content and we don't trust it.
+ if (!trustUnsigned)
+ return new TrustInfo(trusted, persistTrust, trustUnsigned);
+
+ // We've established trust for unsigned content, now examine the untrusted chains
+ if (!isHeadless() && untrustedChains != null && untrustedChains.length > 0) {
+
+ final Object[] result = new Object[1];
+ final TreeNode[] input = createTreeNodes(untrustedChains);
+
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ Shell shell = ProvUI.getDefaultParentShell();
+ ILabelProvider labelProvider = new CertificateLabelProvider();
+ TreeNodeContentProvider contentProvider = new TreeNodeContentProvider();
+ TrustCertificateDialog trustCertificateDialog = new TrustCertificateDialog(shell, input, labelProvider, contentProvider);
+ trustCertificateDialog.open();
+ Certificate[] values = new Certificate[trustCertificateDialog.getResult() == null ? 0 : trustCertificateDialog.getResult().length];
+ for (int i = 0; i < values.length; i++) {
+ values[i] = (Certificate) ((TreeNode) trustCertificateDialog.getResult()[i]).getValue();
+ }
+ result[0] = values;
+ }
+ });
+ persistTrust = true;
+ trusted = (Certificate[]) result[0];
+ }
+ return new TrustInfo(trusted, persistTrust, trustUnsigned);
}
private TreeNode[] createTreeNodes(Certificate[][] certificates) {
@@ -127,7 +162,7 @@ public class ValidationDialogServiceUI implements IServiceUI {
public AuthenticationInfo getUsernamePassword(final String location, final AuthenticationInfo previousInfo) {
final AuthenticationInfo[] result = new AuthenticationInfo[1];
- if (!suppressAuthentication()) {
+ if (!suppressAuthentication() && !isHeadless()) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
Shell shell = ProvUI.getDefaultParentShell();
@@ -148,23 +183,10 @@ public class ValidationDialogServiceUI implements IServiceUI {
return result[0];
}
- public boolean promptForUnsignedContent(final String[] details) {
- final boolean[] result = new boolean[] {false};
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
- public void run() {
- Shell shell = ProvUI.getDefaultParentShell();
- OkCancelErrorDialog dialog = new OkCancelErrorDialog(shell, ProvUIMessages.ServiceUI_warning_title, null, createStatus(), IStatus.WARNING);
- result[0] = dialog.open() == IDialogConstants.OK_ID;
- }
-
- private IStatus createStatus() {
- MultiStatus parent = new MultiStatus(ProvUIActivator.PLUGIN_ID, 0, ProvUIMessages.ServiceUI_unsigned_message, null);
- for (int i = 0; i < details.length; i++) {
- parent.add(new Status(IStatus.WARNING, ProvUIActivator.PLUGIN_ID, details[i]));
- }
- return parent;
- }
- });
- return result[0];
+ private boolean isHeadless() {
+ // If there is no UI available and we are still the IServiceUI,
+ // assume that the operation should proceed. See
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291049
+ return !PlatformUI.isWorkbenchRunning();
}
}

Back to the top