The system architecture that I'm working on requires the comparison between two SSL/TLS (typically X.509) certificates. That is to say, I need to verify if two certificates are the the same or not.
I don't care if they're expired or self-signed, I just want to be sure that they have not being altered in any way.
Which is the most correct way to perform such operation? Would it be enough to compare the two signatures (two byte[]) of those certificates or is this operation prone to exploits I haven't considered so far?
I don't think comparing the two signatures is sufficient, unless your code directly gets the certificates from some instance which assures that the signature has also been checked against the certificate itself. So under many circumstances, I'd say: no.
I believe the most flexible, correct way would be to check the integrity of the two certificates (body vs signature) individually and then directly compare all the information in the certificates which you require to be identical. (I'm putting it this way because I'm not sure you require total identity).
However, if your goal is really to check the certificate a server sends for authenticity, then it's not necessarily wise to have a copy of the whole certificate in your code; in this case, you could verify the server's certificate and then check its body against a secure hash which is stored in your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With