(pem, private_key, keychain=login_keychain,
                          trusted_app_path=None, passphrase=None, gui=False,
                          password=None)
Install the certificate and private key into the keychain.

  Args:
    pem: str, the certificate in PEM format
    private_key: str, private key in PEM format
    keychain: str, keychain to install cert and key into
    trusted_app_path: list of strings, optional applications that can
                      access private key; a single string can be used for
                      backwards compatibility.  If None, trust is set Open
    passphrase: str, optional passphrase the private key is encrypted with
    gui: True if running in a gui context
    password: The user's password if already known.

  Raises:
    KeychainError: if there are any errors installing
Install the certificate and private key into the keychain.
Install the certificate and private key into the keychain .
def InstallCertInKeychain(pem, private_key, keychain=login_keychain,
                          trusted_app_path=None, passphrase=None, gui=False,
                          password=None):
  """Install the certificate and private key into the keychain.

  Args:
    pem: str, the certificate in PEM format
    private_key: str, private key in PEM format
    keychain: str, keychain to install cert and key into
    trusted_app_path: list of strings, optional applications that can
                      access private key; a single string can be used for
                      backwards compatibility.  If None, trust is set Open
    passphrase: str, optional passphrase the private key is encrypted with
    gui: True if running in a gui context
    password: The user's password if already known.

  Raises:
    KeychainError: if there are any errors installing
  """
  sudo, sudo_pass = _GetSudoContext(keychain,
                                    gui=gui,
                                    password=password)

  if type(trusted_app_path) == str:
    # Convert bare strings to a list for backwards compatibility
    trusted_app_path = [trusted_app_path]

  # TODO(user): Make this function just install the certificate and not handle
  # any key installation at all.
  InstallPrivateKeyInKeychain(private_key, keychain=keychain,
                              trusted_app_path=trusted_app_path,
                              passphrase=passphrase, gui=gui,
                              password=sudo_pass)

  temp_dir = tempfile.mkdtemp(prefix='cert_install')
  cert_file = '%s/certificate.cer' % temp_dir

  try:
    cert_handle = open(cert_file, 'w')
    cert_handle.write(pem)
    cert_handle.close()

    logging.info('Installing downloaded certificate into the %s keychain',
                 keychain)

    command = [CMD_SECURITY, 'import', cert_file, '-x', '-k', keychain]
    logging.debug('Command: %s', command)
    (stdout, stderr, status) = gmacpyutil.RunProcess(command, sudo=sudo,
                                                     sudo_password=sudo_pass)
    logging.debug('Certificate installation output: %s', stdout)
    if status:
      raise KeychainError(stdout, stderr)
  except IOError:
    raise KeychainError('Could not write to temp files in %s' % temp_dir)
  finally:
    shutil.rmtree(temp_dir)
def InstallCertInKeychain ( pem , private_key , keychain = login_keychain , trusted_app_path = None , passphrase = None , gui = False , password = None ) : sudo , sudo_pass = _GetSudoContext ( keychain , gui = gui , password = password ) if type ( trusted_app_path ) == str : # Convert bare strings to a list for backwards compatibility trusted_app_path = [ trusted_app_path ] # TODO(user): Make this function just install the certificate and not handle # any key installation at all. InstallPrivateKeyInKeychain ( private_key , keychain = keychain , trusted_app_path = trusted_app_path , passphrase = passphrase , gui = gui , password = sudo_pass ) temp_dir = tempfile . mkdtemp ( prefix = 'cert_install' ) cert_file = '%s/certificate.cer' % temp_dir try : cert_handle = open ( cert_file , 'w' ) cert_handle . write ( pem ) cert_handle . close ( ) logging . info ( 'Installing downloaded certificate into the %s keychain' , keychain ) command = [ CMD_SECURITY , 'import' , cert_file , '-x' , '-k' , keychain ] logging . debug ( 'Command: %s' , command ) ( stdout , stderr , status ) = gmacpyutil . RunProcess ( command , sudo = sudo , sudo_password = sudo_pass ) logging . debug ( 'Certificate installation output: %s' , stdout ) if status : raise KeychainError ( stdout , stderr ) except IOError : raise KeychainError ( 'Could not write to temp files in %s' % temp_dir ) finally : shutil . rmtree ( temp_dir )