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

  Args:
    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.  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 private key into the keychain.
Install the private key into the keychain .
def InstallPrivateKeyInKeychain(private_key, keychain=login_keychain,
                                trusted_app_path=None, passphrase=None,
                                gui=False, password=None):
  """Install the private key into the keychain.

  Args:
    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.  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)

  temp_dir = tempfile.mkdtemp(prefix='cert_pkey_install')
  key_file = '%s/private.key' % temp_dir

  try:
    key_handle = open(key_file, 'w')
    key_handle.write(private_key)
    key_handle.close()

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

    command = [CMD_SECURITY, 'import', key_file, '-x', '-k', keychain]
    if passphrase:
      command.extend(['-P', passphrase])
    if trusted_app_path:
      for trusted_app in trusted_app_path:
        if os.path.exists(trusted_app):
          command.extend(['-T', trusted_app])
    else:
      command.extend(['-A'])
    logging.debug('Command: %s', command)
    (stdout, stderr, status) = gmacpyutil.RunProcess(command, sudo=sudo,
                                                     sudo_password=sudo_pass)
    logging.debug('Private key 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 InstallPrivateKeyInKeychain ( private_key , keychain = login_keychain , trusted_app_path = None , passphrase = None , gui = False , password = None ) : sudo , sudo_pass = _GetSudoContext ( keychain , gui = gui , password = password ) temp_dir = tempfile . mkdtemp ( prefix = 'cert_pkey_install' ) key_file = '%s/private.key' % temp_dir try : key_handle = open ( key_file , 'w' ) key_handle . write ( private_key ) key_handle . close ( ) logging . info ( 'Installing downloaded key into the %s keychain' , keychain ) command = [ CMD_SECURITY , 'import' , key_file , '-x' , '-k' , keychain ] if passphrase : command . extend ( [ '-P' , passphrase ] ) if trusted_app_path : for trusted_app in trusted_app_path : if os . path . exists ( trusted_app ) : command . extend ( [ '-T' , trusted_app ] ) else : command . extend ( [ '-A' ] ) logging . debug ( 'Command: %s' , command ) ( stdout , stderr , status ) = gmacpyutil . RunProcess ( command , sudo = sudo , sudo_password = sudo_pass ) logging . debug ( 'Private key 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 )