import * as core from '@actions/core' ; import * as exec from '@actions/exec' ; import { ExecOptions } from '@actions/exec/lib/interfaces' ; export async function installCertIntoTemporaryKeychain ( keychain , setupKeychain , keychainPassword , p12FilePath , p12Password ) { let output = '' ; const options = { } ; options . listeners = { stdout : ( data ) => { output += data . toString ( ) ; } } ; if ( keychain . endsWith ( '.keychain' ) ) { throw new Error ( 'keychain name should not end in .keychain' ) ; } if ( p12FilePath === '' ) { throw new Error ( 'p12FilePath must not be empty' ) ; } if ( p12Password === '' ) { throw new Error ( 'p12Password must not be empty' ) ; } if ( keychainPassword === '' ) { throw new Error ( 'keychainPassword must not be empty' ) ; } const tempKeychain = `${ keychain }.keychain` ; if ( setupKeychain ) { await createKeychain ( tempKeychain , keychainPassword , options ) ; } await unlockKeychain ( tempKeychain , keychainPassword , options ) ; await importPkcs12 ( tempKeychain , p12FilePath , p12Password , options ) ; await setPartitionList ( tempKeychain , keychainPassword ) ; await updateKeychainList ( tempKeychain , options ) ; core . setOutput ( 'security-response' , output ) ; } param keychain param options async function updateKeychainList ( keychain , options ? ) { const args = [ 'list-keychains' , '-d' , 'user' , '-s' , keychain , 'login.keychain' ] ; await exec . exec ( 'security' , args , options ) ; } param keychain param options export async function deleteKeychain ( keychain , options ? ) { if ( keychain . endsWith ( '.keychain' ) ) { throw new Error ( 'keychain name should not end in .keychain' ) ; } await exec . exec ( 'security' , [ 'delete-keychain' , `${ keychain }.keychain` ] , options ) ; } param keychain param p12FilePath param p12Password param options async function importPkcs12 ( keychain , p12FilePath , p12Password , options ? ) { const importArgs = [ 'import' , p12FilePath , '-k' , keychain , '-f' , 'pkcs12' , '-A' , '-T' , '/usr/bin/codesign' , '-T' , '/usr/bin/security' , '-P' , p12Password ] ; await exec . exec ( 'security' , importArgs , options ) ; } param keychain param password param options async function setPartitionList ( keychain , password , options ? ) { const args = [ 'set-key-partition-list' , '-S' , 'apple-tool:,apple:' , '-k' , password , keychain ] ; await exec . exec ( 'security' , args , options ) ; } param keychain param password param options async function unlockKeychain ( keychain , password , options ? ) { const args = [ 'unlock-keychain' , '-p' , password , keychain ] ; await exec . exec ( 'security' , args , options ) ; } param keychain param password param options async function createKeychain ( keychain , password , options ) { const createArgs = [ 'create-keychain' , '-p' , password , keychain ] ; await exec . exec ( 'security' , createArgs , options ) ; const setSettingsArgs = [ 'set-keychain-settings' , '-lut' , '21600' , keychain ] ; await exec . exec ( 'security' , setSettingsArgs , options ) ; }