簡體   English   中英

在 HTTPS 情況下,服務器證書沒有正確配置 HTTP.SYS

[英]server certificate is not configured properly with HTTP.SYS in the HTTPS case

我需要使用第三方 WCF 服務。 我已經在我的證書存儲中配置了所需的證書,但是在調用 WCF 服務時出現以下異常。

https://XXXX.com/AHSharedServices/CustomerServiceJAXWSController發出 HTTP 請求時發生錯誤。 這可能是由於在 HTTPS 情況下未使用 HTTP.SYS 正確配置服務器證書這一事實。 這也可能是由於客戶端和服務器之間的安全綁定不匹配造成的。

我咨詢了服務供應商,他們說一切都很好,其他人已經在使用這項服務。 他們提到當請求來自我的 IP 地址時,他們的服務沒有收到證書內容。 他們將其監控到了wireshark中並且證書的長度為0

以下是我的客戶端配置。 我在這里錯過了什么嗎?

            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
              <startup>
                <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
              </startup>
              <system.diagnostics>
                <sources>
                  <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
                    <listeners>
                      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                      </add>
                      <add name="ServiceModelMessageLoggingListener">
                        <filter type="" />
                      </add>
                    </listeners>
                  </source>
                </sources>
                <sharedListeners>
                  <add initializeData="D:\Log\MessageLog.svclog"
                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                    <filter type="" />
                  </add>
                </sharedListeners>
                <trace autoflush="true" />
              </system.diagnostics>
              <system.serviceModel>
                <behaviors>
                  <endpointBehaviors>
                    <behavior name="endpointBehavior">
                      <clientCredentials>
                        <clientCertificate findValue="XXX.XX.com" storeName="AddressBook"
                          x509FindType="FindBySubjectName" />
                        <serviceCertificate>
                          <authentication revocationMode="NoCheck" />
                        </serviceCertificate>
                      </clientCredentials>
                    </behavior>
                  </endpointBehaviors>
                </behaviors>
                <bindings>
                  <wsHttpBinding>
                    <binding name="wsBinding">
                      <security mode="Transport">
                        <transport clientCredentialType="Certificate" />
                      </security>
                    </binding>
                  </wsHttpBinding>
                </bindings>
                <client>
                  <endpoint address="https://XXXX.com/AHSharedServices/CustomerServiceJAXWSController"
                    behaviorConfiguration="endpointBehavior" binding="wsHttpBinding"
                    bindingConfiguration="wsBinding" contract="ServiceReference1.CustomerServiceJAXWSController"
                    name="testService" />
                </client>
                <diagnostics>
                  <messageLogging logEntireMessage="true" logMalformedMessages="true"
                    logMessagesAtTransportLevel="true" logKnownPii="true"  logMessagesAtServiceLevel="true"/>
                </diagnostics>
              </system.serviceModel>
            </configuration>

我曾經收到此錯誤,因為我的客戶端使用的是 TLS 1.0 而不是 TLS 1.2。 假設您安裝了所有正確的 SSL 密碼,您可以嘗試更改您的請求以使用 TLS 1.2。 在 .NET 中,您可以在定義客戶端后添加以下內容:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

一旦我切換到 TLS 1.2,錯誤就消失了。

我從 .CRT 和 .KEY 生成了 PFX(附有私鑰的證書)並將其導入到證書存儲中,這解決了我遇到的問題。

在向服務器發送請求之前使用此代碼:

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    return true;
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM