21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

sents a certificate, the commonly accepted convention is for either the commonName or<br />

the subjectAltName to contain the hostname of the server that is presenting it. Often,<br />

if both fields are present, they will contain the same information. If both fields are<br />

present and they contain different information, it is most likely because the<br />

commonName field contains some information other than a hostname. Even if both<br />

fields contain hostnames, the subjectAltName field should always take precedence<br />

over the commonName field. Certificate extensions were added to the X.509 standard in<br />

Version 3, so older certificates use the commonName field, while newer ones use the<br />

subjectAltName extension.<br />

Discussion<br />

The basic certificate verification, as described in Recipe 10.4, is the hard part of verifying<br />

a certificate. It ensures that the certificate is valid for the dates it was issued (i.e.,<br />

the current date is within the certificate’s start and end dates), it has not been revoked<br />

(provided that you have the relevant CRL), and it was signed by a trusted CA. Now<br />

you must make sure that the certificate is valid for the site that is claiming ownership<br />

of it. If you do not, any site could present you with Microsoft’s certificate, claiming it<br />

as their own, and it would successfully verify.<br />

When new certificates are issued, use of the subjectAltName extension is preferred<br />

over use of the commonName field, so that should be checked first. If no subjectAltName<br />

extension is present, the commonName field should be checked instead. When a<br />

subjectAltName is present but does not match, verification of the certificate should<br />

fail. Likewise, if the commonName field is checked and it does not match, verification of<br />

the certificate should fail. In either case, communication with the peer should be terminated<br />

if verification of its certificate fails.<br />

What we have described thus far, particularly in regard to the<br />

subjectAltName extension, is simplified a great deal. The<br />

subjectAltName extension is actually a container that may contain several<br />

different fields, each one responsible for different information. For<br />

our purposes, and the purposes of verifying the hostname within a certificate,<br />

we are only interested in the dnsName field. When we say that a<br />

subjectAltName extension is either present or absent, we are actually<br />

concerned with the presence or absence of the dnsName field within the<br />

subjectAltName field. In other words, if a subjectAltName extension is<br />

present but does not contain a dnsName field, we say that the<br />

subjectAltName extension is absent.<br />

If you are using OpenSSL, you will normally have a certificate as an X509 object. The<br />

following code will check the hostname in that object:<br />

#include <br />

#include <br />

#include <br />

540 | Chapter 10: Public Key Infrastructure<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!