![](/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.