1
1
import BluebirdPromise from "bluebird-lst"
2
2
import { deepAssign , Arch , AsyncTaskManager , exec , InvalidConfigurationError , log , use , getArchSuffix } from "builder-util"
3
3
import { signAsync } from "@electron/osx-sign"
4
- import { SignOptions } from "@electron/osx-sign/dist/cjs/types"
4
+ import { PerFileSignOptions , SignOptions } from "@electron/osx-sign/dist/cjs/types"
5
5
import { mkdir , readdir } from "fs/promises"
6
6
import { Lazy } from "lazy-val"
7
7
import * as path from "path"
@@ -268,8 +268,9 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
268
268
)
269
269
log . info ( "Signing addtional user-defined binaries: " + JSON . stringify ( binaries , null , 1 ) )
270
270
}
271
+ const customSignOptions = ( isMas ? masOptions : this . platformSpecificBuildOptions ) || this . platformSpecificBuildOptions
271
272
272
- const signOptions : any = {
273
+ const signOptions : SignOptions = {
273
274
identityValidation : false ,
274
275
// https://github.com/electron-userland/electron-builder/issues/1699
275
276
// kext are signed by the chipset manufacturers. You need a special certificate (only available on request) from Apple to be able to sign kext.
@@ -297,27 +298,22 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
297
298
identity : identity ? identity . name : undefined ,
298
299
type,
299
300
platform : isMas ? "mas" : "darwin" ,
300
- version : this . config . electronVersion ,
301
+ version : this . config . electronVersion || undefined ,
301
302
app : appPath ,
302
303
keychain : keychainFile || undefined ,
303
304
binaries,
304
- timestamp : isMas ? masOptions ?. timestamp : options . timestamp ,
305
- requirements : isMas || this . platformSpecificBuildOptions . requirements == null ? undefined : await this . getResource ( this . platformSpecificBuildOptions . requirements ) ,
306
- // https://github.com/electron-userland/electron-osx-sign/issues/196
307
- // will fail on 10.14.5+ because a signed but unnotarized app is also rejected.
308
- "gatekeeper-assess" : options . gatekeeperAssess === true ,
309
305
// https://github.com/electron-userland/electron-builder/issues/1480
310
306
strictVerify : options . strictVerify ,
311
- hardenedRuntime : isMas ? masOptions && masOptions . hardenedRuntime === true : options . hardenedRuntime !== false ,
307
+ optionsForFile : await this . getOptionsForFile ( appPath , isMas , customSignOptions ) ,
308
+ provisioningProfile : customSignOptions . provisioningProfile || undefined ,
312
309
}
313
310
314
- await this . adjustSignOptions ( signOptions , masOptions )
315
311
log . info (
316
312
{
317
313
file : log . filePath ( appPath ) ,
318
314
identityName : identity . name ,
319
315
identityHash : identity . hash ,
320
- provisioningProfile : signOptions [ "provisioning-profile" ] || "none" ,
316
+ provisioningProfile : signOptions . provisioningProfile || "none" ,
321
317
} ,
322
318
"signing"
323
319
)
@@ -342,37 +338,58 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
342
338
return true
343
339
}
344
340
345
- private async adjustSignOptions ( signOptions : any , masOptions : MasConfiguration | null ) {
341
+ private async getOptionsForFile ( appPath : string , isMas : boolean , customSignOptions : MacConfiguration ) {
346
342
const resourceList = await this . resourceList
347
- const customSignOptions = masOptions || this . platformSpecificBuildOptions
348
- const entitlementsSuffix = masOptions == null ? "mac" : "mas"
343
+ const entitlementsSuffix = isMas ? "mas" : "mac"
349
344
350
- let entitlements = customSignOptions . entitlements
351
- if ( entitlements == null ) {
352
- const p = `entitlements.${ entitlementsSuffix } .plist`
353
- if ( resourceList . includes ( p ) ) {
354
- entitlements = path . join ( this . info . buildResourcesDir , p )
355
- } else {
356
- entitlements = getTemplatePath ( "entitlements.mac.plist" )
345
+ const getEntitlements = ( filePath : string ) => {
346
+ // check if root app, then use main entitlements
347
+ if ( filePath === appPath ) {
348
+ if ( customSignOptions . entitlements ) {
349
+ return customSignOptions . entitlements
350
+ }
351
+ const p = `entitlements.${ entitlementsSuffix } .plist`
352
+ if ( resourceList . includes ( p ) ) {
353
+ return path . join ( this . info . buildResourcesDir , p )
354
+ } else {
355
+ return getTemplatePath ( "entitlements.mac.plist" )
356
+ }
357
357
}
358
- }
359
- signOptions . entitlements = entitlements
360
358
361
- let entitlementsInherit = customSignOptions . entitlementsInherit
362
- if ( entitlementsInherit == null ) {
359
+ // It's a login helper...
360
+ if ( filePath . includes ( "Library/LoginItems" ) ) {
361
+ return customSignOptions . entitlementsLoginHelper
362
+ }
363
+
364
+ // Only remaining option is that it's inherited entitlements
365
+ if ( customSignOptions . entitlementsInherit ) {
366
+ return customSignOptions . entitlementsInherit
367
+ }
363
368
const p = `entitlements.${ entitlementsSuffix } .inherit.plist`
364
369
if ( resourceList . includes ( p ) ) {
365
- entitlementsInherit = path . join ( this . info . buildResourcesDir , p )
370
+ return path . join ( this . info . buildResourcesDir , p )
366
371
} else {
367
- entitlementsInherit = getTemplatePath ( "entitlements.mac.plist" )
372
+ return getTemplatePath ( "entitlements.mac.plist" )
368
373
}
369
374
}
370
- signOptions [ "entitlements-inherit" ] = entitlementsInherit
371
375
372
- if ( customSignOptions . provisioningProfile != null ) {
373
- signOptions [ "provisioning-profile" ] = customSignOptions . provisioningProfile
376
+ const requirements = isMas || this . platformSpecificBuildOptions . requirements == null ? undefined : await this . getResource ( this . platformSpecificBuildOptions . requirements )
377
+
378
+ // harden by default for mac builds. Only harden mas builds if explicitly true (backward compatibility)
379
+ const hardenedRuntime = isMas ? customSignOptions . hardenedRuntime === true : customSignOptions . hardenedRuntime !== false
380
+
381
+ const optionsForFile : ( filePath : string ) => PerFileSignOptions = filePath => {
382
+ const entitlements = getEntitlements ( filePath )
383
+ const args = {
384
+ entitlements : entitlements || undefined ,
385
+ hardenedRuntime : hardenedRuntime || undefined ,
386
+ timestamp : customSignOptions . timestamp || undefined ,
387
+ requirements : requirements || undefined ,
388
+ }
389
+ log . debug ( { file : log . filePath ( filePath ) , ...args } , "selecting signing options" )
390
+ return args
374
391
}
375
- signOptions [ "entitlements-loginhelper" ] = customSignOptions . entitlementsLoginHelper
392
+ return optionsForFile
376
393
}
377
394
378
395
//noinspection JSMethodCanBeStatic
@@ -485,12 +502,12 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
485
502
if ( ! appleIdPassword ) {
486
503
throw new InvalidConfigurationError ( `APPLE_APP_SPECIFIC_PASSWORD env var needs to be set` )
487
504
}
488
- const options = this . generateOptions ( appPath , appleId , appleIdPassword )
505
+ const options = this . generateNotarizeOptions ( appPath , appleId , appleIdPassword )
489
506
await notarize ( options )
490
507
log . info ( null , "notarization successful" )
491
508
}
492
509
493
- private generateOptions ( appPath : string , appleId : string , appleIdPassword : string ) : NotarizeOptions {
510
+ private generateNotarizeOptions ( appPath : string , appleId : string , appleIdPassword : string ) : NotarizeOptions {
494
511
const baseOptions = { appPath, appleId, appleIdPassword }
495
512
const options = this . platformSpecificBuildOptions . notarize
496
513
if ( typeof options === "boolean" ) {
0 commit comments