1

Imagine that we have an x509 cert (if it matters, in .pem format) and a key supposed to certified with it.

How can I validate, that the cert certifies exactly that key?

My impression is that it is enough to examine that the cert and the key have the same pub key. I think it is because this is the only shared information between them. However, I am not sure.

Is it enough?

What happens if a possible attacker, having access to the cert, simply re-writes the pubkey part in it?

(Note, the validation of the cert is a different thing. Here I only want to be sure, that the cert certifies exactly that key.)

1

1 Answer 1

4

How can I validate, that the cert certifies exactly that key?

A certificate does not "certify" a key. What you describe is to check if the private key matches the public key in the certificate and thus can be used to prove ownership of the certificate against a third party. And yes, it is enough for this to check that the public key you have in the key pair is exactly the same as the public key of the certificate.

What happens if a possible attacker, having access to the cert, simply re-writes the pubkey part in it?

In this case the issuers signature of the certificate will not match anymore and the validation of the certificate will fail.

4
  • While I thank you the answer (up + accept given), I need to mention: yes, the certificate certifies a key in the sense, that it has the pubkey what can be compared to the pubkey in the key.
    – peterh
    Nov 28, 2019 at 12:43
  • @peterhsaysreinstateMonica I think "certificate certifies a key" is, at best, the wrong way of looking at it, and at worst, meaningless (the certificate contains a copy of the public key). The certificate certifies something else (be it a URL in the case of a SSL/TLS certificate; or that some piece of code was written by a certain company, in the case of a code-signing certificate). The public key (obtained either from a parent certificate or by being a "well known trusted root") certifies who it was that created the certificate.
    – TripeHound
    Nov 28, 2019 at 14:33
  • @peterhsaysreinstateMonica Or are you asking: given a (potential) public / private key pair (what you may be calling "the key"), is it possible to verify that the those two keys actually do form a public-private key-pair? And if so, does a certificate purporting to be signed using the private key help in this verification?
    – TripeHound
    Nov 28, 2019 at 14:36
  • @TripeHound In the sense of my question, key means: "an x509 key file containing the public and the private keys". It is a different thing than the "public key" (what is, typically, mostly a big number and some params, existing both in the key file and in the cert file).
    – peterh
    Nov 28, 2019 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .