gpt4 book ai didi

c# - 使用 WCF 服务在 .NET 中禁用 X.509 证书验证

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:07 24 4
gpt4 key购买 nike

我正在尝试在 WCF 服务中设置消息安全性并在此过程中禁用 X.509 证书验证。我只想用用户名和密码验证客户端,根本不验证服务器。至少现在是这样。

这里引用第一个答案:

How do I tell WCF to skip verification of the certificate?

如何在客户端以编程方式实现以下目标?

<behavior name="DisableServiceCertificateValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="Custom"
customCertificateValidatorType="MyCertificateValidator, Client"
revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>

我有这个:

With myServiceClient.ClientCredentials
.UserName.UserName = "username"
.UserName.Password = "password"
.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom
.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck
End With

我不知道如何设置“customCertificateValidatorType”以及如何将它连接到 MyCertificateValidator 类。

这是否绕过了客户端证书、服务器证书或两者的要求?

这是我的服务器 web.config 文件。

<?xml version="1.0"?>
<configuration>

<system.web>
<customErrors mode="Off"/>
<trust level="Full"/>
<compilation debug="true"/>
</system.web>

<system.serviceModel>

<services>

<service name="HelloWorldService.HelloWorldService" behaviorConfiguration="BehaviourMessageSecurity">

<endpoint address ="" binding="wsHttpBinding" contract="HelloWorld.IHelloWorldService" bindingConfiguration="BindingMessageSecurity"/>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

<host>
<baseAddresses>
<add baseAddress="http://www.example.com/HelloWorldService.svc"/>
</baseAddresses>
</host>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="BehaviourMessageSecurity">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="HelloWorldService.ServiceAuthenticator, HelloWorldService" />
<serviceCertificate findValue="localhost" x509FindType="FindBySubjectName"
storeLocation="LocalMachine" storeName="My" />
</serviceCredentials>
</behavior>

</serviceBehaviors>

</behaviors>

<bindings>
<wsHttpBinding>

<binding name="BindingMessageSecurity">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>

</wsHttpBinding>
</bindings>

</system.serviceModel>

<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>

</configuration>

最佳答案

Czustom 意味着您编写自己的验证方法。如果您根本不想检查证书,请使用无:

.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None

关于c# - 使用 WCF 服务在 .NET 中禁用 X.509 证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23486907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com