【发布时间】:2013-01-14 12:05:29
【问题描述】:
我正在使用 C# 创建一个 TCP 代理,使用 TcpListener 作为代理服务器,使用 TcpCLient 进行客户端和代理之间以及代理和目标服务器之间的通信。这真的很好用。
我还必须支持 SSL 和 TLS 加密通信。 这几乎可以正常工作。我使用以下代码创建了从代理到目标服务器的 SslStream:
var sslStream = new SslStream(remoteStream, false);
sslStream.AuthenticateAsClient(state.RemoteHost);
我使用以下代码创建了一个从代理到客户端的 SslStream:
var sslStream = new SslStream(state.ClientStream, false);
sslStream.AuthenticateAsServer(certificate, false, SslProtocols.Tls | SslProtocols.Ssl3 | SslProtocols.Ssl2, true);
证书是从 X509Store 加载的:
X509Certificate2 certificate;
var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName, "CN=localhost", false);
store.Close();
if (certificates.Count == 0)
{
Console.WriteLine("Server certificate not found...");
return;
}
else
{
certificate = certificates[0];
}
如果我强制客户端手动信任证书,这也很有效。
我的问题是:
- 如何强制(所有)客户端信任证书?
- 代理上需要哪种证书对所有客户端都有效?
- 如果需要,我必须安装哪种客户端证书才能强制客户端信任代理?
- 如何使用 openssl 或 makecert 创建所需的代理类型?
我不想通过隧道传递 SSL 通信,因为我需要读取和操作流。
[更新] 是的,我使用了 Google 和 StackOverflow 中的搜索,我尝试了一些不同的解决方案,但没有成功。 我还尝试了以下线程中的解决方案:
SSLStream example - how do I get certificates that work?
How do I identify my server name for server authentication by client in c#
[更新2] 这是使用 openssl 创建 CA 和服务器证书的非常好的教程,但它对我不起作用: http://webserver.codeplex.com/wikipage?title=HTTPS&referringTitle=Home
【问题讨论】:
标签: c# ssl proxy certificate sslstream