The point at which you should change your code is when your new instance of SSLSocketFactory:
return new SSLSocketFactory(truststore);
The SSLSocketFactory class has other constructors, one of which allows you to specify a keystore, key store password, and trust:
public SSLSocketFactory (KeyStore keystore, String keystorePassword, KeyStore truststore) ( JavaDoc )
I'm not sure if you can download the .P12 file for Android as a KeyStore (on J2SE you can). If you fail to convert the .P12 file to a Bouncy keystore, similar to the trust store you are already using. Use this keystore to create an instance of SSLSocketFactory and you can use the client certificate.
Import a P12 file into BKS via Portecle
Creating a BKS file and importing an existing .key + .pem very simple using the Portecle GUI (Java program). After starting Portecle, choose File → New Keystore → BKS. After that, you can run Tools → Import Key Pair and select the .P12 file. Finally, save the password-protected key store of your choice.
Robert source share