Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.ssl;
 
public class TrustingSslSocketFactory extends SocketFactory {
	private static SocketFactory factory = null;
	public static SocketFactory getDefault() {
	}
	public Socket createSocket(String arg0int arg1throws IOException {
		return .createSocket(arg0arg1);
	}
	public Socket createSocket(InetAddress arg0int arg1throws IOException {
		return .createSocket(arg0arg1);
	}
	public Socket createSocket(String arg0int arg1InetAddress arg2int arg3throws IOException {
		return .createSocket(arg0arg1arg2arg3);
	}
	public Socket createSocket(InetAddress arg0int arg1InetAddress arg2int arg3throws IOException {
		return .createSocket(arg0arg1arg2arg3);
	}

Setup the default trusting SSL socket factory.
	static {
		TrustManager[] trustManager = new TrustManager[] {
					public X509Certificate[] getAcceptedIssuers() { return null; }
					public void checkClientTrusted(X509Certificate[] chainString authTypethrows CertificateException {
						// By not throwing an exception we indicate that we trust this certificate
					}
					public void checkServerTrusted(X509Certificate[] chainString authTypethrows CertificateException {
						// By not throwing an exception we indicate that we trust this server
					}
				}
		};
		// Create the socket factory that uses the trusting trust manager.
		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(nulltrustManagernew java.security.SecureRandom());
catch (GeneralSecurityException e) {
			// This should never happen. If it does there is nothing anyone can do about it
		}
	}
New to GrepCode? Check out our FAQ X