Description
While working on the PR for issue #288, I started to wonder if it would be a good idea to add the initial HttpRequest for the HTTP CONNECT as a parameter to the MitmManager methods. This would allow the MitmManager to impersonate a host based on the Host header from the client, rather than on the actual hostname or the actual certificate returned by the upstream server. I can think of a few cases when the host requested by the client would not match the upstream server's hostname or server's certificate:
- A DNS server or filter has changed the DNS resolution of the client-requested host to resolve to some other host.
- Both of the following conditions are true:
- SNI is not being used (working on that for Supporting fallback for Java's unrecognized_name error with SNI #288), in which case the MitmManager can't get the hostname from sslContext.getPeerHost().
- The certificate returned by the upstream server contains some other hostname (i.e. it is an invalid certificate) and/or condition (1) above.
Adding in the initialRequest to the MitmManager would allow the MitmManager to return a valid certificate to the client. It would still be up to the MitmManager to determine whether or not to trust the upstream server, just as it is today, but at least the client would trust the MitmManager's certs.
What do you think, @ganskef? This would of course be a breaking change to MitmManager, so I always want to be cautious about such things.