code: def extract_python_dict_from_x509(x509):
      
      result = {
          "subject": (
              (("commonName", x509.get_subject().commonName),),
          )
      }
  
      for ext_idx in range(x509.get_extension_count()):
          ext = x509.get_extension(ext_idx)
          sn = ext.get_short_name()
          if sn != b"subjectAltName":
              continue
  
          data = pyasn1.codec.der.decoder.decode(
              ext.get_data(),
              asn1Spec=pyasn1_modules.rfc2459.SubjectAltName())[0]
          for name in data:
              dNSName = name.getComponentByPosition(2)
              if dNSName is None:
                  continue
  
              if hasattr(dNSName, "isValue") and not dNSName.isValue:
                  continue
  
              result.setdefault("subjectAltName", []).append(
                  ("DNS", str(dNSName))
              )
  
      return result
docs: Extract a python dictionary similar to the return value of
      :meth:`ssl.SSLSocket.getpeercert` from the given
      :class:`OpenSSL.crypto.X509` `x509` object.
  
      Note that by far not all attributes are included; only those required to
      use :func:`ssl.match_hostname` are extracted and put in the result.
  
      In the future, more attributes may be added.