Saml2: .NET 5: EnvironmentHelpers.IsNetCore bad implementation

Created on 6 Nov 2020  路  16Comments  路  Source: Sustainsys/Saml2

Hi,
implementation of flag EnvironmentHelpers.IsNetCore in Saml2.Internal and Saml2.Metadata isn't good.
If main application is in .net 5, detection fails and library crashes.

After forking project and fixing bug, library starts to working properly.

bug

Most helpful comment

@DavidBasarab ASAP - got piled up with too much work, but working on it.

All 16 comments

Thanks for noticing. .NET 5 is coming and should definitely work. Would you mind sending a pull request with the new detection logic?

Are there any other issues or incompatibilities you've seen so far?

Is there a reason this is a runtime check instead of a compile time check @AndersAbel? I could open a PR to change this into a compile time check.

Hi @AndersAbel, I also ran into this issue. I created a pull request with a fix: https://github.com/Sustainsys/Saml2/pull/1254.

I haven't seen any other issues or incompatibilities so far but will let you know if I do.

@dlemstra For the .NET Standard target it is not known at compile time if the runtime is .Net Core or .Net Framework. That's the historical reason. But the .NET Standard target might be something to discuss if it's worth keeping - we're already multi-targeting because how .NET Framework does not implement .Net Standard very nicely in some versions.

Hi guys!

Any news about this changes?

We are testing net 5.0 and getting this error:

_InvalidCastException: Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.RSACryptoServiceProvider'._

It is related to the EnvironmentHelpers.IsNetCore at AddSignature method in WebSSO/Saml2RedirectBinding.cs:

``` queryString += "&SigAlg=" + Uri.EscapeDataString(signingAlgorithmUrl); var signatureDescription = (SignatureDescription)CryptographyExtensions.CreateAlgorithmFromName(signingAlgorithmUrl); HashAlgorithm hashAlg = signatureDescription.CreateDigest(); hashAlg.ComputeHash(Encoding.UTF8.GetBytes(queryString)); AsymmetricSignatureFormatter asymmetricSignatureFormatter = signatureDescription.CreateFormatter( EnvironmentHelpers.IsNetCore ? message.SigningCertificate.PrivateKey : ((RSACryptoServiceProvider)message.SigningCertificate.PrivateKey) .GetSha256EnabledRSACryptoServiceProvider()); byte[] signatureValue = asymmetricSignatureFormatter.CreateSignature(hashAlg); queryString += "&Signature=" + Uri.EscapeDataString(Convert.ToBase64String(signatureValue)); return queryString;

My intention is to get a 2.8.0 out next week containing this fix and a few others urgent updates.

I dont know if you noticed @AndersAbel but I opened a PR to fix this issue.

@dlemstra Yes I did, it's that PR that I intend to use.

I moved my code to .net this weekend and ran into this same issue for the InvalidCast. Do you know when this PR will be released?

@DavidBasarab ASAP - got piled up with too much work, but working on it.

Any news about this PR?

Fixed in db3d5ec9184f5 for v2 branch. develop is left open, will review the larger PR for that.

@AndersAbel Thank you so much for the fix! Any idea when the new nuget packages will be available?

@samisq I'm working on the final PR that needs to get into 2.8.0 - it's the AES GCM support in #1251, then I'll make a release.

Hi @AndersAbel .. I confirm that is working good with the new version.

Thanks and happy holidays!

Any status about 2.8.0?

I can't find the source.

Was this page helpful?
0 / 5 - 0 ratings