2014-02-06 108 views
1

我正在嘗試使用.NET 3.5 WCF客戶端來使用外部Web服務(據我所見,它是axis2/apache服務)。WCF SOAP請求中的兩個簽名

該服務需要使用x509證書對傳入郵件進行簽名和加密。到目前爲止,簽名和加密似乎工作正常,但WCF在SOAP標頭中添加了第二個<signature>元素,這會混淆遠程Web服務。

我無法擺脫這第二個簽名元素。我在研究此事時發現的是,此簽名用於簽署第一個簽名。

我WCF配置目前使用有下列安全設置的自定義綁定:

<security messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
    authenticationMode="MutualCertificate" 
    securityHeaderLayout="Lax" 
    defaultAlgorithmSuite="Basic128" 
    includeTimestamp="false" 
    keyEntropyMode="CombinedEntropy" 
    requireDerivedKeys="false" 
    messageProtectionOrder="SignBeforeEncrypt" 
    requireSignatureConfirmation="true"> 

任何人有一個想法,因爲我有什麼改變來使這項工作?

一個由我的客戶生成的樣本SOAP請求是這樣的:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <e:EncryptedKey Id="uuid-0a13788c-6cb3-4fe2-940b-1e220d15230e-3" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
       <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"> 
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns="http://www.w3.org/2000/09/xmldsig#"/> 
       </e:EncryptionMethod> 
       <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 
        <o:SecurityTokenReference> 
         <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"><!-- ... --></o:KeyIdentifier> 
        </o:SecurityTokenReference> 
       </KeyInfo> 
       <e:CipherData> 
        <e:CipherValue><!-- ... --></e:CipherValue> 
       </e:CipherData> 
       <e:ReferenceList> 
        <e:DataReference URI="#_2"/> 
       </e:ReferenceList> 
      </e:EncryptedKey> 
      <o:BinarySecurityToken> 
       <!-- Removed--> 
      </o:BinarySecurityToken> 
      <Signature Id="_0" xmlns="http://www.w3.org/2000/09/xmldsig#"> 
       <SignedInfo> 
        <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
        <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/> 
        <Reference URI="#_1"> 
         <Transforms> 
          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
         </Transforms> 
         <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
         <DigestValue><!-- ... --></DigestValue> 
        </Reference> 
       </SignedInfo> 
       <SignatureValue><!-- ... --></SignatureValue> 
       <KeyInfo> 
        <o:SecurityTokenReference k:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey" xmlns:k="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"> 
         <o:Reference ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey" URI="#uuid-0a13788c-6cb3-4fe2-940b-1e220d15230e-3"/> 
        </o:SecurityTokenReference> 
       </KeyInfo> 
      </Signature> 
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 
       <SignedInfo> 
        <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
        <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 
        <Reference URI="#_0"> 
         <Transforms> 
          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
         </Transforms> 
         <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
         <DigestValue><!-- ... --></DigestValue> 
        </Reference> 
       </SignedInfo> 
       <SignatureValue><!-- ... --></SignatureValue> 
       <KeyInfo> 
        <o:SecurityTokenReference> 
         <o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-9618ae47-8bcd-4a96-b56e-800759a0ee57-7"/> 
        </o:SecurityTokenReference> 
       </KeyInfo> 
      </Signature> 
     </o:Security> 
    </s:Header> 
    <s:Body u:Id="_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <e:EncryptedData Id="_2" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
      <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/> 
      <e:CipherData> 
       <e:CipherValue><!-- ... --></e:CipherValue> 
      </e:CipherData> 
     </e:EncryptedData> 
    </s:Body> 
</s:Envelope> 

回答

0

原來我用錯了messageSecurityVersion值。值爲WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10只有一個簽名被添加到SOAP頭中。

之後服務器能夠理解請求。對defaultAlgorithmSuite進行了一些調整,現在服務和客戶正在交談並理解對方。