Skip to content

Commit

Permalink
feat: import startssl certs by default
Browse files Browse the repository at this point in the history
No need to define CSA_LINK explicitly
  • Loading branch information
develar committed Apr 23, 2016
1 parent 84ead73 commit 0f19455
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@
"chalk": "^1.1.3",
"command-line-args": "^2.1.6",
"deep-assign": "^2.0.0",
"electron-packager": "^7.0.0",
"electron-packager": "^7.0.1",
"electron-winstaller-fixed": "~2.3.0-beta.4",
"fs-extra": "^0.28.0",
"fs-extra-p": "^0.2.0",
"fs-extra-p": "^0.3.0",
"globby": "^4.0.0",
"hosted-git-info": "^2.1.4",
"image-size": "^0.5.0",
Expand All @@ -72,7 +71,8 @@
"read-package-json": "^2.0.3",
"signcode": "^0.4.0",
"source-map-support": "^0.4.0",
"tmp": "0.0.28"
"tmp": "0.0.28",
"typescript": "^1.9.0-dev.20160423"
},
"optionalDependencies": {
"appdmg": "^0.3.7"
Expand Down
20 changes: 14 additions & 6 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,39 @@ export function generateKeychainName(): string {
}

export function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, csaLink?: string): Promise<CodeSigningInfo> {
const authorityCertPath = path.join(tmpdir(), randomString() + ".cer")
const authorityCerts = [csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer"]
if (csaLink == null) {
authorityCerts.push("https://startssl.com/certs/sca.code2.crt", "https://startssl.com/certs/sca.code3.crt")
}
const authorityCertPaths = authorityCerts.map(() => path.join(tmpdir(), randomString() + ".cer"))

const developerCertPath = path.join(tmpdir(), randomString() + ".p12")

const keychainPassword = randomString()
return executeFinally(BluebirdPromise.all([
download(csaLink || "https://developer.apple.com/certificationauthority/AppleWWDRCA.cer", authorityCertPath),
BluebirdPromise.map(authorityCertPaths, (p, i) => download(authorityCerts[i], p)),
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, authorityCertPath, developerCertPath, cscKeyPassword)),
.then(() => importCerts(keychainName, authorityCertPaths, developerCertPath, cscKeyPassword)),
errorOccurred => {
const tasks = [deleteFile(authorityCertPath, true), deleteFile(developerCertPath, true)]
const tasks = authorityCertPaths.map(it => deleteFile(it, true))
tasks.push(deleteFile(developerCertPath, true))
if (errorOccurred) {
tasks.push(deleteKeychain(keychainName))
}
return all(tasks)
})
}

async function importCerts(keychainName: string, authorityCertPath: string, developerCertPath: string, cscKeyPassword: string): Promise<CodeSigningInfo> {
await exec("security", ["import", authorityCertPath, "-k", keychainName, "-T", "/usr/bin/codesign"])
async function importCerts(keychainName: string, authorityCertPaths: Array<string>, developerCertPath: string, cscKeyPassword: string): Promise<CodeSigningInfo> {
for (let p of authorityCertPaths) {
await exec("security", ["import", p, "-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/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface BuildMetadata {
Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.
* If you don't plan to build windows installer, you can omit it.
* If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico` by default.
* If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${u}/${p}/master/build/icon.ico` by default.
*/
readonly iconUrl?: string

Expand Down
16 changes: 11 additions & 5 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Packager implements BuildInfo {
for (let platform of platforms) {
const helper = this.createHelper(platform, cleanupTasks)
for (let arch of normalizeArchs(platform, this.options.arch)) {
await this.installAppDependencies(arch)
await this.installAppDependencies(platform, arch)
// electron-packager uses productName in the directory name
const appOutDir = path.join(outDir, `${helper.appName}-${platform.nodeName}-${arch}`)
await helper.pack(outDir, appOutDir, arch)
Expand Down Expand Up @@ -153,14 +153,20 @@ export class Packager implements BuildInfo {
}
}

private installAppDependencies(arch: string): Promise<any> {
private installAppDependencies(platform: Platform, arch: string): Promise<any> {
if (this.isTwoPackageJsonProjectLayoutUsed) {
return installDependencies(this.appDir, this.electronVersion, arch, "rebuild")
if (platform.nodeName === process.platform) {
return installDependencies(this.appDir, this.electronVersion, arch, "rebuild")
}
else {
log("Skip app dependencies rebuild because platform is different")
}
}
else {
log("Skipping app dependencies installation because dev and app dependencies are not separated")
return BluebirdPromise.resolve()
log("Skip app dependencies rebuild because dev and app dependencies are not separated")
}

return BluebirdPromise.resolve()
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/promise.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Promise as BluebirdPromise } from "bluebird"
import { red } from "chalk"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")

export function printErrorAndExit(error: Error) {
console.error(error.stack || error.message || error)
console.error(red(error.stack.toString() || error.message || error.toString()))
process.exit(-1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/repositoryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { readFile } from "fs-extra-p"
import { AppMetadata, Metadata } from "./metadata"
import * as path from "path"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Array.isArray(__awaiter)

export interface ProjectMetadataProvider {
metadata: AppMetadata
Expand Down
9 changes: 5 additions & 4 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
if (!iconUrl) {
use(this.customBuildOptions, it => iconUrl = it.iconUrl)

if (!iconUrl) {
use(this.info.repositoryInfo, async(it) =>
use(await it.getInfo(this), it =>
iconUrl = `https://raw.githubusercontent.com/${it.user}/${it.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`))
if (!iconUrl && this.info.repositoryInfo != null) {
const info = await this.info.repositoryInfo.getInfo(this)
if (info != null) {
iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`
}
}

if (!iconUrl) {
Expand Down

0 comments on commit 0f19455

Please sign in to comment.