Disable SSL as a protocol in HttpsURLConnection

后端 未结 6 1746
眼角桃花
眼角桃花 2020-12-02 15:14

Due to the POODLE vulnerability, my server, hosted in Amazon AWS does no longer support SSLv3.

As a result, the first HTTPS connection my Android app does against th

6条回答
  •  执笔经年
    2020-12-02 15:40

    I've recently tested this using SSLContext (as I needed access to Trustmanager) instead of implementing my own NoSSLv3Factory and so far I haven't had any problems.

    private getSSLContext()
    {
        /* Load the keyStore that includes self-signed cert as a "trusted" entry. */
        KeyStore keyStore = ...  //optional
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); //optional
        tmf.init(keyStore); //optional
    
        //This is the important line, specifying the cipher to use and cipher provider
        SSLContext sslContext = SSLContext.getInstance("TLSv1","AndroidOpenSSL");
        ctx.init(null, tmf.getTrustManagers(), null); //if trustmanager not used pass null as the second parameter    
        return sslContext;
    }
    

    You could then use this in your HttpsURLConnection object like so:

    ...
    URL url = new URL("https://yourwebapp.com/");
    HttpsURLConnection webConnection = (HttpsURLConnection)url.openConnection();
    webConnection.setSSLSocketFactory(getSSLContext())
    ...    
    

    This does mean that you'll have to stay on top of any TLS vulnerabilities though and modify the specified cipher if any SSL/TLS vulnerabilities are publicly disclosed.

    A list of supported ciphers and providers you can use are listed here

    The first code block, minor the key change for this scenario, was primarily taken from this SO answer

提交回复
热议问题