(keychain=None)
Gets all certificates in a given keychain.

  On a newly-created keychain, searching for all certs gives a
  CSSMERR_DL_INVALID_RECORDTYPE error and sets the returncode to 9. Just
  assume there are no certs in this case.

  Args:
    keychain: str, keychain to look in

  Yields:
    Certificate objects

  Raises:
    CertError: could not search for certficates
    StopIteration: no more matching certs
Gets all certificates in a given keychain.
Gets all certificates in a given keychain .
def _GetCertificates(keychain=None):
  """Gets all certificates in a given keychain.

  On a newly-created keychain, searching for all certs gives a
  CSSMERR_DL_INVALID_RECORDTYPE error and sets the returncode to 9. Just
  assume there are no certs in this case.

  Args:
    keychain: str, keychain to look in

  Yields:
    Certificate objects

  Raises:
    CertError: could not search for certficates
    StopIteration: no more matching certs
  """
  cmd = [CMD_SECURITY, 'find-certificate', '-a', '-p']

  if keychain is not None:
    cmd.extend([keychain])

  (stdout, stderr, returncode) = gmacpyutil.RunProcess(cmd)
  if returncode == 0:
    allcerts = stdout.split(PEM_FOOTER)
    allcerts.pop()
    for cert in allcerts:
      pem = '%s\n%s\n%s' % (PEM_HEADER, '\n'.join(cert.split()[2:]), PEM_FOOTER)
      try:
        yield Certificate(pem)
      except CertError, e:
        logging.info('Encountered an unparseable certificate, continuing.')
        logging.debug(str(e))
        continue
  elif returncode == 9:
    raise StopIteration
  else:
    raise CertError('Unable to get all certificates. Exit code: %s, '
                    'Output: %s' % (returncode, stderr))
def _GetCertificates ( keychain = None ) : cmd = [ CMD_SECURITY , 'find-certificate' , '-a' , '-p' ] if keychain is not None : cmd . extend ( [ keychain ] ) ( stdout , stderr , returncode ) = gmacpyutil . RunProcess ( cmd ) if returncode == 0 : allcerts = stdout . split ( PEM_FOOTER ) allcerts . pop ( ) for cert in allcerts : pem = '%s\n%s\n%s' % ( PEM_HEADER , '\n' . join ( cert . split ( ) [ 2 : ] ) , PEM_FOOTER ) try : yield Certificate ( pem ) except CertError , e : logging . info ( 'Encountered an unparseable certificate, continuing.' ) logging . debug ( str ( e ) ) continue elif returncode == 9 : raise StopIteration else : raise CertError ( 'Unable to get all certificates. Exit code: %s, ' 'Output: %s' % ( returncode , stderr ) )