I'm using Netty on Android and server side to establish a SSL-secured connection with client-authentication. Now I'm having difficulties connecting with these certificates since SSLEngine declines them due to "null cert chain".
This is what I've done on the Server side. I set up an SSLContext with a signed Server Certificat (the client knows the CA so it can validate this one).
To make the server accept any certificates from clients (since they are all self-signed) I implemented an DummyTrustManager that will just accept any.
private static class DummyTrustManager implements X509TrustManager
{
private X509Certificate[] mCerts;
public DummyTrustManager(Certificate[] pCerts)
{
// convert into x509 array
mCerts = new X509Certificate[pCerts.length];
for(int i = 0; i < pCerts.length; i++)
{
mCerts[i] = (X509Certificate)pCerts[i];
}
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException{}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException{}
@Override
public X509Certificate[] getAcceptedIssuers()
{
return mCerts;
//return new X509Certificate[0];
}
}
The point is that I'm not quite sure about the getAcceptedIssuers() method.
If I retrurn an empty array than the openssl-binary (which I use to veryfi the correct setup) fails due to an empty AcceptedIssuers list.
If I add the currents server certificate chain than it will work at least for client certificates that were signed by the same ca but not with ones that are self signed (which is what I need).
But maybe I'm doing something wrong on the client side:
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
keyStore.setEntry("user_certificate", new KeyStore.PrivateKeyEntry(mPrivate, new Certificate[]{mClientCert}), this);
keyStore.setCertificateEntry("server_certificate", mServerCert);
Also I did some researches and from what I understood so far: The client has a valid certificate chain but does not send it because the server tells it that it only accepts the issuers listed by the server.
If this is right, then how can I overcome this issue?
I was thinking of an seperate self-signed CA that is delivered to all clients and that is also listed in the server accepted issuers list. Any client uses this CA to sign its own certificate. I see of no security problem with this. Or is there a better solution?