I need to sign XML documents with a cert, using .NET Core and SignedXml
, but I don't know how to configure some of the elements expected by the other side in the signature tag. I've checked many articles, one of this, authored by Rick Stahl, is pretty similar, but I am still validated with errors. Unfortunately, I cannot send any good log message, I have only a general answer, that signature is invalid.
The expected content of the signature looks like below. It looks like all details - tags, prefixes, identifiers, schemas - are required.
<wsse:Security xmlns:wsse="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">
<ds:Signature Id="{{someValue}}" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="soapenv urn urn1 urn2 urn3 urn4" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#{{someValue}}">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="urn urn1 urn2 urn3 urn4" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>VALUEOFDIGIESTVALUE</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>VALUEOFSIGNATUREVALUE</ds:SignatureValue>
<ds:KeyInfo Id="{{someValue}}">
<wsse:SecurityTokenReference wsu:Id="{{someValue}}">
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>{{someValue}}</ds:X509IssuerName>
<ds:X509SerialNumber>{{someValue}}</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
EVERY TIP IS HELPFUL, I don't expect overall answer, but I am interested the most of these questions:
- How to define prefixes
ds
andec
? - How to configure
wsse:SecurityTokenReference
? - Where to find all identifiers, marked as
{{someValue}}
After two weeks of fighting with SignedXml
I need to confirm the same state in 2021, which was described by Rick Stahl in 2008:
It really is no wonder that security for signatures and encryption with certificates is so lightly used on Windows. It's a royal pain in the ass, horribly documented and requires a host of tools.
Although colleagues from the Java county say, that this is much simpler abroad, I think the problem is overcomplicated specifications of SOAP services.
This is a partial solution, based on mentioned Rick Stahl's article. Let's suppose we have that XML document to sign:
With that code:
I have this result: