2013-12-20 84 views
1

我正在開發一個WCF服務,該服務必須使用用戶名憑據在HTTPS上運行,並且發現在IIS上運行的測試解決方案中可以使用以下配置:使用HTTPS配置WCF服務

服務器配置:

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

    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <customErrors mode="Off" /> 
    </system.web> 

    <system.serviceModel> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Behavior1"> 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Service.UserNamePassValidator, Service" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <bindings> 
     <wsHttpBinding> 
     <binding name="Binding1"> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

    <services> 
     <service behaviorConfiguration="Behavior1" name="Service.Service"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="https://localhost/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="Service.IService" /> 
     <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 

    </system.serviceModel> 

</configuration> 

客戶端配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.serviceModel> 

    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IService"> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

    <client> 
     <endpoint address="https://localhost:44303/UsernamePasswordService.svc" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" 
     contract="ServiceReference1.IService" name="WSHttpBinding_IService" /> 
    </client> 

    </system.serviceModel> 
</configuration> 

客戶端在我的方案是一個WinForms應用程序。

我是很新的構式這一點,只是想確認這是否是用於HTTPS(SSL)使用用戶名憑據的有效/設置好?

由於我使用的是自簽名證書,我必須繞過客戶端證書的驗證,因此我不覺得我可以清楚地看到這將有效證書工作。

我想象它的工作方式是,服務器開始通信時,然後在客戶端加密所有發送到與客戶端證書的服務器的流量經過客戶端證書給客戶端。該流量隨後通過服務器端的服務器證書進行解密。

但這是它的工作方式?現在它的配置方式是,僅在IIS偵聽端口上指定證書,那麼它是否會根據每個請求的服務器證書爲客戶端生成證書?或者來自客戶端的流量是否未加密?

我想對我的要求運行小提琴手並啓用了HTTPS進行解密,並注意到我可以閱讀在XML純文本用戶名和密碼。這是因爲小提琴手會通過我的證書加密來讀取一些魔法或者發送的消息根本沒有加密?

在這種情況下,我必須自己加密和解密數據嗎?

我不想在客戶端安裝證書。

回答

0

簡短的回答你的第一個問題是,在我看來,是 - HTTPS(SSL)與用戶名的憑證可以是一個有效的安全配置。使用WSHttpBinding實現WS-Security規範,並提供與實現WS- *規範的服務的互操作性。

參考:http://msdn.microsoft.com/en-us/library/ms731172(v=vs.110).aspx

爲了提供任何進一步的評估,人們會需要比較對你的系統的需求是解決方案的安全性。

老實說,我沒有完全理解這個問題的其餘部分,雖然我收集您在使用使用自簽名證書的客戶蘊涵的擔憂。這就是說,通過以下鏈接(至少一個)應該提供一些指導:

http://msdn.microsoft.com/en-us/library/ff648840.aspx
http://www.codeproject.com/Articles/570539/HTTPSplusCommunicationplusinplusWCFplususingplusSe
http://blog.adnanmasood.com/2010/04/29/step-by-step-guide-for-authenticating-wcf-service-with-username-and-password-over-ssl/