2010-09-24 21 views
8

我需要爲第三方提供服務,該服務將發送帶有簽名時間戳的SOAP消息。帶WS-Security的WCF服務僅需要簽名時間戳

如何配置我的服務來支持此功能?

UPDATE 我設法去接近SOAP消息的,我們是後但WCF堅持雙方簽訂的用戶名和時間戳標記的格式,是否有修改 結合的方式只簽署時間戳?


進一步更新 這裏是我們的要求:

  • 的Timestamp元素必須簽名。
  • 用於簽名的證書上的CN名稱必須與UsernameToken元素中的用戶名一致。
  • 用於簽名的證書務必在BinarySecurityToken元素中發送。
  • KeyInfo元素必須只包含一個SecurityTokenReference元素,它必須被用來引用BinarySecurityToken。
  • 必須指定規範化算法。
  • 必須指定SignatureMethod,並且必須是SHA-1或SHA-2算法。
  • 獨立簽名應該被使用。

有什麼建議?

當前設置

客戶端綁定

<bindings> 
    <wsHttpBinding> 
    <binding name="WSBC"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None"></transport> 
     <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

客戶終端

<client> 
    <endpoint address="https://localhost/WcfTestService/Service2.svc" 
    behaviorConfiguration="CCB" binding="wsHttpBinding" 
    bindingConfiguration="WSBC" 
    contract="ServiceReference2.IService2" 
    name="wsHttpBinding_IService2" /> 
</client> 

客戶行爲

<behaviors> 
    <endpointBehaviors> 
    <behavior name="MBB"> 
     <clientCredentials> 
     <clientCertificate findValue="03 58 d3 bf 4b e7 67 2e 57 05 47 dc e6 3b 52 7f f8 66 d5 2a" 
          storeLocation="LocalMachine" 
          storeName="My" 
          x509FindType="FindByThumbprint" /> 
     <serviceCertificate> 
      <defaultCertificate findValue="03 58 d3 bf 4b e7 67 2e 57 05 47 dc e6 3b 52 7f f8 66 d5 2a" 
           storeLocation="LocalMachine" 
           storeName="My" 
           x509FindType="FindByThumbprint" /> 
     </serviceCertificate> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

服務綁定

<bindings> 
    <wsHttpBinding> 
    <binding name="ICB"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None"></transport> 
     <message clientCredentialType="UserName" 
        negotiateServiceCredential="false" 
        establishSecurityContext="false" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

的貢獻莫過於端點

<service name="WcfTestService.Service2" behaviorConfiguration="SCB"> 
    <endpoint  address="" binding="wsHttpBinding" contract="WcfTestService.IService2" 
    bindingConfiguration="ICB" name="MS" /> 
</service> 

服務行爲

<behaviors> 
    <serviceBehaviors> 
    <behavior name="SCB"> 
     <serviceCredentials> 
     <serviceCertificate  findValue="4d a9 d8 f2 fb 4e 74 bd a7 36 d7 20 a8 51 e2 e6 ea 7d 30 08" 
           storeLocation="LocalMachine" 
           storeName="TrustedPeople" 
           x509FindType="FindByThumbprint" /> 
     <userNameAuthentication 
      userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="WcfTestService.UsernameValidator, WcfTestService" /> 
     <clientCertificate> 
      <authentication certificateValidationMode="None" revocationMode="NoCheck" /> 
     </clientCertificate> 
     </serviceCredentials> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
+1

你是否設法使配置工作,以便只有Timestamp元素被簽名?我目前正試圖達到同樣的目的。 – Edward 2011-05-06 15:17:36

回答

3

你可能要考慮的是實現了安全只是你想要的方式自定義安全綁定類,而比WCF默認。

這些MSDN鏈接解釋自定義綁定和SecurityBindingElement抽象基類:

http://msdn.microsoft.com/en-us/library/ms730305.aspx

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.securitybindingelement.aspx

+0

這不是我!我一直在拉我的頭髮,以獲得一個自定義綁定產生正確的結果!我應該更新的問題,因爲現在基本上我想要的是basicHttpBinding(Soap 1.1)與安全模式= TransportWithMessageCredential同時具有消息和傳輸證書。但另外我們需要發送/接收UsernameToken以及..! – 2011-03-03 23:30:13

+0

感謝評論@Dog Ears,你認爲值得用更具體的要求創建一個新問題嗎? – 2011-03-04 05:23:10

0

你可以用消息協定爲此,請參閱:http://msdn.microsoft.com/en-us/library/ms730255.aspx

下面是一個例子從上面的鏈接:

[MessageContract] 
public class PatientRecord 
{ 
    [MessageHeader(ProtectionLevel=None)] public int recordID; 
    [MessageHeader(ProtectionLevel=Sign)] public string patientName; 
    [MessageHeader(ProtectionLevel=EncryptAndSign)] public string SSN; 
    [MessageBodyMember(ProtectionLevel=None)] public string comments; 
    [MessageBodyMember(ProtectionLevel=Sign)] public string diagnosis; 
    [MessageBodyMember(ProtectionLevel=EncryptAndSign)] public string medicalHistory; 
} 

注意保護級別無,簽名,加密和簽名

+0

我不認爲這會工作我基本上試圖添加一個wsse:UserNameToken但使用這種方法不工作,因爲框架認識到令牌並拋出一個錯誤,因爲它不是作爲綁定的一部分預期的? – 2011-03-03 19:52:29

1

WCF本身不允許簽署時間戳,但不是用戶名。首先,我非常肯定這與您所面臨的問題無關 - 服務器應該能夠處理這兩種情況。如果你真的需要它,那麼我建議在安全中不要使用用戶名(比如「anonymousForCertificate」的安全模式),然後實現一個自定義的消息編碼器,以便將用戶名/密碼標籤手動推入正確位置的標題中注意不要更改消息中的任何簽名部分,主要是時間戳)。

+0

這是一個老問題,我只是想解決,原來的要求只是爲了用戶名,沒有密碼,(用戶名是持有SSL證書的通用名稱)。我們被要求,我們必須實現連接到我們無法控制的第三方系統(Java)的服務器和客戶端。我會給編碼器一個旋轉,任何鏈接到自定義編碼信息將是有用的。親切的問候。 – 2013-08-14 15:21:10

+0

http://msdn.microsoft.com/en-us/library/ms751486.aspx – 2013-08-14 15:24:21

相關問題