code: def validate_host(cert, name):
      
      cn = None
      for t, v in cert.get_subject().get_components():
          if t == b'CN':
              cn = v
              break
  
      if cn == name:
          return True
  
      # checking SAN
      s_name = name.decode('ascii')
      for i in range(cert.get_extension_count()):
          ext = cert.get_extension(i)
          if ext.get_short_name() == b'subjectAltName':
              s = str(ext)
              # SANs are usually have form like: DNS:hostname
              if s.startswith('DNS:') and s[4:] == s_name:
                  return True
  
      # TODO handle wildcards
      return False
docs: Validates host name against certificate
  
      @param cert: Certificate returned by host
      @param name: Actual host name used for connection
      @return: Returns true if host name matches certificate