(jdata, logger)
return True
Checks server SSL certificate for correct CN.
Checks server SSL certificate for correct CN.
Checks server SSL certificate for correct CN .
def _check(jdata, logger):
    """Checks server SSL certificate for correct CN."""
    host = jdata['data']['host']
    port = int(jdata['data'].get('port', 443))
    expected_hostname = jdata['data']['expected_hostname']
    cert = ssl.get_server_certificate(
        (host, port), ssl_version=ssl.PROTOCOL_TLSv1)
    x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    actual_hostname = x509.get_subject().CN
    logger.debug('Hostname in certificate: %s' % actual_hostname)
    assert actual_hostname == expected_hostname, "Hostname doesn't match."
    return True
def _check ( jdata , logger ) : host = jdata [ 'data' ] [ 'host' ] port = int ( jdata [ 'data' ] . get ( 'port' , 443 ) ) expected_hostname = jdata [ 'data' ] [ 'expected_hostname' ] cert = ssl . get_server_certificate ( ( host , port ) , ssl_version = ssl . PROTOCOL_TLSv1 ) x509 = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , cert ) actual_hostname = x509 . get_subject ( ) . CN logger . debug ( 'Hostname in certificate: %s' % actual_hostname ) assert actual_hostname == expected_hostname , "Hostname doesn't match." return True