2010-09-21 38 views
14

Tôi đang thử nghiệm phát hành sớm dịch vụ web WCF mà tôi đã tạo. Về phía khách hàng khi tôi sử dụng VS để 'thêm tham chiếu dịch vụ' mà tất cả các công trình.Làm thế nào để tạm dừng các lỗi chứng chỉ với các dịch vụ WCF

Nhưng khi tôi cố gắng sử dụng dịch vụ tôi nhận được lỗi,

Could not establish trust relationship for the SSL/TLS secure 
channel with authority ** 

đâu các ngôi sao đại diện cho địa chỉ IP của máy chủ.

Dù sao trên máy chủ có chứng chỉ bảo mật nhưng nó đã được tự tạo chỉ để thử nghiệm, vì vậy tôi không quan tâm đến lỗi chứng chỉ cho thời điểm này.

Về phía khách hàng một app.config đã được tạo ra cho tôi,

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="BindingName" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
        allowCookies="false"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="***************" 
       binding="wsHttpBinding" bindingConfiguration="BindingName" 
       contract="***************" name="BindingName"> 
       <identity> 
        <servicePrincipalName value="***************" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

Vì vậy, những gì các thiết lập sao tôi cần phải thay đổi để tạm thời bỏ qua lỗi giấy chứng nhận?

Trả lời

26

Đặt chứng chỉ PRIOR để khởi tạo dịch vụ WCF của bạn trên máy khách. Đây là cách (chỉ cần thực hiện cuộc gọi đến SetCertificatePolicy() phương pháp một lần)

/// <summary> 
    /// Sets the cert policy. 
    /// </summary> 
    private static void SetCertificatePolicy() 
    { 
     ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; 
    } 

    /// <summary> 
    /// Certificate validation callback 
    /// </summary> 
    private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) 
    { 
     if (error == SslPolicyErrors.None) 
     { 
      return true; // already determined to be valid 
     } 

     switch (cert.GetCertHashString()) 
     { 
      // thumbprints/hashes of allowed certificates (uppercase) 
      case "066CF9CAD814DE2097D368F22D3A7D398B87C4D6": 
      case "5B82C96685E3A20079B8CE7AFA32554D55DB9611": 

       Debug.WriteLine("Trusting X509Certificate '" + cert.Subject + "'"); 
       return true; 

      default: 
       return false; 
     } 
    } 
+0

đẹp bình luận - "điều khiển từ xa validate chứng chỉ." : P –

+0

Hehe, tôi đã không nhận thấy trước đây. Nó trông kỳ lạ. Tôi đã thay đổi nó. Cảm ơn! –

+0

Có vẻ như ValidateRemoteCertificate của tôi không bao giờ được gọi là ... bất kỳ manh mối nào tại sao? – guiomie

3

Kiểm tra câu trả lời cho câu hỏi này:

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

nó mang lại cho hai giải pháp khả thi: 1. chỉ sử dụng cấu hình các mục nhập ở phía máy khách hoặc 2. sử dụng trình xác thực chứng chỉ tùy chỉnh sử dụng cả mã và mục cấu hình

3

Sửa đổi công việc web.config ed cho tôi

Tôi đã làm điều đó bằng cách sử dụng câu trả lời của Steve Ellinger và một số googling. Về cơ bản, tôi đã phải:

  • tell quản lý các kết nối HTTP để sử dụng giấy chứng nhận mà không phù hợp với tên giấy chứng nhận với tên máy chủ máy chủ, và không có kiểm tra liệu chứng chỉ đã bị thu hồi
  • sửa đổi hành vi đầu cuối về phía khách hàng trong trật tự để tắt xác nhận giấy chứng nhận

Dưới đây là các đoạn web.config ...

<configuration> 

    <system.net> 
    <settings> 
     <servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" /> 
    </settings> 
    </system.net> 

    <system.serviceModel> 
    <client> 
     <endpoint ... behaviorConfiguration="DisableServiceCertificateValidation" /> 
    </client> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="DisableServiceCertificateValidation"> 
      <clientCredentials> 
      <serviceCertificate> 
       <authentication certificateValidationMode="None" 
           revocationMode="NoCheck" /> 
      </serviceCertificate> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 
+1

Cảm ơn, nó giúp. Tôi đã tìm thấy thêm một chút thông tin, xem [WCF Gotcha: Vô hiệu hóa xác thực SSL] (http://webservices20.blogspot.co.nz/2008/12/wcf-gotcha-disabling-ssl-validation.html) – cateyes

13
<configuration> 
    <system.net> 
    <settings> 
     <servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" /> 
    </settings> 
    </system.net> 
</configuration> 

Điều này phù hợp với tôi. Cảm ơn

2

Bạn cũng có thể ghi đè bằng công cụ trực tuyến này.

ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true; 

Đơn giản chỉ cần dán nó vào WCF constructor khách hàng tạo ra trong Reference.cs

[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
public partial class WebQuoteServiceClient : System.ServiceModel.ClientBase<Corp.Legal.Webservices.ServiceReference1.IWebQuoteService>, Corp.Legal.Webservices.ServiceReference1.IWebQuoteService { 

    public WebQuoteServiceClient() 
    { 
     ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true; 
    } 
Các vấn đề liên quan