code: def verify_tls(self, socket, hostname, context):
          
          cert = socket.getpeercert()
  
          try:
              # Make sure the hostnames for which this certificate is valid include the one we're connecting to.
              ssl.match_hostname(cert, hostname)
          except ssl.CertificateError:
              return ssl.ALERT_DESCRIPTION_BAD_CERTIFICATE
  
          return None
docs: Verify a TLS connection. Return behaviour is dependent on the as_callback parameter:
              - If True, a return value of None means verification succeeded, else it failed.
              - If False, a return value of True means verification succeeded, an exception or False means it failed.