-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Cms signature created with .Net Framework cannot be verified with .Net Core for an elliptic curve certificate #77377
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsDescriptionLink to a project to reproduce: https://github.com/jgustavs-tibco/cmssigner-incompatibility If you use CmsSigner to create a signature in .Net Framework 4.8 with an ECC certificate then the signature cannot be verified using CmsSigner in .Net Core 6.0. The signature is created as follows:
The signature is verified as follows.
Note that it is possible to verify the signature in .Net Framework. We have tried to generate the ECC certificate using .Net and using Java and it the verification fails in both cases. We have tried to reproduce the issue using RSA certificates. Then it works fine. We noticed that the signature algorithm is SignedCms.SignerInfos is not the same if we try to generate the signature using .Net Framework and .Net Core which is not what we expected. Reproduction StepsBuild the project in https://github.com/jgustavs-tibco/cmssigner-incompatibility and run This runs different combinations of .Net Framework and .Net Core and certificate key algorithms. It gives the following output
Expected behaviorAll combinations of .Net Framework and .Net Core and certificate key algorithms should work. Actual behaviorThe case where the signature is created in .Net Framework but verified in .Net Core does not work for ECC certificates. Regression?No response Known WorkaroundsNo response ConfigurationWe have tried .Net Framework 4.8 and .Net Core 6.0 on Windows. Other informationNo response
|
Okay, I think I see what is going on here. In .NET Framework, the signature algorithm is 1.2.840.10045.2.1 (EcPublicKey). When we lookup the signature info here: Line 20 in 36df7cc
We use a Line 52 in 36df7cc
I think the right fix here for maintaining compat with .NET Framework is to skip the hash algorithm check if we are using .NET Framework's signature algorithm identifier. Basically change the check to: if (_expectedDigest != default(HashAlgorithmName) && _expectedDigest != digestAlgorithmName) (or make @bartonjs does this sound reasonable? |
if (_expectedDigest != default(HashAlgorithmName) && _expectedDigest != digestAlgorithmName) seems like the right fix to me. |
As a matter of an update to this, even once we get past the hash algorithm check, the digest that gets signed and verified differs between .NET Framework and .NET 6+. So this will take a little more time for me to understand exactly what .NET Framework is doing differently. |
I'm moving this to Future as we won't be able to further investigate it during .NET 8. I'm also going to label this as
help wanted
|
Supports SignedCms signatured with an ECDSA key created by the Windows API or .NET Framework. These signatures store an EC public key OID rather than a hash specific ECDSA OID used in newer versions of dotnet. Fixes dotnet#77377
@vcsjones I tested out skipping the check if the
Do you remember how you verified this? From testing I can generate a signature from both .NET and the Win32 API directly with an ECDSA key and the code is able to check the digest just fine. Even the test the PR adds is fine with the new changes. I do have a user report with a problematic signature signed by
I don't think they are related as even Windows fails to verify the signature but I've yet to figure out why |
Supports SignedCms signatured with an ECDSA key created by the Windows API or .NET Framework. These signatures store an EC public key OID rather than a hash specific ECDSA OID used in newer versions of dotnet. Fixes #77377
Supports SignedCms signatured with an ECDSA key created by the Windows API or .NET Framework. These signatures store an EC public key OID rather than a hash specific ECDSA OID used in newer versions of dotnet. Fixes #77377 Co-authored-by: Jordan Borean <[email protected]>
Description
Link to a project to reproduce: https://github.com/jgustavs-tibco/cmssigner-incompatibility
If you use CmsSigner to create a signature in .Net Framework 4.8 with an ECC certificate then the signature cannot be verified using CmsSigner in .Net Core 6.0.
The signature is created as follows:
The signature is verified as follows.
Note that it is possible to verify the signature in .Net Framework.
We have tried to generate the ECC certificate using .Net and using Java and it the verification fails in both cases. We have tried to reproduce the issue using RSA certificates. Then it works fine.
We noticed that the signature algorithm is SignedCms.SignerInfos is not the same if we try to generate the signature using .Net Framework and .Net Core which is not what we expected.
Reproduction Steps
Build the project in https://github.com/jgustavs-tibco/cmssigner-incompatibility and run
test.bat
.This runs different combinations of .Net Framework and .Net Core and certificate key algorithms.
It gives the following output
Expected behavior
All combinations of .Net Framework and .Net Core and certificate key algorithms should work.
Actual behavior
The case where the signature is created in .Net Framework but verified in .Net Core does not work for ECC certificates.
Regression?
No response
Known Workarounds
No response
Configuration
We have tried .Net Framework 4.8 and .Net Core 6.0 on Windows.
Other information
No response
The text was updated successfully, but these errors were encountered: