def _getinfos_cert(spec):
 infos = {}
 fullinfos = {}
 try:
  cert = spec.get('fullvalue', spec['value']).decode('base64')
 except Exception:
  return {}
 for hashtype in ['md5', 'sha1']:
  infos[('%shash' % hashtype)] = hashlib.new(hashtype, cert).hexdigest()
 proc = subprocess.Popen(['openssl', 'x509', '-noout', '-text', '-inform', 'DER'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 proc.stdin.write(cert)
 proc.stdin.close()
 try:
  newinfos = _CERTINFOS.search(proc.stdout.read()).groupdict()
  newfullinfos = {}
  for field in newinfos:
   if (len(newinfos[field]) > utils.MAXVALLEN):
    newfullinfos[field] = newinfos[field]
    newinfos[field] = newinfos[field][:utils.MAXVALLEN]
  infos.update(newinfos)
  fullinfos.update(newfullinfos)
 except Exception:
  pass
 res = {}
 if infos:
  res['infos'] = infos
 if fullinfos:
  res['fullinfos'] = fullinfos
 return res

def _getinfos_cert ( spec ) : infos = { } fullinfos = { } try : cert = spec . get ( 'fullvalue' , spec [ 'value' ] ) . decode ( 'base64' ) except Exception : return { } for hashtype in [ 'md5' , 'sha1' ] : infos [ ( '%shash' % hashtype ) ] = hashlib . new ( hashtype , cert ) . hexdigest ( ) proc = subprocess . Popen ( [ 'openssl' , 'x509' , '-noout' , '-text' , '-inform' , 'DER' ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) proc . stdin . write ( cert ) proc . stdin . close ( ) try : newinfos = _CERTINFOS . search ( proc . stdout . read ( ) ) . groupdict ( ) newfullinfos = { } for field in newinfos : if ( len ( newinfos [ field ] ) > utils . MAXVALLEN ) : newfullinfos [ field ] = newinfos [ field ] newinfos [ field ] = newinfos [ field ] [ : utils . MAXVALLEN ] infos . update ( newinfos ) fullinfos . update ( newfullinfos ) except Exception : pass res = { } if infos : res [ 'infos' ] = infos if fullinfos : res [ 'fullinfos' ] = fullinfos return res
extract info from a certificate in an handy-to-index-and-query form .