I'm writing a program to simulate a secure connection over SSL sockets. I want the client to import certificates that are not trusted (and hence not in its truststore) at their own discretion through an interface. These certificates are self-signed.
So far I have hit a wall, where the program crashes and reports Received fatal alert: certificate_unknown
due to the fact that the server certificate doesn't reside in the client truststore.
I am simulating the connection locally. I've found examples where truststore managers are used explicitly to override all SSL checking, but this is wide open to MITM attacks.
I need to wrap the truststore manager implementation in some way to make it secure, and ensure server certificates are validated. The link here gives a good example of an open implementation, but I don't know how to wrap it securely.
In the case of the trustmanager implementation it will still fire a CertificateException
when it locates an untrusted certificate (from its checkServerTrusted
method), do I have to handle the exception yet continue execution of the program from there? I'm very unsure how to tackle this secure wrapping.
Many thanks all