- Verifying the certificate itself and attaching it to a CA certificate that you already trust allows you to verify the authenticity and validity of the certificate.
- Checking the hostname in the certificate allows you to verify that you are talking to the server you want to talk to, provided that the certificate is valid.
- (Verifying that the remote party really belongs to the one who has the private key for this certificate is performed in SSL / TLS confirmation mode.)
If you need an analogy with passport / ID verification for people:
- Verifying a certificate is similar to verifying the authenticity of a passport or form of identification. You can decide which forms of identifier you want to accept from a person (for example, passport, driver’s license, personnel card, ...) and which issuing countries you trust to verify their authenticity.
- Checking that the remote side belongs to the private key is similar to checking that the image on the passport / ID matches the face of the person in front of you.
- Checking the host name is similar to checking that the passport belongs to the person whose name you are looking for.
If you do not check the host name, anyone who has a valid passport that you think is genuine can come to you and claim that he is the one you are looking for (by name).
In a very limited set of circumstances where you trust only a particular CA or a self-signed certificate, where you allow any potential certificate to impersonate another from the entire set of trusted certificates, it may be acceptable to ignore this check, but this is very rare and not good practice.
Checking that the name in the passport matches the name of the person you are looking for will be considered common sense; do this for certificates too. Doing this does not allow anyone who has a certificate that you trust to be genuine to represent any other certificate you trust, thereby potentially leading to MITM attacks.
HTTPS hostname validation rules are defined in RFC 2818 Section 3.1 (also most recently in the Best Practices specification, RFC 6125 , has not yet been implemented).
In short, the host name should be in the DNS record of the subject of the alternative name (although you can return to the CN DN of the object where the certificate does not have SAN). When you use the IP address, the IP address must be in the SAN IP address entry (although some browsers allow you to leave with the IP address in the CN DN of the topic).
Bruno
source share