I am trying to implement an SSL proxy server in Java that does not raise certificate errors in the browser. I understand that I will need to process the "CONNECT" request, do an SSL handshake thus requiring that I create a sever certificate and store that in the keystore which I will initialize for the SSL socket.
But the browser will always have to verify the server certificate returned and throw the warning error if; 1.The CA certificate is not trusted, but this can be overcome by installing the CA certificate used in signing the server certificate once in the browser. 2.The CN of the certificate does not match the hostname of the website being requested. For this second issue, I implemented using BouncyCastle a certificate generation thread, that uses the hostname being requested to generate a certificate that is signed with the trusted CA private key from above. Then I add the server certificate generated and it's private key into the keystore using the hostname as the alias for the key entry. Now comes the part I can't seem to get a hold of, how do I get to use different certificates for the handshake depending on the hostname being requested. I have seen so many suggestions talking about keymanagers and sslcontext but none of that seem to be able to dynamically change the certificate used for sslhandshake depending on the differing hostname being requested.
I am sorry for the very verbose question, I am new to all this, so please be a little patient with me.
EDIT: Considering implementing a keymanager and initializing sslcontext with it, and creating the serversocket, at the moment when the serversocket is being created there is no hostname being requested, so how do I create a keymanager that is dynamic unlike the fixedserveralias examples I have seen around.