Как установить доверительные отношения для безопасного канала WCF SSL/TLSC#

Место общения программистов C#
Anonymous
Как установить доверительные отношения для безопасного канала WCF SSL/TLS

Сообщение Anonymous »

У нас есть клиент-серверное приложение, в котором для связи используется WCF. Как правильно связать сертификат со службой WCF с помощью app.config. Прямо сейчас я определяю сертификат в app.config на сервере следующим образом: На стороне клиента я присваиваю сертификат программно следующим образом:

Код: Выделить всё

   X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, "5b92cf508b894aec82074514954185ecd78b654a", true); //I am seeing the certificate correctly. Please see the screenshot below.

InstanceContext context = new InstanceContext(callback);
this.SystemService = new SystemServiceClient(context, tcpBinding, tcpAddress);
this.SystemService.ClientCredentials.ClientCertificate.Certificate = certificates[0];
При отладке правильно отображается сертификат на стороне клиента, как показано ниже:
Изображение

При попытке установить соединение со службой WCF с помощью строки string[] lstIFs = this.ServerConnection.NetworkService .GetNetworkInterfaces(); мы получаем следующую ошибку: «System.ServiceModel.Security.SecurityNegotiationException Не удалось установить доверительные отношения для безопасного канала SSL/TLS с полномочиями».
Изображение

Изменить
Вот трассировка стека для исключения
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

Код: Выделить всё

   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at EchoAdminClient.SystemService.INetworkSettingService.GetNetworkInterfaces()

at EchoAdminClient.SystemService.NetworkSettingServiceClient.GetNetworkInterfaces() in C:\Git\EchoAdminForEcho65XPlus\EchoAdminClient\Connected Services\SystemService\Reference.cs:line 843

at EchoAdminClient.MainForm.UpdateNetworkSettings() in C:\Git\EchoAdminForEcho65XPlus\EchoAdminClient\MainForm.cs:line 556

at EchoAdminClient.MainForm.ConnectServer() in C:\Git\EchoAdminForEcho65XPlus\EchoAdminClient\MainForm.cs:line 495
И данные и внутреннее исключение следующие:

Код: Выделить всё

Data: "Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost:8080'."

Type: System.ServiceModel.Security.SecurityNegotiationException
Внутреннее исключение:

Код: Выделить всё

"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

Type: System.Exception {System.Net.WebException}
Если мы посмотрим дальше, то обнаружится еще одно внутреннее исключение, которое гласит:

Код: Выделить всё

{"The remote certificate is invalid according to the validation procedure."}

Type: System.Exception {System.Security.Authentication.AuthenticationException}
Вот скриншот сертификата:
[img]https://i.sstatic.net /fzRm7Be6.png[/img]


Подробнее здесь: https://stackoverflow.com/questions/785 ... re-channel

Вернуться в «C#»