Skip to content

Commit f278fed

Browse files
authored
Merge pull request #106 from JavaJoeS/master
Add SSLContext Default
2 parents 51d6d58 + 378659a commit f278fed

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

framework/bundles/org.eclipse.ecf.ssl/src/org/eclipse/ecf/internal/ssl/SSLContextHelper.java

+31-22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*****************************************************************************/
1010
package org.eclipse.ecf.internal.ssl;
1111

12+
import java.security.NoSuchAlgorithmException;
1213
import java.security.SecureRandom;
1314
import java.util.*;
1415
import javax.net.ssl.SSLContext;
@@ -21,31 +22,39 @@ public class SSLContextHelper {
2122

2223
public static SSLContext getSSLContext(String protocols) {
2324
SSLContext resultContext = null;
24-
if (protocols != null) {
25+
try {
26+
resultContext = SSLContext.getDefault();
27+
} catch (NoSuchAlgorithmException pkiNotAvailableERR) {
28+
// TODO Auto-generated catch block
29+
// e.printStackTrace();
2530

26-
String[] httpsProtocols = protocols.split(",");
27-
// trim to make sure
28-
for (int i = 0; i < httpsProtocols.length; i++)
29-
httpsProtocols[i] = httpsProtocols[i].trim();
30-
// Now put into defaultProtocolsList in order of jreProtocols
31-
List<String> splitProtocolsList = Arrays.asList(httpsProtocols);
32-
List<String> defaultProtocolsList = new ArrayList();
33-
for (String jreProtocol : jreProtocols) {
34-
if (splitProtocolsList.contains(jreProtocol)) {
35-
defaultProtocolsList.add(jreProtocol);
36-
}
37-
}
38-
// In order of jre protocols, attempt to create and init SSLContext
39-
for (String protocol : defaultProtocolsList) {
40-
try {
41-
resultContext = SSLContext.getInstance(protocol);
42-
resultContext.init(null, new TrustManager[] { new ECFTrustManager() }, new SecureRandom());
43-
break;
44-
} catch (Exception e) {
45-
// just continue to look for SSLContexts with the next
46-
// protocolName
31+
if (protocols != null) {
32+
33+
String[] httpsProtocols = protocols.split(",");
34+
// trim to make sure
35+
for (int i = 0; i < httpsProtocols.length; i++)
36+
httpsProtocols[i] = httpsProtocols[i].trim();
37+
// Now put into defaultProtocolsList in order of jreProtocols
38+
List<String> splitProtocolsList = Arrays.asList(httpsProtocols);
39+
List<String> defaultProtocolsList = new ArrayList();
40+
for (String jreProtocol : jreProtocols) {
41+
if (splitProtocolsList.contains(jreProtocol)) {
42+
defaultProtocolsList.add(jreProtocol);
43+
}
4744
}
45+
// In order of jre protocols, attempt to create and init
46+
// SSLContext
47+
for (String protocol : defaultProtocolsList) {
48+
try {
49+
resultContext = SSLContext.getInstance(protocol);
50+
resultContext.init(null, new TrustManager[] { new ECFTrustManager() }, new SecureRandom());
51+
break;
52+
} catch (Exception e) {
53+
// just continue to look for SSLContexts with the next
54+
// protocolName
55+
}
4856

57+
}
4958
}
5059
}
5160
return resultContext;

providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java

+8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import java.net.PasswordAuthentication;
2222
import java.net.URL;
2323
import java.net.URLConnection;
24+
import java.security.NoSuchAlgorithmException;
2425
import java.util.Collections;
2526
import java.util.HashMap;
2627
import java.util.Iterator;
2728
import java.util.List;
2829
import java.util.Map;
30+
import javax.net.ssl.SSLContext;
2931
import org.eclipse.core.runtime.IPath;
3032
import org.eclipse.core.runtime.Path;
3133
import org.eclipse.ecf.core.security.Callback;
@@ -97,6 +99,12 @@ public String getRemoteFileName() {
9799
protected void connect() throws IOException {
98100
setupTimeouts();
99101
urlConnection = getRemoteFileURL().openConnection();
102+
try {
103+
SSLContext.getDefault();
104+
} catch (NoSuchAlgorithmException e) {
105+
// TODO Auto-generated catch block
106+
e.printStackTrace();
107+
}
100108
// set cache to off if using jar protocol
101109
// this is for addressing bug
102110
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933

0 commit comments

Comments
 (0)