def _verify_hostname(self, hostname, cert):
        common_name = self._get_common_name(cert)
        alt_names = self._get_subject_alt_names(cert)

        # replace * with alphanumeric and dash
        # replace . with literal .
        valid_patterns = [
            re.compile(
                pattern.replace(
                    r".", r"\."
                ).replace(
                    r"*", r"[0-9A-Za-z]+"
                )
            )
            for pattern
            in (set(common_name) | set(alt_names))
        ]

        return any(
            pattern.search(hostname)
            for pattern in valid_patterns
        )
Verify hostname against peer cert
dataset/ETHPy150Open cloudkick/libcloud/libcloud/httplib_ssl.py/LibcloudHTTPSConnection._verify_hostname