@@ -28,7 +28,7 @@ import java.security.cert.CertificateFactory
28
28
import java.security.cert.X509Certificate
29
29
import javax.net.ssl.*
30
30
31
- const val BADSSL_UNTRUSTED_ROOT_SHA256 = " sr2tjak7H6QRi8o0fyIXGWdPiU32rDsczcIEAqA+s4g ="
31
+ const val DIGICERT_ROOT_SHA256 = " 5kJvNEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w ="
32
32
33
33
class MainActivity : AppCompatActivity () {
34
34
override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity() {
86
86
GlobalScope .launch(Dispatchers .IO ) {
87
87
onStart(R .id.unpinned)
88
88
try {
89
- val mURL = URL (" https://badssl .com" )
89
+ val mURL = URL (" https://example .com" )
90
90
with (mURL.openConnection() as HttpsURLConnection ) {
91
91
println (" URL: ${this .url} " )
92
92
println (" Response Code: ${this .responseCode} " )
@@ -104,8 +104,8 @@ class MainActivity : AppCompatActivity() {
104
104
GlobalScope .launch(Dispatchers .IO ) {
105
105
onStart(R .id.config_pinned)
106
106
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" )
109
109
with (mURL.openConnection() as HttpsURLConnection ) {
110
110
println (" URL: ${this .url} " )
111
111
println (" Response Code: ${this .responseCode} " )
@@ -124,16 +124,16 @@ class MainActivity : AppCompatActivity() {
124
124
onStart(R .id.okhttp_pinned)
125
125
126
126
try {
127
- val hostname = " badssl.com"
127
+ val hostname = " sha512. badssl.com"
128
128
val certificatePinner = CertificatePinner .Builder ()
129
- .add(hostname, " sha256/${BADSSL_UNTRUSTED_ROOT_SHA256 } " )
129
+ .add(hostname, " sha256/${DIGICERT_ROOT_SHA256 } " )
130
130
.build()
131
131
132
132
val client = OkHttpClient .Builder ()
133
133
.certificatePinner(certificatePinner)
134
134
.build()
135
135
val request = Request .Builder ()
136
- .url(" https://untrusted-root .badssl.com" )
136
+ .url(" https://sha512 .badssl.com" )
137
137
.build();
138
138
139
139
client.newCall(request).execute().use { response ->
@@ -155,7 +155,7 @@ class MainActivity : AppCompatActivity() {
155
155
try {
156
156
// Create an HTTP client that only trusts our specific certificate:
157
157
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 ))
159
159
val ca = cf.generateCertificate(caStream)
160
160
caStream.close()
161
161
@@ -179,7 +179,7 @@ class MainActivity : AppCompatActivity() {
179
179
// Make a request using that client:
180
180
val stringRequest = StringRequest (
181
181
com.android.volley.Request .Method .GET ,
182
- " https://example .com" ,
182
+ " https://sha512.badssl .com" ,
183
183
{ _ ->
184
184
println (" Volley success" )
185
185
this @MainActivity.onSuccess(R .id.volley_pinned)
@@ -201,10 +201,10 @@ class MainActivity : AppCompatActivity() {
201
201
GlobalScope .launch(Dispatchers .IO ) {
202
202
onStart(R .id.trustkit_pinned)
203
203
try {
204
- val mURL = URL (" https://untrusted-root .badssl.com" )
204
+ val mURL = URL (" https://sha512 .badssl.com" )
205
205
with (mURL.openConnection() as HttpsURLConnection ) {
206
206
this .sslSocketFactory = TrustKit .getInstance().getSSLSocketFactory(
207
- " untrusted-root .badssl.com"
207
+ " sha512 .badssl.com"
208
208
)
209
209
println (" URL: ${this .url} " )
210
210
println (" Response Code: ${this .responseCode} " )
@@ -235,19 +235,19 @@ class MainActivity : AppCompatActivity() {
235
235
val context = SSLContext .getInstance(" TLS" )
236
236
context.init (null , trustManager, null )
237
237
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
239
239
240
240
val certs = socket.session.peerCertificates
241
241
242
- if (! certs.any { cert -> doesCertMatchPin(BADSSL_UNTRUSTED_ROOT_SHA256 , cert) }) {
242
+ if (! certs.any { cert -> doesCertMatchPin(DIGICERT_ROOT_SHA256 , cert) }) {
243
243
socket.close() // Close the socket immediately without sending a request
244
244
throw Error (" Unrecognized cert hash." )
245
245
}
246
246
247
247
// Send a real request, just to make it clear that we trust the connection:
248
248
val pw = PrintWriter (socket.outputStream)
249
249
pw.println (" GET / HTTP/1.1" )
250
- pw.println (" Host: untrusted-root .badssl.com" )
250
+ pw.println (" Host: sha512 .badssl.com" )
251
251
pw.println (" " )
252
252
pw.flush()
253
253
0 commit comments