def load_and_handle_cert(cert_string, now, base64decode=False):
 if base64decode:
  _cert_string = cert_string.decode('base-64')
 else:
  _cert_string = cert_string
 cert_loaded = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, _cert_string)
 cert_serial = cert_loaded.get_serial_number()
 cert_subjects = []
 for (name, value) in cert_loaded.get_subject().get_components():
  cert_subjects.append('{}:{}'.format(name, value))
 i = 0
 checked_all_extensions = False
 while (not checked_all_extensions):
  try:
   ext = cert_loaded.get_extension(i)
  except IndexError:
   san = None
   checked_all_extensions = True
  else:
   if (ext.get_short_name() == 'subjectAltName'):
    san = ext
    checked_all_extensions = True
   else:
    i += 1
 if (san is not None):
  cert_subjects.extend(str(san).split(', '))
 cert_subject = ', '.join(cert_subjects)
 cert_expiry = cert_loaded.get_notAfter()
 cert_expiry_date = datetime.datetime.strptime(cert_expiry, '%Y%m%d%H%M%SZ')
 time_remaining = (cert_expiry_date - now)
 return (cert_subject, cert_expiry_date, time_remaining, cert_serial)

def load_and_handle_cert ( cert_string , now , base64decode = False ) : if base64decode : _cert_string = cert_string . decode ( 'base-64' ) else : _cert_string = cert_string cert_loaded = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , _cert_string ) cert_serial = cert_loaded . get_serial_number ( ) cert_subjects = [ ] for ( name , value ) in cert_loaded . get_subject ( ) . get_components ( ) : cert_subjects . append ( '{}:{}' . format ( name , value ) ) i = 0 checked_all_extensions = False while ( not checked_all_extensions ) : try : ext = cert_loaded . get_extension ( i ) except IndexError : san = None checked_all_extensions = True else : if ( ext . get_short_name ( ) == 'subjectAltName' ) : san = ext checked_all_extensions = True else : i += 1 if ( san is not None ) : cert_subjects . extend ( str ( san ) . split ( ', ' ) ) cert_subject = ', ' . join ( cert_subjects ) cert_expiry = cert_loaded . get_notAfter ( ) cert_expiry_date = datetime . datetime . strptime ( cert_expiry , '%Y%m%d%H%M%SZ' ) time_remaining = ( cert_expiry_date - now ) return ( cert_subject , cert_expiry_date , time_remaining , cert_serial )
load a certificate .