nuget sign
should validate certificate input has a private key
#13375
Labels
Category:Quality Week
Issues that should be considered for quality week
Functionality:Signing
Priority:2
Issues for the current backlog.
Product:dotnet.exe
Product:NuGet.exe
NuGet.exe
Type:Bug
NuGet Product Used
dotnet.exe
Product Version
9.0.100-preview.2.24157.14
Worked before?
No response
Impact
It bothers me. A fix would be nice
Repro Steps & Context
When using
dotnet nuget sign
the signing operation does not validate that theX509Certificate2
instance contains a private key when it is used for signing purposes.When used with a public X.509 certificate, not a PKCS#12/PFX, it produces an exception.
I would recommend checking
X509Certificate2.HasPrivateKey
prior to performing a signing operation, and if false, print an appropriate error.Currently, this produces an exception that is difficult to diagnose. The easiest way to reproduce this is to pass a public certificate to
--certificate-path
.I don't know the best place to insert that check, but maybe somewhere around here: https://github.com/NuGet/NuGet.Client/blob/7ad6fcc9c56c960975c37b2416c7eae1d53ba3fd/src/NuGet.Core/NuGet.Commands/SignCommand/SignCommandRunner.cs#L47
Without this check, you'll receive an error that looks something like this:
as noted over at dotnet/runtime#100414.
.NET will try an make the exception have a better error message, but it would be nice if NuGet handled this more gracefully instead of producing a stack trace.
Verbose Logs
No response
The text was updated successfully, but these errors were encountered: