diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ECFSSLContextFactory.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ECFSSLContextFactory.java index 077f325a0..8caf4f8c3 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ECFSSLContextFactory.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ECFSSLContextFactory.java @@ -14,6 +14,9 @@ import java.security.*; import java.util.Optional; import javax.net.ssl.SSLContext; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ecf.internal.core.identity.Activator; import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; @@ -65,6 +68,16 @@ protected Provider findProvider(String providerName) { if (providerName == null) { return this.providerTracker.getService(); } + // If providerName is same as current default SSLContext then use it + SSLContext defaultContext = null; + try { + defaultContext = SSLContext.getDefault(); + } catch (NoSuchAlgorithmException e) { + Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not get SSLContext.getDefault()", e)); //$NON-NLS-1$ + } + if (defaultContext != null && providerName.equals(defaultContext.getProvider().getName())) { + return defaultContext.getProvider(); + } Optional optResult = this.providerTracker.getTracked().values().stream().filter(p -> // test that providerName is equal to Provider.getName() providerName.equals(p.getName())).findFirst(); diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/META-INF/MANIFEST.MF index 0c8c1d81d..9d389fae7 100644 --- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/META-INF/MANIFEST.MF +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.ecf.provider.filetransfer.httpclientjava;singleton:=true -Bundle-Version: 2.0.300.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Vendor: %plugin.provider Bundle-Localization: plugin Automatic-Module-Name: org.eclipse.ecf.provider.filetransfer.httpclientjava diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/Activator.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/Activator.java index ec45ead9f..5d739da1f 100644 --- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/Activator.java +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/Activator.java @@ -27,10 +27,9 @@ import java.util.List; import java.util.Map; -import javax.net.ssl.SSLSocketFactory; - import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.ecf.core.security.SSLContextFactory; import org.eclipse.ecf.core.util.ECFRuntimeException; import org.eclipse.ecf.core.util.LogHelper; import org.eclipse.ecf.core.util.Trace; @@ -118,7 +117,7 @@ public void removedService(ServiceReference reference, HttpClient se private ServiceTracker logServiceTracker = null; - private ServiceTracker sslSocketFactoryTracker; + private ServiceTracker sslContextFactoryTracker; private ServiceTracker ntlmProxyHandlerTracker; @@ -181,8 +180,8 @@ private void applyDebugOptions(BundleContext ctxt) { @Override public synchronized void stop(BundleContext ctxt) throws Exception { - if (sslSocketFactoryTracker != null) { - sslSocketFactoryTracker.close(); + if (sslContextFactoryTracker != null) { + sslContextFactoryTracker.close(); } if (logServiceTracker != null) { @@ -247,12 +246,15 @@ public void log(IStatus status) { } } - public synchronized SSLSocketFactory getSSLSocketFactory() { - if (sslSocketFactoryTracker == null) { - sslSocketFactoryTracker = new ServiceTracker(this.context, SSLSocketFactory.class, null); - sslSocketFactoryTracker.open(); + /** + * @since 2.0 + */ + public synchronized SSLContextFactory getSSLContextFactory() { + if (sslContextFactoryTracker == null) { + sslContextFactoryTracker = new ServiceTracker(this.context, SSLContextFactory.class, null); + sslContextFactoryTracker.open(); } - SSLSocketFactory service = sslSocketFactoryTracker.getService(); + SSLContextFactory service = sslContextFactoryTracker.getService(); return service; } diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java index fd31454e8..81422322a 100644 --- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java @@ -17,12 +17,16 @@ import java.net.http.HttpClient; import java.net.http.HttpClient.Redirect; import java.net.http.HttpRequest; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; import java.time.Duration; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.util.Trace; import org.eclipse.ecf.internal.provider.filetransfer.DebugOptions; import org.eclipse.ecf.provider.filetransfer.httpclientjava.HttpClientOptions; @@ -48,6 +52,11 @@ public class ECFHttpClientFactory implements IHttpClientFactory { public HttpClient.Builder newClient() { HttpClient.Builder builder = HttpClient.newBuilder().followRedirects(Redirect.NORMAL); + try { + builder.sslContext(Activator.getDefault().getSSLContextFactory().getDefault()); + } catch (NoSuchAlgorithmException | NoSuchProviderException e) { + Activator.getDefault().log(new Status(IStatus.ERROR,Activator.PLUGIN_ID,"Could not set SSLContext when creating jre HttpClient", e)); + } builder = Activator.getDefault().runModifiers(builder, new ModifierRunner() { @Override public HttpClient.Builder run(IHttpClientModifier modifier, HttpClient.Builder value) {