@WildMr

Как правильно подписать xml файл?

Добрый вечер. Захотел поиграться с файлом лицензии одной программы. Подскажите, пожалуйста, как правильно подписать xml файл лицензии?
Рабочая лицензия сейчас выглядит приблизительно таким образом:
<?xml version="1.0" encoding="UTF-8"?>
<license created="2017-05-12 13:34:48.432434">
  <type>enterprise</type>
  <licensee>Evaluation</licensee>
  <starts>2017-05-12</starts>
  <expires>2017-11-20</expires>
  <maxconcurrentsessions>15</maxconcurrentsessions>
  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
      <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"/>
        </Transforms>
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
        <DigestValue>SAdsad324DSafcewds5FDSf324fd</DigestValue>
      </Reference>
    </SignedInfo>
    <SignatureValue>kjHBLIUJgluyiTGLYuigfklv3678GFKLH7ot6y7Ot6yo7TVBhbGF678FVGK8</SignatureValue>
  </Signature>
</license>

Поигрался с онлайн генераторами подписей - не получилось. Выдаёт такой Exception:

System.Security.Cryptography.CryptographicException: Неверно сформированный элемент SignedInfo.
в System.Security.Cryptography.Xml.Signature.LoadXml(XmlElement value)
в System.Security.Cryptography.Xml.SignedXml.LoadXml(XmlElement value)
в BluePrism.BPCoreLib.KeyInfo.Verify(RSA key)
в BluePrism.BPCoreLib.AuthorisationDetails.FromLicenseKeys(ICollection`1 keys)
в BluePrism.BPCoreLib.clsLicensingRuntime.AddLicenseKey(KeyInfo key)
в AutomateUI.ctlSystemLicense.AddLicense()

Ок, прошёлся декомпиллером, вот что получил.
internal void Verify(RSA key)
    {
      SignedXml signedXml = new SignedXml(this.mLicenseXml);
      signedXml.Resolver = (XmlResolver) null;
      XmlNodeList elementsByTagName = this.mLicenseXml.GetElementsByTagName("Signature");
      if (elementsByTagName.Count != 1)
        throw new ApplicationException("Verification failed: Signature count invalid.");
      signedXml.LoadXml((XmlElement) elementsByTagName[0]);
      if (!signedXml.CheckSignature((AsymmetricAlgorithm) key))
        throw new ApplicationException("Verification failed - signature is not valid.");
    }

public static AuthorisationDetails FromLicenseKeys(ICollection<KeyInfo> keys)
    {
      AuthorisationDetails authorisationDetails1;
      if (keys == null || keys.Count == 0)
      {
        authorisationDetails1 = AuthorisationDetails.DefaultLicense;
      }
      else
      {
        AuthorisationDetails authorisationDetails2 = AuthorisationDetails.LoadKeys(keys);
        RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider();
        cryptoServiceProvider.FromXmlString("<RSAKeyValue><Modulus>Тут-Длинный-Длинный-Ключ</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>");
        IEnumerator<KeyInfo> enumerator;
        if (authorisationDetails2.LicenseType != LicenseTypes.None)
        {
          try
          {
            enumerator = authorisationDetails2.LicenseKeys.GetEnumerator();
            while (enumerator.MoveNext())
              enumerator.Current.Verify((RSA) cryptoServiceProvider);
          }
          finally
          {
            if (enumerator != null)
              enumerator.Dispose();
          }
        }
        authorisationDetails1 = authorisationDetails2;
      }
      return authorisationDetails1;
    }

Собственно вопрос - зная тот самый "Длинный-Длинный-Ключ" можно ли корректно подписать исправленный XML файл? Спасибо.
  • Вопрос задан
  • 573 просмотра
Решения вопроса 1
@gosha-z
Нет. Длинный-длинный-ключ - это public key, а подписывается приватным ключом. Получить private из public нельзя -это один из краеугольных камней PKI.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы