Skip to content

Commit

Permalink
Add SSLContext Default
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaJoeS committed Apr 29, 2024
1 parent 51d6d58 commit 378659a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
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

0 comments on commit 378659a

Please sign in to comment.