'Simple certificate/host name checker.  Returns True if the
certificate matches, False otherwise.  Does not support
wildcards.'

def check_host_name(self, peercert, name):

    if (not peercert):
        return False
    if peercert.has_key('subjectAltName'):
        for (typ, val) in peercert['subjectAltName']:
            if ((typ == 'DNS') and (val == name)):
                return True
    else:
        cn = None
        for (attr, val) in peercert['subject']:
            if (attr == 'commonName'):
                cn = val
        if (cn is not None):
            return (cn == name)
    return False
