Проверка подписанного XML в C # с несколькими подписями - PullRequest
0 голосов
/ 09 мая 2018

У меня есть код проверки подписи XML, который работает на всех примерах SAML XML, кроме одного. Тот, на котором он терпит неудачу, имеет несколько подписей. Успешно с первой подписью и с ошибкой второй.

Тогда я подумал: эй, что если я обменяю подписи? В первом сценарии подпись A является первой, подпись B является второй. Код проверяет подпись A и дает сбой в сигнатуре B. Если я поменяю их местами так, что сигнатура B будет первой, код проверит сигнатуру B, но не получится в сигнатуре A! Таким образом, кажется, что код способен проверять обе подписи независимо, но завершается неудачно, когда находится в определенном месте.

Теперь я знаю, что этот ответ saml действителен, и вы можете убедиться сами на samltool.com. Единственная проблема заключается в том, что в некоторых случаях код не может проверить подпись, и я не уверен, почему.

public static int isValidSignature(string encodedXml, string key)
{
    int ret = 0;

    string xml = Encoding.UTF8.GetString(Convert.FromBase64String(encodedXml));

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.PreserveWhitespace = true;
    xmlDoc.LoadXml(xml);

    X509Certificate2 cert = new X509Certificate2(Convert.FromBase64String(key));

    SignedXml signedXml = new SignedXml(xmlDoc);

    //XmlNodeList nodeList = xmlDoc.GetElementsByTagName("ds:Signature");
    NameTable nt = new NameTable();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
    nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");

    XmlNodeList nodeList = xmlDoc.SelectNodes(".//ds:Signature", nsmgr);

    if (nodeList.Count == 0)
    {
        ret = -1;
    }
    else
    {
        foreach (XmlNode node in nodeList) {
            signedXml.LoadXml((XmlElement)node);

            if (signedXml.CheckSignature(cert, true))
            {
                ret = 1;
            }
            else if(ret == 1)
            {
                ret = -2;
                break;
            }
        }
    }

    return ret;
}

Приведенный ниже код проверяет две вещи: исходный XML, XML с замененными подписями Я также протестировал две другие вещи, но они не подходят к этому вопросу: XML с только внешней подписью (возвращает 1) и XML с только внутренней подписью (возвращает 0).

string oktaKey = "MIIDpDCCAoygAwIBAgIGAVyqF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NpczpuYW1lczp0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0PC9zYW1sMjpBdXRobkNvbnRleHRDbGFzc1JlZj48L3NhbWwyOkF1dGhuQ29udGV4dD48L3NhbWwyOkF1dGhuU3RhdGVtZW50PjxzYW1sMjpBdHRyaWJ1dGVTdGF0ZW1lbnQgeG1sbnM6c2FtbDI9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphc3NlcnRpb24iPjxzYW1sMjpBdHRyaWJ1dGUgTmFtZT0iRW1haWxBZGRyZXNzIiBOYW1lRm9ybWF0PSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXR0cm5hbWUtZm9ybWF0OnVuc3BlY2lmaWVkIj48c2FtbDI6QXR0cmlidXRlVmFsdWUgeG1sbnM6eHM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4c2k6dHlwZT0ieHM6c3RyaW5nIj5mYWtlQGZha2UubmV0PC9zYW1sMjpBdHRyaWJ1dGVWYWx1ZT48L3NhbWwyOkF0dHJpYnV0ZT48L3NhbWwyOkF0dHJpYnV0ZVN0YXRlbWVudD48L3NhbWwyOkFzc2VydGlvbj48L3NhbWwycDpSZXNwb25zZT4=";

Debug.WriteLine(MyXml2.isValidSignature(oktaSample, oktaKey)); // prints -2
Debug.WriteLine(MyXml2.isValidSignature(oktaSample2, oktaKey)); // prints -2

1 Ответ

0 голосов
/ 21 мая 2018

Эндрю! Я уверен, что отвечу на многие ваши вопросы.

Хорошо, во-первых, второй пример не будет работать, потому что вы изменили XML таким образом, что подпись не будет совпадать.

Итак, после советов по поиску этого кода в Google, я наткнулся на эту страницу , в которой описано, как просмотреть протоколирование для SignedXml. Мясо добавить это в App.config под тегом:

<system.diagnostics>
  <sources>
    <source name="System.Security.Cryptography.Xml.SignedXml" switchName="XmlDsigLogSwitch">
      <listeners>
        <add name="logFile" />
      </listeners>
    </source>
  </sources>
  <switches>
    <add name="XmlDsigLogSwitch" value="Verbose" />
  </switches>
  <sharedListeners>
    <add name="logFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="XmlDsigLog.txt"/>
  </sharedListeners>
  <trace autoflush="true">
    <listeners>
      <add name="logFile" />
    </listeners>
  </trace>
</system.diagnostics>

Из этого и вашего кода я смог сделать вывод, что канонизация не работает правильно для второй подписи. В частности, не удалось удалить сам тег подписи. Это важно при проверке подписи, поскольку сама подпись не является частью подписанной информации. Если бы это было так, вы были бы здесь до тех пор, пока не сгорит солнце, пытаясь найти подпись, которая содержит себя.

Теперь я считаю, что это ошибка в реализации C #, но я не такой умный, как люди, которые пишут C #, поэтому я могу ошибаться. Но здесь есть обходной путь. Я добавил свой собственный класс, который расширяет XmlDsigExcC14NTransform, что было предложено несколькими результатами Google, но для немного другой проблемы. В методе LoadInput этого класса я удаляю узел. Оттуда все работало счастливо!

public class SigKillXmlDsigExcC14NTransform : XmlDsigExcC14NTransform
{
    public SigKillXmlDsigExcC14NTransform() { }

    public override void LoadInput(Object obj)
    {
        XmlElement root = ((XmlDocument)obj).DocumentElement;
        NameTable nt = new NameTable();
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
        nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
        XmlNodeList childSignatures = root.SelectNodes("./ds:Signature", nsmgr);

        // Sometimes C# fails to remove the child node.  Let's hold his hand and do it for him.
        foreach (XmlNode oneChild in childSignatures)
        {
            oneChild.ParentNode.RemoveChild(oneChild);
        }

        base.LoadInput(obj);
    }
}

Оттуда вы добавляете одну строку к исходному коду, а остальное остается прежним.

CryptoConfig.AddAlgorithm(typeof(SigKillXmlDsigExcC14NTransform), "http://www.w3.org/2001/10/xml-exc-c14n#");

А теперь первый пример работает!

...