Created
September 19, 2013 14:18
-
-
Save robmadden/6624182 to your computer and use it in GitHub Desktop.
Custom SSL Socket Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.InputStream; | |
import java.security.KeyManagementException; | |
import java.security.KeyStore; | |
import java.security.KeyStoreException; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.UnrecoverableKeyException; | |
import org.apache.http.conn.ssl.SSLSocketFactory; | |
import android.content.Context; | |
import android.util.Log; | |
import com.sproutsocial.android.R; | |
public class CustomSSLSocketFactory { | |
protected static final String TAG = "CustomSSLSocketFactory"; | |
public static CustomSSLSocketFactory getSSLSocketFactory(final Context context) { | |
SSLSocketFactory ret = null; | |
try { | |
final KeyStore ks = KeyStore.getInstance("BKS"); | |
final InputStream inputStream = context.getResources().openRawResource(R.raw.certs); | |
ks.load(inputStream, context.getString(R.string.store_pass).toCharArray()); | |
inputStream.close(); | |
ret = new SSLSocketFactory(ks); | |
} catch (UnrecoverableKeyException ex) { | |
Log.d(TAG, ex.getMessage()); | |
} catch (KeyStoreException ex) { | |
Log.d(TAG, ex.getMessage()); | |
} catch (KeyManagementException ex) { | |
Log.d(TAG, ex.getMessage()); | |
} catch (NoSuchAlgorithmException ex) { | |
Log.d(TAG, ex.getMessage()); | |
} catch (IOException ex) { | |
Log.d(TAG, ex.getMessage()); | |
} catch (Exception ex) { | |
Log.d(TAG, ex.getMessage()); | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment