title: Using Charles Web Proxy as an Https Reverse Proxy
body: <p>I am using the great Charles Web Proxy do make a reverse proxy and debug an exchange between my client and a secure server.I accepted the Charles certificate as a trusted authority and it works generally very well when using it in Proxy Mode, the problem is when I try to make a reverse proxy.</p>
  
  <p>I am using an external library over which I have no control that uses an HttpUrlConnection and lets me specify the URL. Following the <a href="http://www.charlesproxy.com/documentation/proxying/reverse-proxy/" rel="noreferrer">Charles documentation</a>, I set my URL to <code>https://mybox.test.com:100</code> (note that I used a hostname, added to my host file, instead of localhost in the hope that I can have a valid certificate).</p>
  
  <p>The problem is that as part of the Https validation, HttpUrlConnection verifies the host name (mybox.test.com since it is pointing to my reverse proxy) against the one in the certificate (the one of the secure site I am connecting to). Obviously that does not match and causes a
  Caused by: javax.net.ssl.SSLHandshakeException: <code>java.security.cert.CertificateException: No subject alternative DNS name matching localhost found.</code></p>
  
  <p>I realize that Charles cannot generate a certificate for mybox.test.com, since it only listens to a particular port and has no knowledge of the URL used in the HttpUrlConnection. I do not see how it could generate a correct certificate that would be accepted.</p>
  
  <p>My question is: is there a better way to use a reverse proxy with Https or do I need to disable the host name and certificate validation ?</p>