Example usage for javax.net.ssl HttpsURLConnection getSSLSocketFactory

List of usage examples for javax.net.ssl HttpsURLConnection getSSLSocketFactory

Introduction

In this page you can find the example usage for javax.net.ssl HttpsURLConnection getSSLSocketFactory.

Prototype

public SSLSocketFactory getSSLSocketFactory() 

Source Link

Document

Gets the SSL socket factory to be used when creating sockets for secure https URL connections.

Usage

From source file:com.adobe.phonegap.contentsync.Sync.java

/**
 * This function will install a trust manager that will blindly trust all SSL
 * certificates.  The reason this code is being added is to enable developers
 * to do development using self signed SSL certificates on their web server.
 *
 * The standard HttpsURLConnection class will throw an exception on self
 * signed certificates if this code is not run.
 *///from w ww  .ja  va 2 s .c  om
private static SSLSocketFactory trustAllHosts(HttpsURLConnection connection) {
    // Install the all-trusting trust manager
    SSLSocketFactory oldFactory = connection.getSSLSocketFactory();
    try {
        // Install our all trusting manager
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        SSLSocketFactory newFactory = sc.getSocketFactory();
        connection.setSSLSocketFactory(newFactory);
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return oldFactory;
}