Skip to content

Commit 4e9ffce

Browse files
feat: add support for and document --deep for subresources (#316)
1 parent 806db73 commit 4e9ffce

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ Default to `undefined`.
6666
`optionsForFile` - *Function*
6767

6868
Function that receives the path to a file and can return the entitlements to use for that file to override the default behavior. The
69-
object this function returns can include any of the following optional keys.
69+
object this function returns can include any of the following optional keys. Any properties that are returned **override** the default
70+
values that `@electron/osx-sign` generates. Any properties not returned use the default value.
71+
72+
Take care when overriding the `entitlements` property as for security reasons different bundles within Electron are normally signed with
73+
different entitlement files. See the [default implementation](https://github.com/electron/osx-sign/blob/806db73bda1400e82b327619d0c2a793acf576a7/src/sign.ts#L91-L122)
74+
for a reference implementation.
7075

7176
| Option | Description | Usage Example |
7277
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
7378
| `entitlements` | String specifying the path to an `entitlements.plist` file. Will default to built-in entitlements files. Can also be an array of entitlement keys that osx-sign will write to an entitlements file for you. | `'path/to/entitlements'` |
7479
| `hardenedRuntime` | Boolean flag to enable the Hardened Runtime when signing the app. Enabled by default. | `false` |
7580
| `requirements` | Either a string beginning with `=` which specifies in plain text the [signing requirements](https://developer.apple.com/library/mac/documentation/Security/Conceptual/CodeSigningGuide/RequirementLang/RequirementLang.html) that you recommend to be used to evaluate the code signature, or a string specifying a path to a text or properly encoded `.rqset` file which contains those requirements. | `'=designated => identifier com.github.Electron'`<br> or <br> `'path/to/requirements.rqset'` |
76-
| `signatureFlags` | List of [code signature flags](https://developer.apple.com/documentation/security/seccodesignatureflags?language=objc). Accepts an array of strings or a comma-separated string. | `['kSecCodeSignatureRestrict']` |
81+
| `signatureFlags` | List of [code signature flags](https://keith.github.io/xcode-man-pages/codesign.1.html#OPTION_FLAGS). Accepts an array of strings or a comma-separated string. | `['runtime']` |
7782
| `timestamp` | String specifying the URL of the timestamp authority server. Defaults to the server provided by Apple. Please note that this default server may not support signatures not furnished by Apple. Disable the timestamp service with `none`. | `'https://different.timeserver'` |
83+
| `additionalArguments` | Array of strings specifying additional arguments to pass to the `codesign` command used to sign a specific file. | `['--deep']` |
7884

7985
**Note:** Only available via the JS API
8086

@@ -142,6 +148,35 @@ Default to latest Electron version.
142148

143149
It is recommended to utilize this option for best support of specific Electron versions. This may trigger pre/post operations for signing: For example, automation of setting `com.apple.security.application-groups` in entitlements file and of updating `Info.plist` with `ElectronTeamID` is enabled for all versions starting from `1.1.1`; set `preAutoEntitlements` option to `false` to disable this feature.
144150

151+
#### Signing with `--deep`
152+
153+
Some subresources that you may include in your Electron app may need to be signed with `--deep`, this is not typically safe to apply to the entire Electron app and therefore should be applied to _just_ your file.
154+
155+
```js
156+
const { signAsync } = require('@electron/osx-sign')
157+
signAsync({
158+
app: 'path/to/my.app',
159+
optionsForFile: (filePath) => {
160+
// For our one specific file we can pass extra options to be merged
161+
// with the default options
162+
if (path.basename(filePath) === 'myStrangeFile.jar') {
163+
return {
164+
additionalArguments: ['--deep'],
165+
};
166+
}
167+
168+
// Just use the default options for everything else
169+
return null;
170+
}
171+
})
172+
.then(function () {
173+
// Application signed
174+
})
175+
.catch(function (err) {
176+
// Handle the error
177+
})
178+
```
179+
145180
#### From the Command Line
146181

147182
```sh

src/sign.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ function defaultOptionsForFile (filePath: string, platform: ElectronMacPlatform)
126126
hardenedRuntime: true,
127127
requirements: undefined as string | undefined,
128128
signatureFlags: undefined as string | string[] | undefined,
129-
timestamp: undefined as string | undefined
129+
timestamp: undefined as string | undefined,
130+
additionalArguments: [] as string[] | undefined
130131
};
131132
}
132133

@@ -157,6 +158,7 @@ async function mergeOptionsForFile (
157158
mergedPerFileOptions.signatureFlags = opts.signatureFlags;
158159
}
159160
if (opts.timestamp !== undefined) mergedPerFileOptions.timestamp = opts.timestamp;
161+
if (opts.additionalArguments !== undefined) mergedPerFileOptions.additionalArguments = opts.additionalArguments;
160162
}
161163
return mergedPerFileOptions;
162164
}
@@ -286,6 +288,10 @@ async function signApplication (opts: ValidatedSignOptions, identity: Identity)
286288
perFileArgs.push('--options', [...new Set(optionsArguments)].join(','));
287289
}
288290

291+
if (perFileOptions.additionalArguments) {
292+
perFileArgs.push(...perFileOptions.additionalArguments);
293+
}
294+
289295
await execFileAsync(
290296
'codesign',
291297
perFileArgs.concat('--entitlements', perFileOptions.entitlements, filePath)

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export type PerFileSignOptions = {
4141
* timestamp server.
4242
*/
4343
timestamp?: string;
44+
/**
45+
* Additional raw arguments to pass to the "codesign" command.
46+
*
47+
* These can be things like "--deep" for instance when code signing specific resources that may
48+
* require such arguments.
49+
*/
50+
additionalArguments?: string[];
4451
}
4552

4653
type OnlySignOptions = {

0 commit comments

Comments
 (0)