Skip to content

Merge System.Security.Cryptography.Algorithms to System.Security.Cryptography #61543

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

Merged
merged 7 commits into from
Nov 17, 2021

Conversation

bartonjs
Copy link
Member

  • Merge S.S.C.Algorithms into S.S.Cryptography as expected for Windows/Unix/Android/macOS/iOS/tvOS
  • Merge S.S.C.Algorithms into S.S.Cryptography with no PNSE generation for Browser
    • This resulted in a lot of UnsupportedOSPlatform attributes being removed, and a lesser number being moved from the class to a factory method.
    • There was also a small amount of plumbing work needed to handle all of the resulting platform compat warnings.
  • Merge S.S.C.Algorithms.Tests into S.S.Cryptography.Tests, renaming namespaces for files that moved, except the file is a partial to a file in Common\test

This move resulted in a net reduction of about 25 resource strings from a combination of the string already being present in the unified library, perhaps some strings that already had no references, and a few strings got abandoned (unified onto another existing string).

Three notable changes exist in the resource string moves:

  • Cryptography_MissingKey => Cryptography_FormatterMissingKey
    • Added "Formatter" to the resource name because the message wasn't as generic as it sounded.
    • Added an actionable component since it was already pretty darn specific.
    • Before: No asymmetric key object has been associated with this formatter object.
    • After: No asymmetric key object has been associated with this formatter object, assign one via the SetKey method.
  • Cryptography_MissingOID => Cryptography_FormatterMissingAlgorithm
    • The resource key name didn't match the code, or the action a user needed to take.
    • The resource value didn't match the code, or the action a user needed to take.
    • Completely rewrote it to look like Cryptography_FormatterMissingKey
    • Before: Required object identifier (OID) cannot be found.
    • After: No hash algorithm has been associated with this formatter object, assign one via the SetHashAlgorithm method.
  • Cryptography_Prk_TooSmall
    • Added "at least" because it read a little misleadingly as exact.
    • Before: The pseudo-random key length must be {0} bytes.
    • After: The pseudo-random key length must be at least {0} bytes.

The "Unix" files were generally renamed to "OpenSsl" in this change. The Android build still uses many of those files, copying them to an Android specific version is being left to a followup change.

The crypto tests definitely look a bit untidy at this point. The static classes and [Algorithm]Provider model will have to be redone before the Cng/Csp/OpenSsl libraries can be merged in. Since this change is largely about library consolidation, no test cleanup was done with this change.

@ghost
Copy link

ghost commented Nov 13, 2021

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 13, 2021

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Merge S.S.C.Algorithms into S.S.Cryptography as expected for Windows/Unix/Android/macOS/iOS/tvOS
  • Merge S.S.C.Algorithms into S.S.Cryptography with no PNSE generation for Browser
    • This resulted in a lot of UnsupportedOSPlatform attributes being removed, and a lesser number being moved from the class to a factory method.
    • There was also a small amount of plumbing work needed to handle all of the resulting platform compat warnings.
  • Merge S.S.C.Algorithms.Tests into S.S.Cryptography.Tests, renaming namespaces for files that moved, except the file is a partial to a file in Common\test

This move resulted in a net reduction of about 25 resource strings from a combination of the string already being present in the unified library, perhaps some strings that already had no references, and a few strings got abandoned (unified onto another existing string).

Three notable changes exist in the resource string moves:

  • Cryptography_MissingKey => Cryptography_FormatterMissingKey
    • Added "Formatter" to the resource name because the message wasn't as generic as it sounded.
    • Added an actionable component since it was already pretty darn specific.
    • Before: No asymmetric key object has been associated with this formatter object.
    • After: No asymmetric key object has been associated with this formatter object, assign one via the SetKey method.
  • Cryptography_MissingOID => Cryptography_FormatterMissingAlgorithm
    • The resource key name didn't match the code, or the action a user needed to take.
    • The resource value didn't match the code, or the action a user needed to take.
    • Completely rewrote it to look like Cryptography_FormatterMissingKey
    • Before: Required object identifier (OID) cannot be found.
    • After: No hash algorithm has been associated with this formatter object, assign one via the SetHashAlgorithm method.
  • Cryptography_Prk_TooSmall
    • Added "at least" because it read a little misleadingly as exact.
    • Before: The pseudo-random key length must be {0} bytes.
    • After: The pseudo-random key length must be at least {0} bytes.

The "Unix" files were generally renamed to "OpenSsl" in this change. The Android build still uses many of those files, copying them to an Android specific version is being left to a followup change.

The crypto tests definitely look a bit untidy at this point. The static classes and [Algorithm]Provider model will have to be redone before the Cng/Csp/OpenSsl libraries can be merged in. Since this change is largely about library consolidation, no test cleanup was done with this change.

Author: bartonjs
Assignees: -
Labels:

area-System.Security, new-api-needs-documentation

Milestone: -

@bartonjs bartonjs force-pushed the unified_crypto_algorithms branch from ffd8923 to abb6791 Compare November 13, 2021 01:38
@bartonjs
Copy link
Member Author

@safern for the structural/infra changes, please

@GrabYourPitchforks / @stephentoub for the impact of bringing browser fully into the fold here. Specifically the second commit (440df74) (yeah, it'll all get squashed in the end)

@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);INTERNAL_ASYMMETRIC_IMPLEMENTATIONS</DefineConstants>
Copy link
Member

@safern safern Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are merging pretty much all of Crypto into one assembly, is this still needed?

Copy link
Member Author

@bartonjs bartonjs Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still needed in this iteration, yeah. It'll go away between this one and the next. (That is, before the next library merges in; or as part of that)

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infra changes look good. However CI is red due to some of these.

@bartonjs
Copy link
Member Author

However CI is red due to some of these.

Yeah. I was verifying that I'd fixed them all today when the power went out. Sorta... slowed things down.

@bartonjs bartonjs force-pushed the unified_crypto_algorithms branch from fc7cf75 to c48fea3 Compare November 16, 2021 23:09
@GrabYourPitchforks
Copy link
Member

Re: browser impact, I suspect we'd want to add an ILLink.Substitutions.xml file so that patterns like if (!Helpers.SupportsSymmetricEncryption) { /* ... */ } are pruned during build.

With that substitution file in place, I'd assume no measurable impact to non-browser platforms?

@@ -556,6 +580,12 @@ private static CryptographicException AlgorithmKdfRequiresChars(string algId)
{
string? algId = encryptionScheme.Algorithm;

if (!Helpers.HasSymmetricEncryption)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (+ HasHMAC below) are becoming something of a common pattern. Would it make sense to refactor the "check + throw an appropriate exception" logic into its own helper method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M...aybe? They're here because of the UnsupportedOS flow analyzer, to show it that there's no way for Browser to make it to the annotated-as-failing Creates. I don't know how much flexibility we have with what it understands.

@bartonjs
Copy link
Member Author

I suspect we'd want to add an ILLink.Substitutions.xml file so that patterns like if (!Helpers.SupportsSymmetricEncryption) { /* ... */ } are pruned during build.

Well, except we're going to try getting them enabled this release. So these helpers will probably drop out :)

@bartonjs bartonjs merged commit 899bf97 into dotnet:main Nov 17, 2021
eerhardt added a commit to dotnet/sdk that referenced this pull request Nov 30, 2021
dotnet-maestro bot added a commit to dotnet/sdk that referenced this pull request Nov 30, 2021
[main] Update dependencies from dotnet/runtime


 - Merge branch 'main' of https://github.com/dotnet/sdk into darc-main-79a18e20-75f6-4bb7-8d8e-5ae13e5c66b0

 - Update baselines to remove Cryptography.Algorithms.

This assembly has been removed with dotnet/runtime#61543

 - More baseline updates
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2021
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.

3 participants