code: def legacy_validate_callback(cert, hostname):
      """legacy method to validate the peer's SSL certificate, and to check
      the commonName of the certificate to ensure it matches the hostname we
      used to make this connection.  Does not support subjectAltName records
      in certificates.
  
      raises TTransportException if the certificate fails validation.
      """
      if "subject" not in cert:
          raise TTransportException(
              TTransportException.NOT_OPEN,
              "No SSL certificate found from %s" % hostname,
          )
      fields = cert["subject"]
      for field in fields:
          # ensure structure we get back is what we expect
          if not isinstance(field, tuple):
              continue
          cert_pair = field[0]
          if len(cert_pair) < 2:
              continue
          cert_key, cert_value = cert_pair[0:2]
          if cert_key != "commonName":
              continue
          certhost = cert_value
          # this check should be performed by some sort of Access Manager
          if certhost == hostname:
              # success, cert commonName matches desired hostname
              return
          else:
              raise TTransportException(
                  TTransportException.UNKNOWN,
                  'Hostname we connected to "%s" doesn\'t match certificate '
                  'provided commonName "%s"' % (hostname, certhost),
              )
      raise TTransportException(
          TTransportException.UNKNOWN,
          'Could not validate SSL certificate from host "%s".  Cert=%s'
          % (hostname, cert),
      )
  
imports: import logging
  import sys
  from thrift.transport.TTransport import TTransportException
label_desc: Use image node_id 1 for calling a global function with example usage: legacy_validate_callback(cert, hostname) without return types