Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom .p12 certificates #216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export function build(options: BuildOptions = {}): Promise<any> {
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 Expand Up @@ -95,4 +98,4 @@ export function build(options: BuildOptions = {}): Promise<any> {
return null
}
})
}
}
16 changes: 8 additions & 8 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,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(Promise.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)),
error => {
const tasks = [deleteFile(appleCertPath, true), deleteFile(developerCertPath, true)]
const tasks = [deleteFile(authorityCertPath, true), deleteFile(developerCertPath, true)]
if (error != null) {
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 Expand Up @@ -97,4 +97,4 @@ export function downloadCertificate(cscLink: string): Promise<string> {
const certPath = path.join(tmpdir(), randomString() + ".p12")
return download(cscLink, certPath)
.thenReturn(certPath)
}
}
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -106,4 +106,4 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
})
.thenReturn(outDir + "/" + resultPath)
}
}
}
3 changes: 2 additions & 1 deletion src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface PackagerOptions {
projectDir?: string

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

Expand Down Expand Up @@ -131,4 +132,4 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
}

abstract packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any>
}
}