Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[release/2.1]: Fix compatibility issues vs NetFX in SignedCms and EnvelopedCms#30432

Merged
bartonjs merged 3 commits intodotnet:release/2.1from
bartonjs:21_cms_compat
Jun 27, 2018
Merged

[release/2.1]: Fix compatibility issues vs NetFX in SignedCms and EnvelopedCms#30432
bartonjs merged 3 commits intodotnet:release/2.1from
bartonjs:21_cms_compat

Conversation

@bartonjs
Copy link
Member

@bartonjs bartonjs commented Jun 15, 2018

NetFX and EnvelopedCms on Windows are both built on the same set of P/Invokes into Windows CryptMsg* APIs, and the EnvelopedCms recently added for Unix uses a new implementation. When the content type identifier for the payload is not id-data the two implementations encrypt different content. Windows removed the outer ASN/BER tag (and length) and encrypted only the payload bytes, reassembling the outgoing data by wrapping it in an ASN SEQUENCE. Unix/Managed wrote all of the bytes as-were. Both implementations therefore successfully read back what was written by their implementation, but neither implementation could read the content produced by the other. For this change, Unix EnvelopedCms has been changed to write content in the same manner as the existing Windows implementation and therefore to also be able to read that data.

NetFX SignedCms is built on P/Invokes into Windows CryptMsg* APIs, but the CoreFx version is a new pure-managed implementation. When the content type identifier for a SignedCms payload is not id-data and the document was signed by a signer using a signer identifier type of IssuerAndSubjectName (the default) the NetFX version writes the content without a wrapping OCTET STRING, because that was what the pre-1999 PKCS7 specification said to do. The managed implementation could only read the post-1999 CMS format. This change enables the managed implementation of SignedCms to read older PKCS7-conforming documents, but continues to write using the CMS1999 rules (which are successfully read by NetFX).

This is a port of #29926 (EnvelopedCms) and #30405 (SignedCms) to release/2.1.
Fixes #29825

bartonjs added 2 commits June 15, 2018 10:55
* Windows EnvelopedCms removes an outer BER tag and length when encrypting types other than id-data, match that on Unix.
  * When decrypting said data, wrap the response in a definite length SEQUENCE (which may change the tag)
* Make the Windows version encrypt an indefinite length value when not id-data
* Tests for all these things
* SignedCms with a content-type other than id-data should have attributes

* Read classic PKCS7 SignedData(EnvelopedData) documents (NetFx compat)

In NetFX if a SignedCms is created using only CmsSigners with IssuerAndSerial as
the signer identifier type, the document gets encoded using the older PKCS7
structural definition instead of the newer CMS one.

RFC 5652 has a long section (5.2.1) on how to read these documents compatibly.

Since the defaults in SignedCms / CmsSigner are the PKCS7 behavior, not
reading it means that Signed(Enveloped) documents from NetFX cannot be read.
@bartonjs bartonjs self-assigned this Jun 15, 2018
@bartonjs bartonjs added area-System.Security Servicing-consider Issue for next servicing release review labels Jun 15, 2018
@bartonjs bartonjs added this to the 2.1.x milestone Jun 15, 2018
@bartonjs
Copy link
Member Author

@dotnet-bot test Outerloop Windows x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build

@bartonjs bartonjs merged commit 4c4adb8 into dotnet:release/2.1 Jun 27, 2018
@danmoseley danmoseley removed the Servicing-consider Issue for next servicing release review label Aug 17, 2018
@bartonjs bartonjs removed their assignment Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants