moxie0 / AndroidPinning

A standalone library project for certificate pinning on Android.
http://www.thoughtcrime.org/blog/authenticity-is-broken-in-ssl-but-your-app-ha/
GNU General Public License v3.0
618 stars 114 forks source link

How does one obtain Google's X.509 certificate? #22

Closed vectorialgradha closed 9 years ago

vectorialgradha commented 9 years ago

The readme sample using google pins doesn't validate for me. Looking through stackoverflow I found the following shell script which uses openssl to obtain the certificate of a server:

#!/bin/sh
# Based on http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html

SERVER=www.google.com:443
echo | openssl s_client -connect ${SERVER} 2>&1 | \
     sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > mycert.pem &&
     cat mycert.pem &&
     echo "Generated pem file"

Running this generates a file which used with the pin.py tool outputs:

Calculating PIN for certificate: C=US, ST=California, L=Mountain View, O=Google Inc, CN=www.google.com
Pin Value: 6a42217ac7419912ff661867525e5a059a526325

However when I paste the pin value into the readme HttpsURLConnection sample I get an exception javax.net.ssl.SSLHandshakeException: No valid pins found in chain!. Which seems to indicate I'm not getting correctly the certificate. How should I retrieve the cert from google and other public websites?