Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gost CMS Encryption #17

Closed
Fasjeit opened this issue Jan 9, 2020 · 3 comments
Closed

Gost CMS Encryption #17

Fasjeit opened this issue Jan 9, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Fasjeit
Copy link
Collaborator

Fasjeit commented Jan 9, 2020

No description provided.

@Fasjeit Fasjeit self-assigned this Jan 9, 2020
@Fasjeit Fasjeit added the enhancement New feature or request label Jan 9, 2020
@AlexeyAKat
Copy link

Did I understand correctly that CMS Encryption is not working now?
The following code throws an exception:

var contentInfo = new ContentInfo(msg);
var envelopedCms = new EnvelopedCms(contentInfo);

// myCert, recipientCert - X509Certificate2 objects of Gost certificates
var certsColl = new X509Certificate2Collection(new [] { myCert, recipientCert });
var cmsRecipients = new CmsRecipientCollection(SubjectIdentifierType.IssuerAndSerialNumber, certsColl);

// throws an exception
envelopedCms.Encrypt(cmsRecipients);

Exception stack trace:

Windows:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Встречено неверное значение тега ASN1.
   at Internal.Cryptography.Pal.Windows.PkcsPalWindows.EncodeHelpers.CreateCryptMsgHandleToEncode(CmsRecipientCollection recipients, Oid innerContentType, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes)
   at Internal.Cryptography.Pal.Windows.PkcsPalWindows.Encrypt(CmsRecipientCollection recipients, ContentInfo contentInfo, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes)
   at System.Security.Cryptography.Pkcs.EnvelopedCms.Encrypt(CmsRecipientCollection recipients)

Linux:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unknown error (0xffffffff)
    at Internal.Cryptography.Pal.Windows.PkcsPalWindows.EncodeHelpers.CreateCryptMsgHandleToEncode(CmsRecipientCollection recipients, Oid innerContentType, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes)
    at Internal.Cryptography.Pal.Windows.PkcsPalWindows.Encrypt(CmsRecipientCollection recipients, ContentInfo contentInfo, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes)
    at System.Security.Cryptography.Pkcs.EnvelopedCms.Encrypt(CmsRecipientCollection recipients)

OS: Windows 10 Home 1909, Ubuntu 18.04.4 LTS, .net core 3.1 (SDK 3.1.202, runtime 3.1.4), Crypto-Pro CSP 5.0.11732 KC1 (5.0.11455 on Windows), instruction Linux.md, Windows.md was used, corefx ver.3.1.1.241 (4.7.0-dev.20175.1).

@Fasjeit
Copy link
Collaborator Author

Fasjeit commented Feb 3, 2021

ms где то поменяло логику, переписав её в методе EncodeKeyTransRecipientInfo

private static unsafe CMSG_ENVELOPED_ENCODE_INFO* CreateCmsEnvelopedEncodeInfo(CmsRecipientCollection recipients, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes, HeapBlockRetainer hb)

не вижу кода, который бы соотв. коду из старого fw (при этом он раньше вызывался)

      if (encryptParam.useCms)
      {
      // похожий код есть в текущей реализации
      }
      // этого кода просто нет
      else
      {
        EnvelopedCms.SetPkcs7RecipientParams(recipients, ref encryptParam, out certContexts);
        envelopedEncodeInfo.rgpRecipients = encryptParam.rgpRecipients.DangerousGetHandle();
      }

Не знаю пока, в этом ли причина, но падает в CryptMsgOpenToEncode, флаги все те же, что и в FW.

@Fasjeit Fasjeit changed the title Gost Xml/CMS Encryption Gost CMS Encryption Feb 3, 2021
@Fasjeit
Copy link
Collaborator Author

Fasjeit commented Jun 2, 2022

Основная работа по поддержке CMS шифрования тут
#56

@Fasjeit Fasjeit closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants