2016-03-22 16 views
0

私は、次のXSDがありますXMLスキーマ検証[セキュリティ]問題

<xsd:schema 
    targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
    xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
    elementFormDefault="qualified" attributeFormDefault="unqualified" 
    blockDefault="#all" version="0.2"> 
    <xsd:import namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" schemaLocation="../MSG/IRS-WSTimeStampElementMessage.xsd" /> 
    <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="../MSG/IRS-WSSignatureElementMessage.xsd"/> 
    <xsd:complexType name="SecurityHeaderType"> 
     <xsd:annotation> 
      <xsd:documentation>This complexType defines header block to use for 
       security-relevant data directed at a specific SOAP actor. 
      </xsd:documentation> 
     </xsd:annotation> 
     <xsd:sequence> 
      <xsd:element ref="ds:Signature" minOccurs="0"/> 
      <xsd:element ref="wsu:Timestamp" minOccurs="0"/>    
     </xsd:sequence> 
     <xsd:anyAttribute namespace="##other" processContents="lax" /> 
    </xsd:complexType> 
    <xsd:element name="Security" type="wsse:SecurityHeaderType"> 
     <xsd:annotation> 
      <xsd:documentation>This element defines the wsse:Security SOAP header 
       element per Section 4.</xsd:documentation> 
     </xsd:annotation> 
    </xsd:element> 
</xsd:schema> 

そして、これは私が上記のスキーマに対して検証しようとしているXMLです:私は理解できませんでした何

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="TS-E68EBBF1696C5DD4AA143353323390073"> 
       <u:Created>2016-03-22T12:42:44.170Z</u:Created> 
       <u:Expires>2016-03-22T12:52:44.170Z</u:Expires> 
      </u:Timestamp> 
      <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
       <ds:SignedInfo> 
        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" /> 
        <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> 
        <ds:Reference URI="#id-1"> 
         <ds:Transforms> 
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
         </ds:Transforms> 
         <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
         <ds:DigestValue>2gAU0kJV40nvR+Og=</ds:DigestValue> 
        </ds:Reference> 
        <ds:Reference URI="#id-2"> 
         <ds:Transforms> 
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
         </ds:Transforms> 
         <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
         <ds:DigestValue>pISNeszVQ59HKCRbQ=</ds:DigestValue> 
        </ds:Reference> 
        <ds:Reference URI="#TS-E68EBBF1696C5DD4AA143353323390073"> 
         <ds:Transforms> 
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
         </ds:Transforms> 
         <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
         <ds:DigestValue>mh7+cJJPRtrrn/s4N15AE=</ds:DigestValue> 
        </ds:Reference> 
       </ds:SignedInfo> 
       <ds:SignatureValue>fhpY2IlKEdwBFWqNxbVEw7p+ojhw54+op+g==</ds:SignatureValue> 
       <ds:KeyInfo> 
        <ds:X509Data>fshPnGE6H36KNqWMZqTf+X0oBls3dLz7TY=</ds:X509Certificate> 
        </ds:X509Data> 
       </ds:KeyInfo> 
      </ds:Signature> 
</wsse:Security> 

を検証中にエラーが発生する理由:

ERROR: The element 'Security' in namespace 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' has invalid child element 'Signature' in namespace 'http://www.w3.org/2000/09/xmldsig#'. 

名前空間に定義されている要素のようですバリデーターはそれに気付かないか、何らかの理由でその事実を無視しているようです。

答えて

2

それらは間違った順序で表示されます。シーケンスは宣言された順序で表示されるはずです。シグネチャには0の最小値が設定されているため、タイムスタンプが最初に問題になっていません。

あなたは、あなたSE XSDあなたの子供のelememtsの出現順序を強制したくない場合は::すべてが、それは@Robが言った上で展開するには、独自の問題/ルールDifference between <xsd:all> and <xsd:sequence> in schema definition?

+0

ありがとうございました!シーケンスが問題でした!あなたの助けに感謝! – fatherOfWine

+0

常に喜んで助けてください。 – Rob

0

を持っています。私は私のSignature要素を作成したとき

は、SignedXmlオブジェクトのComputeSignature()方法を使用した後、私はXmlElementオブジェクトに出力するXMLをsignedXml.GetXml()方法を使用していました。デジタル署名を保持するために使用されます。私は、Security要素の参照を保持するXmlNodeオブジェクトを作成し、メソッドを使用してSecurity要素のFirstChildの前にデジタル署名を追加しました。

これを実行すると、Security要素の子要素が適切な順序で配置されます。

// Compute the signature. 
xSigned.ComputeSignature(); 

// Get the Xml representation of the signature and save it to an XmlElement object. 
XmlElement xmlDigitalSignature = xSigned.GetXml(); 

// Replace the KeyInfo element of the DigitalSignature with the appropriate KeyInfo information. 
xmlDigitalSignature = ReplaceKeyInfo(xmlDigitalSignature); 

// Create a reference to the Security Element under the SOAP Header. 
XmlNode securityNode = xdoc.DocumentElement.SelectSingleNode("//soapenv:Header/wsse:Security", XmlManager(xdoc)); 

// Add the element to the XmlDocument by moving the Signature Element to be the first child under the Security Element. 
securityNode.InsertBefore(xdoc.ImportNode(xmlDigitalSignature, true), securityNode.FirstChild); 
+0

ありがとう、男!それでも、それをやっているが、役に立たないとはいえ、まだ悪名高いエラーが出ている。間違った指導:( – fatherOfWine

+0

@ fatherOfWineあなたの提出物を受け取ったことがありますか? – Russ

+0

はい、私はあなたの質問に更新を残しました。それを見ましたか? – fatherOfWine