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

DSAKeyValue in S.S.Cryptography.Xml should key for null on _key #75048

Closed
SteveDunn opened this issue Sep 3, 2022 · 5 comments · Fixed by #75620
Closed

DSAKeyValue in S.S.Cryptography.Xml should key for null on _key #75048

SteveDunn opened this issue Sep 3, 2022 · 5 comments · Fixed by #75620
Labels
area-System.Security help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@SteveDunn
Copy link
Contributor

It has a public setter (Key) which doesn't check for null. In GetXml, it is used without checking for null, potentially resulting in an NRE.

Originally posted by @krwq in #67198 (comment)

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 3, 2022
@ghost
Copy link

ghost commented Sep 3, 2022

Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

It has a public setter (Key) which doesn't check for null. In GetXml, it is used without checking for null, potentially resulting in an NRE.

Originally posted by @krwq in #67198 (comment)

Author: SteveDunn
Assignees: -
Labels:

area-System.Security, untriaged

Milestone: -

@bartonjs
Copy link
Member

The DSAKeyValue(DSA) constructor also accepts null, so there's more than one path to that NullReferenceException; and RSAKeyValue has the same two sources of null.

All four can add in argument validation, but we shouldn't do DSA (fairly unused) without RSA (99%+ usage), and on either type we shouldn't do the ctor or property setter without the other.

@bartonjs bartonjs added this to the Future milestone Sep 14, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 14, 2022
@bartonjs bartonjs added the help wanted [up-for-grabs] Good issue for external contributors label Sep 14, 2022
@vcsjones
Copy link
Member

@bartonjs we explicitly test that null in is null out.

[Fact]
public void Ctor_Rsa_Null()
{
RSAKeyValue rsaKeyValue = new RSAKeyValue(null);
Assert.Null(rsaKeyValue.Key);
}

I can't think of a good reason for this, and I am not sure if the tests exists because we want to make sure the test keeps working, or if the test was just thrown in there to test current behavior.

@bartonjs
Copy link
Member

I assume it was just a standard "pass null, record the results" with the intent that changing the behavior is intentional.

In days of yore, new RSAKeyValue()'s RSA.Create() would create an RSACryptoServiceProvider, and the default ctor of RSACryptoServiceProvider would generate an RSA key immediately. So it was possibly an intentional design that you could do new RSAKeyValue(null) and then change the key later. (I forget when we changed RSACryptoServiceProvider to do delayed keygen... before my time, but after netfx20)

Not that we'd do xmldsig today (because... yeah), but if we did it today I don't think we'd make the key have a setter at all... and there'd just be a ctor for a current key instance and one for importing.

I'm also happy to just say "it is what it is" and close the issue. CryptoXml isn't really an area where we expect new development.

@vcsjones
Copy link
Member

I'm also happy to just say "it is what it is" and close the issue. CryptoXml isn't really an area where we expect new development.

It's an easy enough change and it would make the nullability annotations that will (hopefully) get merged soon make more sense.

I looked through all public repos in GitHub and don't see a single instance of new RSAKeyValue(null) aside from our own tests and forks of dotnet/runtime.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants