Отсутствует " - PullRequest
       87

Отсутствует "

0 голосов
/ 24 декабря 2018

Я создаю запрос AuthnRequest для поставщика услуг, используя код C #.После подписания запроса SAML сообщение генерируется следующим образом:

.............
.............
<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="">
 <Transforms>
    <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
    <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
 </Transforms>
 <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
 <DigestValue>sivkexKCvqK7xEEjgOaMf1D98vU=</DigestValue>
 </Reference>
 </SignedInfo>
 ................

Я ожидаю:

.............
.............
<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="">
 <Transforms>
    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
        <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="ds saml samlp"/>
     </ds:Transform>
 </Transforms>
 <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
 <DigestValue>sivkexKCvqK7xEEjgOaMf1D98vU=</DigestValue>
 </Reference>
 </SignedInfo>
 ................

Подписание XML C # Метод:

      public static string SignXml(XmlDocument Document, X509Certificate2 cert)
    {
        SignedXml signedXml = new SignedXml(Document);
        signedXml.SigningKey = cert.PrivateKey;
        Reference reference = new Reference {Uri = ""};
        XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform(true);
        reference.AddTransform(env);
        var transform = new XmlDsigC14NTransform(true)
        {
            Algorithm = SignedXml.XmlDsigExcC14NTransformUrl
        };
        reference.AddTransform(transform);
        KeyInfo keyInfo = new KeyInfo();
        KeyInfoX509Data keyInfoData = new KeyInfoX509Data(cert);
        keyInfo.AddClause(keyInfoData);
        signedXml.KeyInfo = keyInfo;
        signedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
        signedXml.AddReference(reference);
        // Compute the signature.
        signedXml.ComputeSignature();
        // Add it to an rest XML ....
        XmlElement xmlDigitalSignature = signedXml.GetXml();
        ///////////////// END OF XML Part
        var nsmgr = new XmlNamespaceManager(Document.NameTable);
        nsmgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
        var nl = Document.SelectSingleNode("//saml:Issuer", nsmgr);
        //XmlNode xElt = Document.SelectSingleNode("//saml:Issuer");
        Document.DocumentElement.InsertAfter(Document.ImportNode(xmlDigitalSignature, true), nl);
        //Document.DocumentElement.AppendChild(Document.ImportNode(xmlDigitalSignature, true));
        return Document.InnerXml;
    }

какдостичь ожидаемого XML-сообщения выше. ??Любая помощь будет оценена. Спасибо заранее.

...