WCF 使用 Https Web 服务,错误 : Could not establish trust relationship for the SSL/TLS secure channel with authority

标签 wcf security ssl certificate

连接到 https 网络服务服务器时出现此错误:

无法与权限建立 SSL/TLS 安全通道的信任关系

我正在使用消息层安全性,正文使用 CERT 证书加密。服务器证书的证书验证不受 ServicePointManager.ServerCertificateValidationCallback 委托(delegate)控制,我不能用它来接受证书。 https://xxxxx.com/callservice证书加载到调用服务器上,我做错了什么?一个加载证书的例子?

如果你有任何疑问,请告诉我来回答你。

网络配置

<system.serviceModel>
    <extensions>
      <bindingElementExtensions>
        <add name="SecurityBindingElement" type="Service.AsymetricSecurityExtentionElement, Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </bindingElementExtensions>
    </extensions>    
    <bindings>
      <customBinding>
        <binding name="SUMA">
          <MySecurityBindingElement/>
          <textMessageEncoding messageVersion="Soap11" />
          <httpsTransport/>
        </binding>
      </customBinding>
    </bindings>
    
    <client>
      <endpoint address="https://xxxxx.com/callservice"
        binding="customBinding" bindingConfiguration="SUMA" contract="ConsultaService"
        name="SUMA" behaviorConfiguration="cliBeh" >
        <identity>
          <certificateReference  storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="CERT"/>
        </identity>
      </endpoint>
    </client>
    
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>

          <serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="2147483647" maxConcurrentSessions="10" />

        </behavior>
      </serviceBehaviors>
      
      <endpointBehaviors>
        <behavior name="cliBeh">
          <clientCredentials>
            <clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="CERT"/>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
            
    </behaviors>
  </system.serviceModel>

非常感谢您的帮助。

最佳答案

我让服务器不返回这个错误消息,在serviceCertificate部分添加以下内容

<sslCertificateAuthentication trustedStoreLocation="CurrentUser" certificateValidationMode="PeerOrChainTrust"/>

Tenemos estas opciones para que el servidor verifique la autenticidad del certificado emitido por el cliente。 Se determina por el valor de certificateValidationMode, puede tomar estos valores.

ChainTrust:Busca un CA que sea válido y que esté registrado en el repositorio de autoridades de certificación del equipo,siguiendo una cadena de confianza。 Este es el valor por defecto si no se esspecifica otro modo.

PeerTrust:Busca el certificado en el repositorio de Trusted People (personas de confianza) del equipo。

PeerOrChainTrust:Busca en base a una de las dos opciones anteriores。

Custom:允许实现 una validación medida。 Para ello es necesario implementar una clase y asignarlo a la propied CustomCertificateValidatorType。

None:没有 se realiza validación alguna

一句问候

关于WCF 使用 Https Web 服务,错误 : Could not establish trust relationship for the SSL/TLS secure channel with authority,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43868837/

相关文章:

c# - WCF 客户端异常 : Unrecognized message version

c# - 如何拦截来自 WCF 客户端的 header ...?

python - 屏蔽掉 python 日志中的敏感信息

ruby-on-rails - 验证 ssl 证书以验证访问我们私有(private) api 的服务?

ssl - 我网站的 AWS 负载均衡器和 ssl 证书

WCF:代理打开和关闭 - whaaa?

wcf - (网站) 上的网页可能暂时关闭,或者可能已永久移至新网址

javascript - 实现客户端ajax登录,使用ajax注销安全还是需要刷新?

javascript - 公开 AWS Cognito ID 是否安全?

ssl - 无法绑定(bind)套接字 [0.0.0.0 :443] for HAproxy