I am trying to create a reverse proxy using Fiddler.Core which we can use to replay third party requests over http(s).
The lib works great for http, for for https, I seem to be lacking a step, as replaying the response simply seems to timeout.
Here is the code for the specs:
[TestClass]
public class Verify_basic_proxy_functionality
{
WebClient WC;
Proxy SUT;
[TestInitialize]
public void Init()
{
SUT = new Proxy();
SUT.InsertSession(Url:"http://proxy/ping",ResponseBody:"pong");
var uri = SUT.Startup(9100,IsRecording: false);
WC = new WebClient() { Proxy = new WebProxy(uri)};
}
[TestMethod]
public void Ping_should_return_pong()
{
WC.DownloadString("http://proxy/ping").ShouldBe("pong");
}
[TestMethod]
[ExpectedException(typeof(WebException))]
public void Pang_should_return_error()
{
WC.DownloadString("http://proxy/pang");
}
[TestMethod]
public void Http_reverse_proxy_should_work()
{
SUT.IsRecording = true;
var http_url = "http://httpbin.org/ip";
var initial_result = WC.DownloadString(http_url);
initial_result.ShouldContain("origin");
SUT.IsRecording = false;
var result = WC.DownloadString(http_url);
result.ShouldBe(initial_result);
}
// This one fails with a timeout... Probably need to close the connection or similar?
[TestMethod]
public void Https_reverse_proxy_should_work()
{
SUT.IsRecording = true;
var https_url = "https://httpbin.org/ip";
var initial_result = WC.DownloadString(https_url);
initial_result.ShouldContain("origin");
SUT.IsRecording = false;
var result = WC.DownloadString(https_url);
result.ShouldBe(initial_result);
}
}
The code for the proxy can be found over at this gist: https://gist.github.com/ToJans/5082560
I think I might need to add an extra step for https (i.e. encoding). AFAIK fiddler.core ignores certificate errors as I intercept the OnValidateServerCertificate
and always return true.
Who can tell me what I am doing wrong here?
Well, a collegue of mine pointed me to a flaw in my thinking; when doing replay for SSL you should not record/replay the CONNECT!!!
MITM proxy works now.....