Skip to content

Add SSLContext Default #106

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

Merged
merged 1 commit into from
Apr 30, 2024
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 @@ -9,6 +9,7 @@
*****************************************************************************/
package org.eclipse.ecf.internal.ssl;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.*;
import javax.net.ssl.SSLContext;
Expand All @@ -21,31 +22,39 @@ public class SSLContextHelper {

public static SSLContext getSSLContext(String protocols) {
SSLContext resultContext = null;
if (protocols != null) {
try {
resultContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException pkiNotAvailableERR) {
// TODO Auto-generated catch block
// e.printStackTrace();

String[] httpsProtocols = protocols.split(",");
// trim to make sure
for (int i = 0; i < httpsProtocols.length; i++)
httpsProtocols[i] = httpsProtocols[i].trim();
// Now put into defaultProtocolsList in order of jreProtocols
List<String> splitProtocolsList = Arrays.asList(httpsProtocols);
List<String> defaultProtocolsList = new ArrayList();
for (String jreProtocol : jreProtocols) {
if (splitProtocolsList.contains(jreProtocol)) {
defaultProtocolsList.add(jreProtocol);
}
}
// In order of jre protocols, attempt to create and init SSLContext
for (String protocol : defaultProtocolsList) {
try {
resultContext = SSLContext.getInstance(protocol);
resultContext.init(null, new TrustManager[] { new ECFTrustManager() }, new SecureRandom());
break;
} catch (Exception e) {
// just continue to look for SSLContexts with the next
// protocolName
if (protocols != null) {

String[] httpsProtocols = protocols.split(",");
// trim to make sure
for (int i = 0; i < httpsProtocols.length; i++)
httpsProtocols[i] = httpsProtocols[i].trim();
// Now put into defaultProtocolsList in order of jreProtocols
List<String> splitProtocolsList = Arrays.asList(httpsProtocols);
List<String> defaultProtocolsList = new ArrayList();
for (String jreProtocol : jreProtocols) {
if (splitProtocolsList.contains(jreProtocol)) {
defaultProtocolsList.add(jreProtocol);
}
}
// In order of jre protocols, attempt to create and init
// SSLContext
for (String protocol : defaultProtocolsList) {
try {
resultContext = SSLContext.getInstance(protocol);
resultContext.init(null, new TrustManager[] { new ECFTrustManager() }, new SecureRandom());
break;
} catch (Exception e) {
// just continue to look for SSLContexts with the next
// protocolName
}

}
}
}
return resultContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLContext;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ecf.core.security.Callback;
Expand Down Expand Up @@ -97,6 +99,12 @@ public String getRemoteFileName() {
protected void connect() throws IOException {
setupTimeouts();
urlConnection = getRemoteFileURL().openConnection();
try {
SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// set cache to off if using jar protocol
// this is for addressing bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933
Expand Down
Loading