Depends how do you obtain your certificate and what exactly you want to validate. Whether it's during SSL conneciton with 2way auth, or client side auth, or just the steps you described.
In case of HTTP connection the difference is where you can obtain certificate (and which methods allows you to do it), if you don't need this just skip to bottom:
HTTP
Tricky thing here, since android 6.0 Apache HTTP client was removed from Android SDK thus all info descibed below may be deprecated. However since it's school project you may get general idea how it can be done:
http://developer.android.com/intl/es/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client
Nevertheless,
There is a interface called X509HostnameVerifier
https://stuff.mit.edu/afs/sipb/project/android/docs/reference/org/apache/http/conn/ssl/X509HostnameVerifier.html
abstract boolean verify(String host, SSLSession session)
abstract void verify(String host, X509Certificate cert)
abstract void verify(String host, SSLSocket ssl)
abstract void verify(String host, String[] cns, String[] subjectAlts)
And here you can acces server certificate
OWN CERTIFICATE
Question is how you want to provide certificate to your app. There couple possibilities:
- hardcode PEM string in app
- generate BKS keystore and store certificate in it, keep keystore in assets
- keep certificate in either der or crt format in assets
All three above are almost the same, because retrieving X509Certificate from them is very easy and you can find plenty examples how to do it.
As soon as you get your desired X509Certificate object:
1.you can extract it from X509Cert principals
2. checkValidity() for validation and getNotAfter() getNotBefore() methods for exact date
3. X509Certificate can have only on signer so: getIssuerX500Principal() or getIssuerDn(). If you want to go up you'd need certificate chain