我正在使用C#和TcpListener创建一个TCP代理服务器,使用TcpCLient实现客户端与代理服务器以及代理服务器与目标服务器之间的通信。这种方式运行得非常好。
我还需要支持SSL和TLS加密通信。这基本上可以实现。我使用以下代码从代理服务器到目标服务器创建了一个SslStream:
证书从X509Store加载:
我还需要支持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通信,因为我需要读取和操作流。
[更新] 是的,我使用了谷歌和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