I am developing an Android application which requires SSL handshaking to be done only if the server has a particular certificate issued by a CA(For eg: GoDaddy). I referred the documentation on Android developer website but it only says about verifying a self signed certificate or certificate that is not trusted by Android.In my case should I get the client certificate and add it to my keystore.I am using apache HttpClient for my webservice requests. Any help is much appreciated.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
You need to
It is actually simple. You have to override the checkServerTrusted in your X509TrustManager and throw a CertificateException if the issuer is not GoDaddy. In the code I provided, I used "bla bla", you should probably get the exact name.
You have first to use the provider for your Http Requests: This provider will be used to do the requestes using provider.execute function:
Now you need your EasySSLSocketFactory:
Finally, and here is the work, you need the EasyX509TrustManager which will not accept except certificates issued by GoDaddy:
This is how I check SSL Certs in my code.
I'm validating only CAcert certificats. But you can easily replace the certificate by the root cert from Go Daddy.
It's very easy and safe on API14+ (maybe since 11+).
There is some extra work to make it run on older API levels. Basically I run my own checks on API<14 with the implementation found here: Validate X509 certificates using Java APis
I wrote a tiny script to create the
byte[]
from any given .der file:Anyway, you could use a complete trust store with a hand full of trusted certificates if you want to.
You can do this easily by:
1. Add the CA Certificate you want to your truststore.
2. Remove all other CA Certificate's(default) from your truststore and catch the SSLHandshakeException.
Or create a new truststore that contains only your CA Certificate.