Created
April 7, 2017 17:57
-
-
Save handstandsam/d7d7956a05698b23cad14dd404350e23 to your computer and use it in GitHub Desktop.
OkHttp 3 SSL Handshake Interceptor - Prints TLS Version & Cipher Suite Used
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 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); | |
} | |
} | |
} | |
} |
How I was able to apply this intercepter in my program was to use code like this:
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new SSLHandshakeInterceptor())
.build();
For more details read about interceptors with okhttp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you please guide, how to call this class and execute the method