bcgit / bc-csharp

BouncyCastle.NET Cryptography Library (Mirror)
https://www.bouncycastle.org/csharp
MIT License
1.67k stars 556 forks source link

DigestAlgorithmID always with DerNull parameter #162

Open eulercb opened 5 years ago

eulercb commented 5 years ago

Hello bc Team!

I was tinkering with bc-csharp and comparing the results of a generated CMS by bc against one from .Net Core 'System.Security.Cryptography.Pkcs' package and found some annoying differences.

Here are a sample of a signed CMS using .Net Core: MIIEZAYJKoZIhvcNAQcCoIIEVTCCBFECAQExDTALBglghkgBZQMEAgEwEwYJKoZIhvcNAQcBoAYEBFRFU1SgggKEMIICgDCCAWigAwIBAgIIZl81FSTJTXwwDQYJKoZIhvcNAQELBQAwADAeFw0xNzEyMDIxMzIyNTJaFw0xOTEyMDIxMzIyNTJaMAAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDP8mwzIUwbnnEW2muVuqQ0IuFLh/haSU4A71hmP5nglaEm0BN99nsXhTmcaGfaAxGOXPyjSLkKKhV3YaLl4kYW7eQ2PWeROBB48N5B2Gclyqu4ecYDrcSNebv8LXMpwPpcqjoxXOh6QqxYek/bIk6bduuXSJDlLww4/gOzmN+lURAjMzE7t0ZsqH7wh68XrIn9zZK637osmnhEA4eW3FIbfAvt7g7kc91zKbCkAb4752+VNlc5wB3cpPUn2XmzZp1+oYICbAkg7oPCRJNHfXxIU2RYmFtWj3nKhMXKncmV4FgOxKEzcU6Ewe3msSj8kA5nx2DAJxmDmzzgfTtEPiw1AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAEgredkp7OE4eLN407y7k3GwqbdeamGx9AqOdiGO9fNFCQEgJfHiaOpof4QMqI0I1CeB8+ne4EGJcl7A+XfJqcxS2e9v/tb17cOVSB5kWMQKb8CPPIQtKipsgP7W0u4FgsaVJXU2Qg5yYGGFHZ35scR4bFgTdt+eHDr1ogrM+yMtRSSktTFxGcFIDtSOnqYsN77qlJQnXsReITcr8IKAUQEMsFHAvq3+qpvjISpTx/q0h587Tc7eVkac/obh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8kwQayTcvze6PW24JcuXfojqdAae

Using some ASN1 viewer, you can see the one from bc has a NULL value for the Digest Algorithm, as seen below: image

So, does this behavior is expected? There is some RFC definition for this value?

Removing this value from the bc-csharp library didn't break any test so I guess is an optional behavior.

This is a similar question as one on issue #164.

jimsch commented 5 years ago

RFC 5754 defines the correct encoding. Omitting NULL is preferred, but both are legal.