Last active
April 4, 2019 00:40
-
-
Save pyeongho/7fdab667be595ec8e77af3ffb6478410 to your computer and use it in GitHub Desktop.
This file contains 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 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