code: def x509_to_dict(x509):
      
      from requests.packages.urllib3.contrib.pyopenssl import get_subj_alt_name
      res = {
              'subject': (
                  (('commonName', x509.get_subject().CN),),
              ),
              'subjectAltName': [
                  ('DNS', value)
                  for value in get_subj_alt_name(x509)
              ]
      }
      notAfter = x509.get_notAfter()
      if notAfter is not None:
          parsedtime = asn1_generaltime_to_seconds(notAfter)
          if parsedtime is not None:
              res['notAfter'] = parsedtime.strftime('%b %d %H:%M:%S %Y')
              if parsedtime.tzinfo is None:
                  res['notAfter'] += ' GMT'
          else:
              # give up parsing, just set the string
              res['notAfter'] = notAfter
      return res
docs: Parse a x509 pyopenssl object to a dictionary with keys
      subject, subjectAltName and optional notAfter.