Ars*_*ray 7 c# ssl fiddler fiddlercore
我正在尝试使用FiddlerCore实现系统内SSL服务器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace fiddlerCoreTest
{
using System.IO;
using System.Threading;
using Fiddler;
class Program
{
static Proxy oSecureEndpoint;
static string sSecureEndpointHostname = "localhost";
static int iSecureEndpointPort = 7777;
static void Main(string[] args)
{
//var tt = Fiddler.CertMaker.GetRootCertificate().GetRawCertData();
//File.WriteAllBytes("root.crt",tt);
Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS)
{
oS.bBufferResponse = false;
if ((oS.hostname == sSecureEndpointHostname)&&oS.port==7777)
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers.HTTPResponseStatus = "200 Ok";
oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
oS.oResponse["Cache-Control"] = "private, max-age=0";
oS.utilSetResponseBody("<html><body>Request for httpS://" + sSecureEndpointHostname + ":" + iSecureEndpointPort.ToString() + " received. Your request was:<br /><plaintext>" + oS.oRequest.headers.ToString());
}
};
FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
oFCSF = (oFCSF & ~FiddlerCoreStartupFlags.RegisterAsSystemProxy);
Fiddler.FiddlerApplication.Startup(8877, oFCSF);
oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, sSecureEndpointHostname);
if (null != oSecureEndpoint)
{
FiddlerApplication.Log.LogFormat("Created secure end point listening on port {0}, using a HTTPS certificate for '{1}'", iSecureEndpointPort, sSecureEndpointHostname);
}
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Firefox中,GET http://localhost:7777/工作正常,但是当我获取时https://localhost:7777/,firefox会报告以下错误:
为什么我会这样做,我该如何解决?
更新
只有当我使用fiddler作为firefox的代理时才会发生这种情况.当我删除fiddler代理时,我可以访问https://localhost:7777/.但是,我也希望能够https://localhost:7777/通过代理访问
这种情况下的问题是您要处理此流量两次:
首先,浏览器向端口 8888 发送 CONNECT 消息:“请给我一个到端口 7777 的 TCP/IP 隧道”,然后在 Fiddler 说“好吧,我们会这样做”之后,客户端通过该隧道向端口发送 HTTPS 请求7777.
这里的问题是,您正在破坏 CONNECT 响应并返回 HTML,而不是允许来自端口 7777 的 HTTPS 握手流过。
解决此问题的最简单方法是将 BeforeRequest 代码更改为以下内容:
if ( (oS.hostname == sSecureEndpointHostname) && (oS.port==7777)
&& !oS.HTTPMethodIs("CONNECT")) {
Run Code Online (Sandbox Code Playgroud)
执行此操作后,您的 CONNECT 隧道将不再受到破坏,并且 HTTPS 握手将成功。
| 归档时间: |
|
| 查看次数: |
2109 次 |
| 最近记录: |