Skip to content

Commit

Permalink
feat: Allow custom .p12 certificates
Browse files Browse the repository at this point in the history
Closes #216
  • Loading branch information
pauliusuza authored and develar committed Mar 9, 2016
1 parent 5d376e1 commit 6918916
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export async function build(options: BuildOptions = {}): Promise<void> {
if (options.cscLink == null) {
options.cscLink = process.env.CSC_LINK
}
if (options.csaLink == null) {
options.csaLink = process.env.CSA_LINK
}
if (options.cscKeyPassword == null) {
options.cscKeyPassword = process.env.CSC_KEY_PASSWORD
}
Expand Down
14 changes: 7 additions & 7 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ export function generateKeychainName(): string {
return "csc-" + randomString() + ".keychain"
}

export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string): Promise<CodeSigningInfo> {
const appleCertPath = path.join(tmpdir(), randomString() + ".cer")
export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, csaLink?: string): Promise<CodeSigningInfo> {
const authorityCertPath = path.join(tmpdir(), randomString() + ".cer")
const developerCertPath = path.join(tmpdir(), randomString() + ".p12")

const keychainPassword = randomString()
return executeFinally(BluebirdPromise.all([
download("https://developer.apple.com/certificationauthority/AppleWWDRCA.cer", appleCertPath),
download(csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer", authorityCertPath),
download(cscLink, developerCertPath),
BluebirdPromise.mapSeries([
["create-keychain", "-p", keychainPassword, keychainName],
["unlock-keychain", "-p", keychainPassword, keychainName],
["set-keychain-settings", "-t", "3600", "-u", keychainName]
], it => exec("security", it))
])
.then(() => importCerts(keychainName, appleCertPath, developerCertPath, cscKeyPassword)),
.then(() => importCerts(keychainName, authorityCertPath, developerCertPath, cscKeyPassword)),
errorOccurred => {
const tasks = [deleteFile(appleCertPath, true), deleteFile(developerCertPath, true)]
const tasks = [deleteFile(authorityCertPath, true), deleteFile(developerCertPath, true)]
if (errorOccurred) {
tasks.push(deleteKeychain(keychainName))
}
return all(tasks)
})
}

async function importCerts(keychainName: string, appleCertPath: string, developerCertPath: string, cscKeyPassword: string): Promise<CodeSigningInfo> {
await exec("security", ["import", appleCertPath, "-k", keychainName, "-T", "/usr/bin/codesign"])
async function importCerts(keychainName: string, authorityCertPath: string, developerCertPath: string, cscKeyPassword: string): Promise<CodeSigningInfo> {
await exec("security", ["import", authorityCertPath, "-k", keychainName, "-T", "/usr/bin/codesign"])
await exec("security", ["import", developerCertPath, "-k", keychainName, "-T", "/usr/bin/codesign", "-P", cscKeyPassword])
let cscName = await extractCommonName(cscKeyPassword, developerCertPath)
return {
Expand Down
2 changes: 1 addition & 1 deletion src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
if (this.options.cscLink != null && this.options.cscKeyPassword != null) {
const keychainName = generateKeychainName()
cleanupTasks.push(() => deleteKeychain(keychainName))
this.codeSigningInfo = createKeychain(keychainName, this.options.cscLink, this.options.cscKeyPassword)
this.codeSigningInfo = createKeychain(keychainName, this.options.cscLink, this.options.cscKeyPassword, this.options.csaLink)
}
else {
this.codeSigningInfo = BluebirdPromise.resolve(null)
Expand Down
1 change: 1 addition & 0 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface PackagerOptions {
projectDir?: string

cscLink?: string
csaLink?: string
cscKeyPassword?: string
}

Expand Down

0 comments on commit 6918916

Please sign in to comment.