- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个充当代理服务器的控制台应用程序。现在我也喜欢实现 SSL。不喜欢解密任何流量。就像普通的 https 代理一样。我不确定我该如何继续。
var host = text.Remove(0, connectText.Length + 1);
var hostIndex = host.IndexOf(" ", StringComparison.Ordinal);
var hostEntry = host.Remove(hostIndex).Split(new []{":"}, StringSplitOptions.None);
requestClient.Connect(hostEntry[0], Convert.ToInt32(hostEntry[1]));
requestStream = requestClient.GetStream();
var sslStream = new SslStream(requestStream, false, (x1,x2,x3,x4) => true);
sslStream.AuthenticateAsClient(hostEntry[0]);
const string sslResponse = "HTTP/1.0 200 Connection established\r\n\r\n";
var sslResponseBytes = Encoding.UTF8.GetBytes(sslResponse);
proxyStream.Write(sslResponseBytes, 0, sslResponseBytes.Length);
proxyStream.Flush();
我应该直接将所有内容写入sslStream吗?浏览器连接proxyClient
呢?我是否也需要包装流,或者我是否可以将所有内容直接写入 proxyStream
?我应该使用 AuthenticateAsServer 并以某种方式传递来自 AuthenticateAsClient 的证书吗?
我看到了这个,但是如何在没有假证书的情况下进行 AuthenticateAsServer。我可以像在我的正常流中那样写吗,还是我应该考虑一些事情?
static void Main(string[] args)
{
var tcpServer = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080);
tcpServer.Start();
while (true)
{
var proxyClient = tcpServer.AcceptTcpClient();
var requestClient = new TcpClient();
var proxyStream = proxyClient.GetStream();
NetworkStream requestStream = null;
var bytes = new byte[proxyClient.ReceiveBufferSize];
var hostHeaderAvailable = 0;
int count;
while (proxyStream.DataAvailable)
{
count = proxyStream.Read(bytes, 0, bytes.Length);
if (hostHeaderAvailable == 0)
{
var text = Encoding.UTF8.GetString(bytes);
const string connectText = "connect";
const string hostText = "Host: ";
//HTTPS NOT FULLY IMPLEMENTED YET
if (text.ToLower().StartsWith(connectText))
{
var host = text.Remove(0, connectText.Length + 1);
var hostIndex = host.IndexOf(" ", StringComparison.Ordinal);
var hostEntry = host.Remove(hostIndex).Split(new []{":"}, StringSplitOptions.None);
requestClient.Connect(hostEntry[0], Convert.ToInt32(hostEntry[1]));
requestStream = requestClient.GetStream();
var sslStream = new SslStream(requestStream, false, (x1,x2,x3,x4) => true);
sslStream.AuthenticateAsClient(hostEntry[0]);
const string sslResponse = "HTTP/1.0 200 Connection established\r\n\r\n";
var sslResponseBytes = Encoding.UTF8.GetBytes(sslResponse);
proxyStream.Write(sslResponseBytes, 0, sslResponseBytes.Length);
proxyStream.Flush();
}
//HTTP WORKS LIKE A CHARM
else {
var hostIndex = text.IndexOf(hostText, StringComparison.Ordinal);
if (hostIndex < 0)
continue;
var host = text.Remove(0, hostIndex + hostText.Length);
hostIndex = host.IndexOf("\n", StringComparison.Ordinal);
if (hostIndex < 0)
continue;
host = host.Remove(hostIndex).Replace("\r", "");
requestClient.Connect(host, 80);
requestStream = requestClient.GetStream();
}
}
hostHeaderAvailable++;
if (requestClient.Connected) {
requestStream.Write(bytes, 0, count);
}
}
if (!requestClient.Connected) {
proxyStream.Close();
proxyClient.Close();
continue;
}
var timeout = 0;
while (!requestStream.DataAvailable) {
if (timeout > 12)
break;
Thread.Sleep(500);
timeout++;
}
while (requestStream.DataAvailable)
{
count = requestStream.Read(bytes, 0, bytes.Length);
proxyStream.Write(bytes, 0, count);
}
proxyStream.Close();
proxyClient.Close();
}
}
最佳答案
IE issues a CONNECT request to my proxy My proxy sees that its a CONNECT request and gets the ip:port of the destination (eg, www.hotmail.com:443) My proxy creates a new TCP connection to www.hotmail.com:443
目前一切正确。
My proxy gets an SslStream from this destination and calls AuthenticateAsClient - this gives my proxy a secure connection to the hotmail side of things
没有。您的代理应该使用您已有的纯文本连接。
My proxy then sends an "HTTP/1.0 200" message back to the browser to say that the CONNECT was successful.
正确。或者,如果您遇到连接失败,您会发回适当的 HTTP 失败响应。
My proxy then gets an SslStream from the browser connection and calls AuthenticateAsServer - gives my proxy a secure connection to the browser side of things
没有。您的代理继续使用明文连接到浏览器。
how AuthenticateAsServer without fake certificate?
您根本不必这样做。
此时浏览器和上游服务器准备执行SSL握手。但是正如您所说,您不想嗅探内容,您自己无需成为 SSL 端点。您现在要做的就是同时在两个方向上复制字节。端点将进行 SSL 握手,就像您不在场一样。
关于c# - HTTPS 代理实现 (SSLStream),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24195011/
当远程客户端未发送任何内容时,我遇到了 SSLStream 返回一些数据的问题。当服务器正在监听新命令时,我遇到了这个问题。如果服务器没有收到新的请求,ReadMessage() 函数应该捕获一个 I
我最近在将套接字通信转换为使用 System.Net.Security.SslStream 而不是 NetworkStream 时遇到了一个问题。此转换针对 .Net Framework 4.8 项目
我正在尝试使用 SslStream 和 TLS 1.2 协议(protocol)与远程服务器建立 TCP 连接。代码如下: _tcpClient.Connect(endPoint); var cert
我正在尝试使用 TLS (openssl) 实现客户端-服务器应用程序。我按照 rust doc 中给出的示例作为我的代码结构:example 服务器代码 fn handle_client(mut s
当我尝试从 SslStream 函数读取时,如果我没有设置连接超时,Read() 永远不会结束,但如果我设置了连接超时异常。这家伙有同样的问题http://msdn.microsoft.com/en-
我正在尝试通过 C# .Net 应用程序中的 SslStream 连接到服务器。 当我尝试向服务器进行身份验证时,我在客户端收到一条错误消息,显示从传输流中收到了意外的 EOF 或 0 字节。 在服务
我用 C# 制作了一个简单的 ftp 客户端,它可以满足我的需要(连接到 ftp,可以选择使用代理),但我也希望能够使用 AUTH SSL。 因此,我查看了 SslStream 而不是 Network
我有一个多线程异步System.Net.Socket,它监听一个端口。如果我收到来自 HTTP 的请求,我没有任何问题,但最近我不得不向我的应用程序添加 https 支持。 客户给了我一个.arm认证
我正在尝试编写一个客户端-服务器库,让我的 LAN 计算机相互通信。由于这在很大程度上是一种自学尝试,因此我试图通过 SSL 建立这些连接。我的计划是维护一台主机,并让每个客户端维护一个到主机的相互验
各位,我正在尝试写一些关于 SSL 的文章,这里是问题: 我在下面构建了一些东西: CA 证书(自制 CA) Server pfx, Server cert, Server key(由自制的CA签发到
我正在尝试对存在证书交换的客户端进行身份验证。我遇到的问题是 openssl 客户端拒绝连接尝试,因为身份验证握手中没有包含任何证书颁发机构。 这对于在 Windows Server 2008 R2
我正在尝试连接到 SSL TCP 服务器,它可以在我的浏览器上运行,并且我可以收到硬编码的响应。在应用程序上,当使用 ReadLine 函数时抛出异常。 Error: System.ArgumentE
伙计们,我正在使用 SslStream 作为服务器来测试我的应用程序,但我在从流中读取时遇到了问题。我正在使用以下代码: while (true) {
我正在设计一个基于客户端服务器架构的系统 - 基于 TCP。要求服务器和客户端之间的所有消息都应该加密。所以我正在考虑在 .NET Framework 中使用 SslStream 类。 从 SslSt
我有这个代码: string certificateFilePath = @"C:\Users\Administrator\Documents\Certificate.pfx"; string cer
我看了很长时间的 MSDN 信息文章,但我仍然无法理解。 基于不需要客户端身份验证的假设: 1.当我调用SslStream.AuthenticateAsServer(...)时,我是在服务器端还是在客
我对处理套接字时“最好”使用什么感到困惑。 Socket 对象提供 Send/Receive 方法(和异步等效方法),但也允许创建 NetworkStream。我对使用 Socket.Send 感到高
我正在开发 C# SSL 客户端。 这是单向证书验证。我的客户需要进行服务器证书验证。 我已将 RemoteCertificateValidationCallback 添加到 SslStream。 目
我目前正在尝试使用 TcpClient 连接到 FTP 服务器。 为了使用 FTPS 作为协议(protocol),我通过 NetworkStream 处理一个单独的方法,该方法使用该方法创建一个 S
当使用 SSLStream 向(已经过身份验证的)客户端发送“大”数据 block (1 兆)时,我看到的数据包碎片/分解是 远大于使用普通 NetworkStream 时。 在客户端使用异步读取(即
我是一名优秀的程序员,十分优秀!