runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Reasons behind X509Certificate.cs Equals()

Open Dissimilis opened this issue 8 years ago • 3 comments

X509Certificate.Equals() compares only serialNumber and issuer, which is counter-intuitive for some developers. It's very easy to wrongly implement certificate pinning assuming Equals() does the job. Whats the reasoning behind such Equals() implementation? Why not a hash check?

https://github.com/dotnet/corefx/blob/efcd88d8e7b4bd8a30a4008da3231ec6617d365a/src/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs#L262

Dissimilis avatar May 29 '18 11:05 Dissimilis

cc: @bartonjs

gfoidl avatar May 29 '18 11:05 gfoidl

I don't know that we can really answer that question.

  • It has the behavior it does in .NET Core because that's what it had in .NET Framework 4.6.
  • It has the behavior it does in .NET Framework 4.6 because that's what it had in .NET Framework 1.1.
  • .NET Framework 1.1 just turned 15. So this decision was at least 15 years ago.

The best I can come up with is that the CMS/PKCS7/SMIME formats originally used Issuer+Serial as the means of identifying a certificate, and the developer at the time considered that a good enough standard.

Personally, I recommend just comparing cert.RawData values, as it eliminates the concern of "what if this thumbprint hash algorithm is broken in the future`?

But at this point we probably can't change it, because of compatibility.

bartonjs avatar Jun 04 '18 16:06 bartonjs

The question was "answered" and discussion has died out, closing the issue.

bartonjs avatar Sep 13 '18 22:09 bartonjs