SOAP 応答内の xml 署名を検証する必要があります。Javaで取得できますが、.Netで実行する必要がありますが、解決できません。ここで仕事をするJavaコード:
public class SigVal {
private PublicKey publicKey;
public XMLSignatureValidator(PublicKey publicKey) {
this.publicKey = publicKey;
}
public boolean isValid(Node dsSignature)
{
DOMValidateContext context = new DOMValidateContext(publicKey, dsSignature);
String providerName = System.getProperty "jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM", (Provider) Class
.forName(providerName).newInstance());
XMLSignature signature = factory.unmarshalXMLSignature(context);
boolean coreValidity = signature.validate(context);
}
}
公開鍵は、wsse:BinarySecurityToken から生成された X509Certificate からのものです。dsSignature ノードは ds:Signature 要素です。
それが SOAP 応答です。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="CertId-33637684">MII..==</wsse:BinarySecurityToken>
<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#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#id-23582192">
<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>VvfpzVGZkr/AQ3krGcdklXujj3w=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-961374">
<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>KGBEkW1e0fkV3ooAptSIldv9ftQ=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
StF...=
</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-12282214">
<wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-314846">
<wsse:Reference URI="#CertId-33637684" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-23582192">
<wsu:Created>2013-06-06T07:08:19.323Z</wsu:Created>
<wsu:Expires>2013-06-06T07:13:19.323Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
<wsa:MessageID SOAP-ENV:mustUnderstand="0">uuid:dddca070-ce77-11e2-b9ac-d6977a2ed2bf</wsa:MessageID>
<wsa:To SOAP-ENV:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action SOAP-ENV:mustUnderstand="0">...</wsa:Action>
<From xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" SOAP-ENV:mustUnderstand="0">
<Address>...</Address>
</From>
<wsa:RelatesTo RelationshipType="wsa:Reply" SOAP-ENV:mustUnderstand="0">urn:uuid:3f4f070b-9e28-410d-b10b-a21a7d62ee86</wsa:RelatesTo>
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-961374">
...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
わかりました、C#で試しました
XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName("wsse:BinarySecurityToken");
string binarySecurityToken = xmlNodeList[0].InnerText;
X509Certificate2 x509Certificate2 = new X509Certificate2(Convert.FromBase64String(binarySecurityToken));
xmlNodeList = xmlDocument.GetElementsByTagName("Signature", "http://www.w3.org/2000/09/xmldsig#");
XmlElement signature = (XmlElement) xmlNodeList[0];
SignedXml signedXml = new SignedXml(xmlDocument);
signedXml.LoadXml(signature);
signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
bool isOk = signedXml.CheckSignature();
ただし、CheckSignature は常に False を返します。参照要素を取得するために SignedXml.GetIdElement を上書きしました。しかし、それは仕事をしません。
正しく理解していますか: Soap メッセージ (ds:Signature) から署名要素を取得し、Soap メッセージ (wsse:BinarySecurityToken) から証明書を取得して、それらを検証する必要があります。