[英]How to avoid setting DnsEndpointIdentity on client side
所以基本上我有一個應用程序,我有一個客戶端和兩個通過 netTcpBinding 或 netNamedPipe 公開端點的服務。 此外,服務和客戶端之間的整個通信都通過證書進行保護(現在我使用的是自信任證書)。
它工作正常,但在創建EndpointAddress實例期間,我還需要使用服務端使用的證書名稱設置DnsEndpointIdentity 。 所以它看起來像這樣:
new EndpointAddress(serviceUrl, new DnsEndpointIdentity("MyCertificateName"));
所以我的問題是:這正常嗎? 有沒有辦法避免在客戶端設置它?
這是正常現象,身份不能無知,它代表了服務器的身份。 第三方可以冒充服務程序讓客戶端調用,以達到竊取客戶端信息的目的。 為確保客戶端不會找到錯誤的服務器,證書(主題)中的主機名必須與客戶端提供的主機名(DNS 身份)相同。 我們也可以使用證書的公鑰作為身份,因為證書的公鑰對外部是公開的。
<identity>
<rsa value="...."/>
</identity>
這是獲取證書公鑰的示例代碼。
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = null;
foreach (var certificate in store.Certificates)
{
if (certificate.Subject.Contains("myhostname"))
{
cert = certificate;
break;
}
}
if (cert==null)
{
return;
}
//output the public key
string xmlKey = cert.PublicKey.Key.ToXmlString(false);
//encoded
string encodedkey = System.Net.WebUtility.HtmlEncode(xmlKey);
Console.WriteLine($"Public key:\n{encodedkey}");
store.Close();
store.Dispose();
順便說一句,這些配置可以在使用“添加服務引用”對話框調用服務時自動生成。
如果有什么我可以幫忙的,請隨時告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.