![](/img/trans.png)
[英]How to specify accepted certificates for Client Authentication in .NET SslStream
[英]understanding server/proxy/client certificates with .NET sslstream
我正在使用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];
}
如果我强制客户端手动信任证书,这也很有效。
我的问题是:
我不想隧道SSL通信抛出代理,因为我需要读取和操作流。
[更新]是的我使用谷歌和StackOverflow中的搜索,我尝试了一些不同的解决方案,没有任何成功。 我还尝试了以下线程中的解决方案:
[UPDATE2]这是一个非常好的教程,用openssl创建CA和服务器证书,但它对我不起作用: http ://webserver.codeplex.com/wikipage?title = HTTPS&referenceTitle = Home
没有一个证书对所有请求都有效。 所以我的想法不起作用。 因为无法为每个域名生成单个许可证。
但答案比预期的要容易:要解决我的问题,我必须为每个请求创建一个证书。
我需要做的就是:
(这在提琴手中完全相同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.