gpt4 book ai didi

c# - SSL在用fiddler修改请求时收到超过最大允许长度的记录

转载 作者:太空狗 更新时间:2023-10-29 20:36:59 28 4
gpt4 key购买 nike

我正在尝试使用 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();
}
}
}

在 firefox 中,GET http://localhost:7777/ 工作正常,但是当我 GET https://localhost:7777/ 时,firefox 报告以下错误:

SSL received a record that exceeded the maximum permissible length

为什么会出现这个问题,我该如何解决?

更新只有当我使用 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")) {

执行此操作后,您的 CONNECT 隧道将不再被破坏,并且 HTTPS 握手将成功。

关于c# - SSL在用fiddler修改请求时收到超过最大允许长度的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14176673/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com