I encountered the same problem, and I have resolved in this way :
private void initPrivateKeyAndX509Certificate(int clientCertResourceId, String clientCertPassword) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
try {
InputStream certificateFileStream = null;
if (clientCertResourceId > 0) {
certificateFileStream = new ByteArrayInputStream(Utility.readbyteFromResources(clientCertResourceId, MYApplication.getAppContext()));
}
if (certificateFileStream != null) {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(certificateFileStream, clientCertPassword != null ? clientCertPassword.toCharArray() : null);
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Key key = keyStore.getKey(alias, clientCertPassword.toCharArray());
if (key instanceof PrivateKey) {
mPrivateKey = (PrivateKey) key;
Certificate[] arrayOfCertificate = keyStore.getCertificateChain(alias);
mCertificates = new X509Certificate[arrayOfCertificate.length];
for (int i = 0; i < mCertificates.length; i++) {
mCertificates[i] = ((X509Certificate) arrayOfCertificate[i]);
}
break;
}
}
certificateFileStream.close();
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
throw e;
}
}
Where the clientCertResourceId is the resourceId related of the p12 which is in raw folder.
Then I have overrided the onReveicedClientCertRequest in this way :
@Override
public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
if (mPrivateKey != null && mCertificates != null && mCertificates.length != 0) {
request.proceed(mPrivateKey, mCertificates);
} else {
request.cancel();
}
}
I wondering if this way to do is the correct one, but currently it works