'Verify that cert (in socket.getpeercert() format) matches hostname.
CRLs are not handled.
Returns error message if any problems are found and None on success.'

def __verifycert(self, cert, hostname):

    errstr = 'CA    Cert    verifying    failed:    '
    if (not cert):
        return ('%s    no    certificate    received' % errstr)
    dnsname = hostname.lower()
    certnames = []
    notafter = cert.get('notAfter')
    if notafter:
        if (time.time() >= cert_time_to_seconds(notafter)):
            return ('%s    certificate    expired    %s' % (errstr, notafter))
    for s in cert.get('subject', []):
        (key, value) = s[0]
        if (key == 'commonName'):
            certnames.append(value.lower())
    if (len(certnames) == 0):
        return ('%s    no    commonName    found    in    certificate' % errstr)
    for (key, value) in cert.get('subjectAltName', []):
        if (key == 'DNS'):
            certnames.append(value.lower())
    for certname in certnames:
        if ((certname == dnsname) or (('.' in dnsname) and (certname == ('*.' + dnsname.split('.', 1)[1])))):
            return None
    return ('%s    no    matching    domain    name    found    in    certificate' % errstr)
