Skip to content

HashAlgorithm.Create throws PNSE on .NET Core 2 #22929

Closed

Description

@clairernovotny

If you need to call HashAlgorithm.Create to create an instance without knowing the concrete type, it throws PNSE on .NET Core 2.

Workaround is to call (HashAlgorithm)CryptoConfig.CreateFromName(string), though calling CryptoConfig directly is generally discouraged.

Activity

  1. danmoseley commented on Jul 27, 2017

    @danmoseley
    Contributor

    Hm, I don't remember the rationale for this one. @bartonjs @ianhays why isn't it like desktop:

          public static HashAlgorithm Create(String hashName) {
                return (HashAlgorithm) CryptoConfig.CreateFromName(hashName);
            }

    If the caller just has to do exactly that, it seems perverse for us to not do it. There's no string in the PNSE either.

  2. danmoseley commented on Jul 27, 2017

    @danmoseley
    Contributor

    This method has non trivial usage.

  3. bartonjs commented on Jul 27, 2017

    @bartonjs
    Member

    It just got missed when CryptoConfig finally made it back. If @Petermarcu wants to take it this late I don't have an objection. But I can't, with a straight face, say it's necessary.

  4. Petermarcu commented on Jul 27, 2017

    @Petermarcu
    Member

    We should get it fixed in 2.0.1

  5. clairernovotny commented on Jul 27, 2017

    @clairernovotny
    Author

    @Petermarcu as a library author, how do I know where the fix is and how to set baseline requirements? I can target netstandard2.0, but then what? There's no way for me to force that it needs netcoreapp2.0.1 on that platform?

    Basically, the question/issue is around how long should a workaround stay in place for? (it's a more general topic), but doing feature-detection and then having both code-paths seems really redundant (for this).

  6. danmoseley commented on Jul 27, 2017

    @danmoseley
    Contributor

    @Petermarcu may have a better answer, but I think you're right that if you target netstandard2.0 the only safe approach is to leave the workaround in. The purpose of servicing is to at least help folks who fully deploy the servicing release: they don't need the workaround in their own code.

  7. Petermarcu commented on Jul 27, 2017

    @Petermarcu
    Member

    There are always going to be bugs in the platform implementations of .NET Standard that may require workarounds.

    Yes, as long as you want to behave well on 2.0.0 you will have to use the workaround. The lifespan of 2.0.0 should be fairly short as support for it will die off quickly once we ship a 2.0.1 which I expect will only be a month or two out. Apps will automatically roll forward to it, all the download links will be updated, and servicing releases will have security fixes in them where we will strongly encourage people to get the latest.

  8. Petermarcu commented on Jul 27, 2017

    @Petermarcu
    Member

    Lets make sure we leave this in the 2.0.0 milestone so we don't lose track of it for the first update.

  9. clairernovotny commented on Jul 27, 2017

    @clairernovotny
    Author

    @Petermarcu one thing that'll help are regular telemetry releases that show the % of users who have what version deployed -- ideally would love a time-series chart to see as new versions are introduced and watch it exceed the current version.

  10. Petermarcu commented on Jul 27, 2017

    @Petermarcu
    Member

    I agree. I think that would help everyone. We currently don't have any telemetry at runtime which would be the most accurate way to get this info but should be able to get a better understanding of the trend of which SDK they are using which also tells us all which runtime people are running on at dev time at least.

  11. Petermarcu commented on Jul 27, 2017

    @Petermarcu
    Member

    @richlander do we have the datapoint in the sdk to tell us which runtime they are running on and/or which runtime they are deploying with their SCD?

  12. ianhays commented on Jul 27, 2017

    @ianhays
    Contributor

    @danmosemsft sure thing :)

  13. danmoseley commented on Jul 27, 2017

    @danmoseley
    Contributor

    This needs fixing in more places:

    Searching 11736 files for "Create\(string.*\n.*{.*\n.*PlatformNot" (regex)
    
    C:\git\corefx\src\System.Security.Cryptography.Primitives\src\System\Security\Cryptography\AsymmetricAlgorithm.cs:
       19:         public static AsymmetricAlgorithm Create(string algName)
       20:         {
       21:             throw new PlatformNotSupportedException();
    
    C:\git\corefx\src\System.Security.Cryptography.Primitives\src\System\Security\Cryptography\HashAlgorithm.cs:
       23:         public static HashAlgorithm Create(string hashName)
       24:         {
       25:             throw new PlatformNotSupportedException();
    
    C:\git\corefx\src\System.Security.Cryptography.Primitives\src\System\Security\Cryptography\HMAC.cs:
       31:         public static new HMAC Create(string algorithmName)
       32:         {
       33:             throw new PlatformNotSupportedException();
    
    C:\git\corefx\src\System.Security.Cryptography.Primitives\src\System\Security\Cryptography\KeyedHashAlgorithm.cs:
       16:         public static new KeyedHashAlgorithm Create(string algName)
       17:         {
       18:             throw new PlatformNotSupportedException();
    
    C:\git\corefx\src\System.Security.Cryptography.Primitives\src\System\Security\Cryptography\SymmetricAlgorithm.cs:
       20:         public static SymmetricAlgorithm Create(string algName)
       21:         {
       22:             throw new PlatformNotSupportedException();
    
  14. 5 remaining items

  15. danmoseley commented on Aug 11, 2017

    @danmoseley
    Contributor

    @krwq please get a fix for this into master, anything we might want to service, I would like to have baking in master.

  16. danmoseley commented on Aug 11, 2017

    @danmoseley
    Contributor

    (leave the issue open)

  17. krwq commented on Aug 14, 2017

    @krwq
    Member

    It seems that we missed that:

    • HashAlgorithm
    • HMAC
    • KeyedHashAlgorithm
    • SymmetricAlgorithm
    • AsymmetricAlgorithm

    live inside System.Security.Cryptography.Primitives while CryptoConfig (which is needed to implement Create(string)) lives inside System.Security.Cryptography.Algorithms which depends on System.Security.Cryptography.Primitives. Fixing this would create dependency problem.

    Given that we have decided NOT to add this back for now as there is not much requests for this and the workaround is straightforward.

    For anyone interested in adding this back please comment and upvote this issue. Closing for now.

  18. bartonjs commented on Mar 21, 2018

    @bartonjs
    Member

    Reopening due to activity on dotnet/standard#530.

  19. assigned and unassigned on Mar 21, 2018
  20. jocull commented on Mar 22, 2018

    @jocull

    I appreciate you taking action on this @bartonjs - thank you!

  21. added a commit that references this issue on Aug 3, 2018
  22. removed their assignment
    on Nov 23, 2018
  23. transferred this issue fromdotnet/corefxon Jan 31, 2020
  24. added this to the 2.1.0 milestone on Jan 31, 2020
  25. ghost locked as resolved and limited conversation to collaborators on Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions