Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flyfire/0908fb7d160e8bfb9e40de1484498931 to your computer and use it in GitHub Desktop.
Save flyfire/0908fb7d160e8bfb9e40de1484498931 to your computer and use it in GitHub Desktop.
OkHttp 3 SSL Handshake Interceptor - Prints TLS Version & Cipher Suite Used
import android.util.Log;
import java.io.IOException;
import okhttp3.CipherSuite;
import okhttp3.Handshake;
import okhttp3.Response;
import okhttp3.TlsVersion;
/** Prints TLS Version and Cipher Suite for SSL Calls through OkHttp3 */
public class SSLHandshakeInterceptor implements okhttp3.Interceptor {
private static final String TAG = "OkHttp3-SSLHandshake";
@Override
public Response intercept(Chain chain) throws IOException {
final Response response = chain.proceed(chain.request());
printTlsAndCipherSuiteInfo(response);
return response;
}
private void printTlsAndCipherSuiteInfo(Response response) {
if (response != null) {
Handshake handshake = response.handshake();
if (handshake != null) {
final CipherSuite cipherSuite = handshake.cipherSuite();
final TlsVersion tlsVersion = handshake.tlsVersion();
Log.v(TAG, "TLS: " + tlsVersion + ", CipherSuite: " + cipherSuite);
}
}
}
}
@RayyanCoIT
Copy link

Can you please guide how to call this class and verify tls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment