- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Description
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:
            using (var certificate = new X509Certificate2(CertificatePath, Password))
            {
                var cmsSigner = new CmsSigner(certificate);
                cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;
                var contentInfo = new ContentInfo(new Oid(PkcsObjectIdentifiersData), InputBytes);
                var signedCms = new SignedCms(SubjectIdentifierType.Unknown, contentInfo, true);
                signedCms.ComputeSignature(cmsSigner);
                File.WriteAllBytes(SignaturePath, signedCms.Encode());
            }
The signature is verified as follows.
                var contentInfo = new ContentInfo(InputBytes);
                var signedData = new SignedCms(contentInfo, true);
                signedData.Decode(signatureBytes);
                var signerInfos = signedData.SignerInfos;
                signedData.CheckSignature(true);
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
Test create signature in .Net Framework. Verify in .Net Framework using elliptic curve.
 Verification ok
Test create signature in .Net Core. Verify in .Net Core using elliptic curve.
 Verification ok
Test create signature in .Net Framework. Verify in .Net Core using RSA.
 Verification ok
Test create signature in .Net Framework. Verify in .Net Core using elliptic curve.
 Verification failed
 Exception: SignerInfo digest algorithm '2.16.840.1.101.3.4.2.1' is not valid for signature algorithm ''.
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