Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified ECFSSLContextFactory constructor and made more robust. #155

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,27 @@
*/
public class ECFSSLContextFactory implements SSLContextFactory {

private final ServiceTracker<Provider, Provider> providerTracker;
private ServiceTracker<Provider, Provider> providerTracker;
private final String defaultProtocol;
private final String defaultProviderName;

public ECFSSLContextFactory(BundleContext context, String defaultProtocol) {
public ECFSSLContextFactory(BundleContext context) throws NoSuchAlgorithmException {
this(context, null);
}

public ECFSSLContextFactory(BundleContext context, String defaultProtocol) throws NoSuchAlgorithmException {
this(context, defaultProtocol, null);
}

public ECFSSLContextFactory(BundleContext context, String defaultProtocol, String defaultProviderName) {
public ECFSSLContextFactory(BundleContext context, String defaultProtocol, String defaultProviderName) throws NoSuchAlgorithmException {
if (context == null)
throw new NullPointerException("context must not be null"); //$NON-NLS-1$
if (defaultProviderName == null) {
defaultProviderName = SSLContext.getDefault().getProvider().getName();
}
if (defaultProtocol == null) {
defaultProtocol = SSLContext.getDefault().getProtocol();
}
this.defaultProtocol = defaultProtocol;
this.defaultProviderName = defaultProviderName;
this.providerTracker = new ServiceTracker<Provider, Provider>(context, Provider.class, null);
Expand All @@ -60,8 +72,11 @@ public SSLContext getInstance(String protocol) throws NoSuchAlgorithmException,
return getInstance0(protocol, this.defaultProviderName);
}

public void close() {
this.providerTracker.close();
public synchronized void close() {
if (this.providerTracker != null) {
this.providerTracker.close();
this.providerTracker = null;
}
}

protected Provider findProvider(String providerName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.ecf.internal.core;

import java.util.*;
import javax.net.ssl.SSLContext;
import org.eclipse.core.runtime.*;
import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.identity.ID;
Expand Down Expand Up @@ -229,8 +228,7 @@ public void ungetService(Bundle bundle, ServiceRegistration registration, Object
containerManagerServiceRegistration = ctxt.registerService(IContainerManager.class.getName(), sf, null);

// Register SSLContextFactory
SSLContext defaultContext = SSLContext.getDefault();
ecfSSLContextFactory = new ECFSSLContextFactory(ctxt, defaultContext.getProtocol(), defaultContext.getProvider().getName());
ecfSSLContextFactory = new ECFSSLContextFactory(ctxt);
sslContextFactoryRegistration = ctxt.registerService(SSLContextFactory.class, ecfSSLContextFactory, null);

SafeRunner.run(new ExtensionRegistryRunnable(this.context) {
Expand Down
Loading