Skip to content

Commit ee90ff2

Browse files
committed
fix(mac): use hash instead of identity name to sign
Close #1629
1 parent 09c914d commit ee90ff2

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

packages/electron-builder/src/codeSign.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async function getValidIdentities(keychain?: string | null): Promise<Array<strin
185185
return result
186186
}
187187

188-
async function _findIdentity(type: CertType, qualifier?: string | null, keychain?: string | null): Promise<string | null> {
188+
async function _findIdentity(type: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {
189189
// https://github.com/electron-userland/electron-builder/issues/484
190190
//noinspection SpellCheckingInspection
191191
const lines = await getValidIdentities(keychain)
@@ -196,7 +196,7 @@ async function _findIdentity(type: CertType, qualifier?: string | null, keychain
196196
}
197197

198198
if (line.includes(namePrefix)) {
199-
return line.substring(line.indexOf('"') + 1, line.lastIndexOf('"'))
199+
return parseIdentity(line)
200200
}
201201
}
202202

@@ -218,13 +218,29 @@ async function _findIdentity(type: CertType, qualifier?: string | null, keychain
218218
}
219219
}
220220

221-
return line.substring(line.indexOf('"') + 1, line.lastIndexOf('"'))
221+
return parseIdentity(line)
222222
}
223223
}
224224
return null
225225
}
226226

227-
export function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<string | null> {
227+
export declare class Identity {
228+
readonly name: string
229+
readonly hash: string
230+
231+
constructor(name: string, hash: string)
232+
}
233+
234+
const _Identity = require("electron-osx-sign/util-identities").Identity
235+
236+
function parseIdentity(line: string): Identity {
237+
const firstQuoteIndex = line.indexOf('"')
238+
const name = line.substring(firstQuoteIndex + 1, line.lastIndexOf('"'))
239+
const hash = line.substring(0, firstQuoteIndex - 1)
240+
return new _Identity(name, hash)
241+
}
242+
243+
export function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {
228244
let identity = qualifier || process.env.CSC_NAME
229245
if (isEmptyOrSpaces(identity)) {
230246
if (keychain == null && !isCi && process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false") {

packages/electron-builder/src/macPackager.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { signAsync, SignOptions } from "electron-osx-sign"
66
import { ensureDir } from "fs-extra-p"
77
import * as path from "path"
88
import { AppInfo } from "./appInfo"
9-
import { appleCertificatePrefixes, CodeSigningInfo, createKeychain, findIdentity } from "./codeSign"
9+
import { appleCertificatePrefixes, CodeSigningInfo, createKeychain, findIdentity, Identity } from "./codeSign"
1010
import { Arch, DIR_TARGET, Platform, Target } from "./core"
1111
import { MacOptions, MasBuildOptions } from "./options/macOptions"
1212
import { BuildInfo } from "./packagerApi"
@@ -158,19 +158,19 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
158158
const explicitType = masOptions == null ? macOptions.type : masOptions.type
159159
const type = explicitType || "distribution"
160160
const isDevelopment = type === "development"
161-
let name = await findIdentity(isDevelopment ? "Mac Developer" : (isMas ? "3rd Party Mac Developer Application" : "Developer ID Application"), isMas ? masQualifier : qualifier, keychainName)
162-
if (name == null) {
161+
let identity = await findIdentity(isDevelopment ? "Mac Developer" : (isMas ? "3rd Party Mac Developer Application" : "Developer ID Application"), isMas ? masQualifier : qualifier, keychainName)
162+
if (identity == null) {
163163
if (!isMas && !isDevelopment && explicitType !== "distribution") {
164-
name = await findIdentity("Mac Developer", qualifier, keychainName)
165-
if (name != null) {
164+
identity = await findIdentity("Mac Developer", qualifier, keychainName)
165+
if (identity != null) {
166166
warn("Mac Developer is used to sign app — it is only for development and testing, not for production")
167167
}
168168
else if (qualifier != null) {
169169
throw new Error(`Identity name "${qualifier}" is specified, but no valid identity with this name in the keychain`)
170170
}
171171
}
172172

173-
if (name == null) {
173+
if (identity == null) {
174174
const message = process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false" ?
175175
`App is not signed: env CSC_IDENTITY_AUTO_DISCOVERY is set to false` :
176176
`App is not signed: cannot find valid ${isMas ? '"3rd Party Mac Developer Application" identity' : `"Developer ID Application" identity or custom non-Apple code signing certificate`}, see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`
@@ -186,15 +186,15 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
186186

187187
const signOptions: any = {
188188
"identity-validation": false,
189-
identity: name!,
189+
identity: identity!,
190190
type: type,
191191
platform: isMas ? "mas" : "darwin",
192192
version: this.info.electronVersion,
193193
app: appPath,
194194
keychain: keychainName || undefined,
195195
binaries: (isMas && masOptions != null ? masOptions.binaries : macOptions.binaries) || undefined,
196196
requirements: isMas || macOptions.requirements == null ? undefined : await this.getResource(macOptions.requirements),
197-
"gatekeeper-assess": appleCertificatePrefixes.find(it => name!.startsWith(it)) != null
197+
"gatekeeper-assess": appleCertificatePrefixes.find(it => identity!.name.startsWith(it)) != null
198198
}
199199

200200
const resourceList = await this.resourceList
@@ -226,7 +226,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
226226
signOptions["entitlements-inherit"] = customSignOptions.entitlementsInherit
227227
}
228228

229-
await task(`Signing app (identity: ${name})`, this.doSign(signOptions))
229+
await task(`Signing app (identity: ${identity.hash} ${identity.name})`, this.doSign(signOptions))
230230

231231
if (masOptions != null) {
232232
const certType = "3rd Party Mac Developer Installer"
@@ -247,7 +247,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
247247
}
248248

249249
//noinspection JSMethodCanBeStatic
250-
protected async doFlat(appPath: string, outFile: string, identity: string, keychain: string | n): Promise<any> {
250+
protected async doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | n): Promise<any> {
251251
// productbuild doesn't created directory for out file
252252
await ensureDir(path.dirname(outFile))
253253

packages/electron-builder/src/targets/pkg.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { exec, use } from "electron-builder-util"
33
import { statOrNull } from "electron-builder-util/out/fs"
44
import { unlink } from "fs-extra-p"
55
import * as path from "path"
6-
import { findIdentity } from "../codeSign"
6+
import { findIdentity, Identity } from "../codeSign"
77
import { Arch, Target } from "../core"
88
import MacPackager from "../macPackager"
99
import { PkgOptions } from "../options/macOptions"
@@ -79,10 +79,10 @@ export class PkgTarget extends Target {
7979
}
8080
}
8181

82-
export function prepareProductBuildArgs(identity: string | n, keychain: string | n) {
83-
const args = []
82+
export function prepareProductBuildArgs(identity: Identity | null, keychain: string | null | undefined): Array<string> {
83+
const args: Array<string> = []
8484
if (identity != null) {
85-
args.push("--sign", identity)
85+
args.push("--sign", identity.hash)
8686
if (keychain != null) {
8787
args.push("--keychain", keychain)
8888
}

test/src/helpers/CheckingPackager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Arch, BuildInfo, MacOptions, Target } from "electron-builder"
22
import SquirrelWindowsTarget from "electron-builder-squirrel-windows"
3+
import { Identity } from "electron-builder/out/codeSign"
34
import OsXPackager from "electron-builder/out/macPackager"
45
import { DmgTarget } from "electron-builder/out/targets/dmg"
56
import { SignOptions } from "electron-builder/out/windowsCodeSign"
@@ -65,7 +66,7 @@ export class CheckingMacPackager extends OsXPackager {
6566
}
6667

6768
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
68-
async doFlat(appPath: string, outFile: string, identity: string, keychain?: string | null): Promise<any> {
69+
async doFlat(appPath: string, outFile: string, identity: Identity, keychain?: string | null): Promise<any> {
6970
// skip
7071
}
7172

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,6 @@ binary@^0.3.0:
547547
buffers "~0.1.1"
548548
chainsaw "~0.1.0"
549549

550-
bit-buffer@^0.1.0:
551-
version "0.1.0"
552-
resolved "https://registry.yarnpkg.com/bit-buffer/-/bit-buffer-0.1.0.tgz#8164c15dbd218eea74e0843da70efa555a4402c4"
553-
554550
bl@^1.0.0:
555551
version "1.2.1"
556552
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.1.tgz#cac328f7bee45730d404b692203fcb590e172d5e"

0 commit comments

Comments
 (0)