Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Commit

Permalink
use the retainAll socket filtering mechanism for android project
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brateman committed Mar 16, 2016
1 parent b3ae3aa commit dd64831
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.paypal.developer.paypaltlscheck;

import android.util.Log;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -60,13 +59,13 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre
}

private Socket enableTLSOnSocket(Socket socket) {
if(socket != null && (socket instanceof SSLSocket)) {
SSLSocket sslSocket = (SSLSocket) socket;
Log.d("TEST-supportedProtocols", Arrays.asList(sslSocket.getSupportedProtocols()).toString());
// We could enable TLSv1.2 only here, but we take a permissive approach for the client
// and leave it up to the server to require TLSv1.2
sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
Log.d("TEST-enabledProtocols", Arrays.asList(sslSocket.getEnabledProtocols()).toString());
if(socket instanceof SSLSocket) {
ArrayList<String> supportedProtocols =
new ArrayList<>(Arrays.asList(((SSLSocket) socket).getSupportedProtocols()));
supportedProtocols.retainAll(Arrays.asList("TLSv1.2", "TLSv1.1", "TLSv1"));

((SSLSocket)socket).setEnabledProtocols(supportedProtocols.toArray(
new String[supportedProtocols.size()]));
}
return socket;
}
Expand Down

0 comments on commit dd64831

Please sign in to comment.