@@ -28,7 +28,7 @@ import java.security.cert.CertificateFactory
2828import java.security.cert.X509Certificate
2929import javax.net.ssl.*
3030
31- const val BADSSL_UNTRUSTED_ROOT_SHA256 = " sr2tjak7H6QRi8o0fyIXGWdPiU32rDsczcIEAqA+s4g ="
31+ const val DIGICERT_ROOT_SHA256 = " 5kJvNEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w ="
3232
3333class MainActivity : AppCompatActivity () {
3434 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity() {
8686 GlobalScope .launch(Dispatchers .IO ) {
8787 onStart(R .id.unpinned)
8888 try {
89- val mURL = URL (" https://badssl .com" )
89+ val mURL = URL (" https://example .com" )
9090 with (mURL.openConnection() as HttpsURLConnection ) {
9191 println (" URL: ${this .url} " )
9292 println (" Response Code: ${this .responseCode} " )
@@ -104,8 +104,8 @@ class MainActivity : AppCompatActivity() {
104104 GlobalScope .launch(Dispatchers .IO ) {
105105 onStart(R .id.config_pinned)
106106 try {
107- // Untrusted in system store, trusted & pinned in network config:
108- val mURL = URL (" https://untrusted-root .badssl.com" )
107+ // Pinned by hash in network config:
108+ val mURL = URL (" https://sha512 .badssl.com" )
109109 with (mURL.openConnection() as HttpsURLConnection ) {
110110 println (" URL: ${this .url} " )
111111 println (" Response Code: ${this .responseCode} " )
@@ -124,16 +124,16 @@ class MainActivity : AppCompatActivity() {
124124 onStart(R .id.okhttp_pinned)
125125
126126 try {
127- val hostname = " badssl.com"
127+ val hostname = " sha512. badssl.com"
128128 val certificatePinner = CertificatePinner .Builder ()
129- .add(hostname, " sha256/${BADSSL_UNTRUSTED_ROOT_SHA256 } " )
129+ .add(hostname, " sha256/${DIGICERT_ROOT_SHA256 } " )
130130 .build()
131131
132132 val client = OkHttpClient .Builder ()
133133 .certificatePinner(certificatePinner)
134134 .build()
135135 val request = Request .Builder ()
136- .url(" https://untrusted-root .badssl.com" )
136+ .url(" https://sha512 .badssl.com" )
137137 .build();
138138
139139 client.newCall(request).execute().use { response ->
@@ -155,7 +155,7 @@ class MainActivity : AppCompatActivity() {
155155 try {
156156 // Create an HTTP client that only trusts our specific certificate:
157157 val cf = CertificateFactory .getInstance(" X.509" )
158- val caStream = BufferedInputStream (resources.openRawResource(R .raw.example_com_digicert_ca ))
158+ val caStream = BufferedInputStream (resources.openRawResource(R .raw.digicert_ca ))
159159 val ca = cf.generateCertificate(caStream)
160160 caStream.close()
161161
@@ -179,7 +179,7 @@ class MainActivity : AppCompatActivity() {
179179 // Make a request using that client:
180180 val stringRequest = StringRequest (
181181 com.android.volley.Request .Method .GET ,
182- " https://example .com" ,
182+ " https://sha512.badssl .com" ,
183183 { _ ->
184184 println (" Volley success" )
185185 this @MainActivity.onSuccess(R .id.volley_pinned)
@@ -201,10 +201,10 @@ class MainActivity : AppCompatActivity() {
201201 GlobalScope .launch(Dispatchers .IO ) {
202202 onStart(R .id.trustkit_pinned)
203203 try {
204- val mURL = URL (" https://untrusted-root .badssl.com" )
204+ val mURL = URL (" https://sha512 .badssl.com" )
205205 with (mURL.openConnection() as HttpsURLConnection ) {
206206 this .sslSocketFactory = TrustKit .getInstance().getSSLSocketFactory(
207- " untrusted-root .badssl.com"
207+ " sha512 .badssl.com"
208208 )
209209 println (" URL: ${this .url} " )
210210 println (" Response Code: ${this .responseCode} " )
@@ -235,19 +235,19 @@ class MainActivity : AppCompatActivity() {
235235 val context = SSLContext .getInstance(" TLS" )
236236 context.init (null , trustManager, null )
237237
238- val socket = context.socketFactory.createSocket(" untrusted-root .badssl.com" , 443 ) as SSLSocket
238+ val socket = context.socketFactory.createSocket(" sha512 .badssl.com" , 443 ) as SSLSocket
239239
240240 val certs = socket.session.peerCertificates
241241
242- if (! certs.any { cert -> doesCertMatchPin(BADSSL_UNTRUSTED_ROOT_SHA256 , cert) }) {
242+ if (! certs.any { cert -> doesCertMatchPin(DIGICERT_ROOT_SHA256 , cert) }) {
243243 socket.close() // Close the socket immediately without sending a request
244244 throw Error (" Unrecognized cert hash." )
245245 }
246246
247247 // Send a real request, just to make it clear that we trust the connection:
248248 val pw = PrintWriter (socket.outputStream)
249249 pw.println (" GET / HTTP/1.1" )
250- pw.println (" Host: untrusted-root .badssl.com" )
250+ pw.println (" Host: sha512 .badssl.com" )
251251 pw.println (" " )
252252 pw.flush()
253253
0 commit comments