Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Last active April 4, 2019 00:40
Show Gist options
  • Save pyeongho/7fdab667be595ec8e77af3ffb6478410 to your computer and use it in GitHub Desktop.
Save pyeongho/7fdab667be595ec8e77af3ffb6478410 to your computer and use it in GitHub Desktop.
import okhttp3.CertificatePinner
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.IOException
class CertificatePinning(dmoain: String){
private val client: OkHttpClient = OkHttpClient.Builder()
.certificatePinner(
CertificatePinner.Builder()
.add(dmoain, "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
.build())
.build()
@Throws(Exception::class)
fun myCert(url : String) {
val request = Request.Builder()
.url(url)
.build()
client.newCall(request)?.execute().use { response ->
response?.let {res ->
if (!res.isSuccessful) throw IOException("Unexpected code $res")
for (certificate in res.handshake().peerCertificates()) {
System.out.println(CertificatePinner.pin(certificate))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment