Skip to content

Commit a78b4fd

Browse files
committed
feat: Specify patterns for archive traversals
1 parent f302e83 commit a78b4fd

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Default to `true`.
195195
The keychain name.
196196
Default to system default keychain.
197197

198-
`ignore` - *RegExp|Function|Array.<(RegExp|Function)>*
198+
`ignore` - *String|RegExp|Function|Array.<(String|RegExp|Function)>*
199199

200200
Regex, function or an array of regex's and functions that signal skipping signing a file.
201201
Elements of other types are treated as `RegExp`.
@@ -250,8 +250,9 @@ Default to `true`.
250250
Specify the URL of the timestamp authority server, default to server provided by Apple. Please note that this default server may not support signatures not furnished by Apple.
251251
Disable the timestamp service with `none`.
252252

253-
`traverse-archives` - *String*
254-
Flag to enable/disable automation of signing binaries inside zip-like archives.
253+
`traverse-archives` - *Boolean|String|RegExp|Function|Array.<(String|RegExp|Function)>*
254+
Option to enable automation of signing binaries inside zip-like archives.
255+
Not specifying any pattern will lead to marking all binary files as potential zip-like archives.
255256
Default to `false`.
256257

257258
`type` - *String*

bin/electron-osx-sign-usage.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ DESCRIPTION
4343
--identity-validation, --no-identity-validation
4444
Flag to enable/disable validation for the signing identity.
4545

46-
--ignore=path
46+
--ignore=pattern/to/ignore/1,pattern/to/ignore/2
4747
Path to skip signing. The string will be treated as a regular expression when used to match the file paths.
4848

4949
--keychain=keychain
@@ -86,8 +86,9 @@ DESCRIPTION
8686
Specify the URL of the timestamp authority server, default to server provided by Apple.
8787
Disable the timestamp service with ``none''.
8888

89-
--traverse-archives
90-
Flag to enable/disable automation of signing binaries inside zip-like archives.
89+
--traverse-archives, --traverse-archives=pattern/to/archive/1,pattern/to/archive/2
90+
Option to enable automation of signing binaries inside zip-like archives.
91+
Not specifying any pattern will lead to marking all binary files as potential zip-like archives.
9192
Disabled by default.
9293

9394
--type=type

bin/electron-osx-sign.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ var args = require('minimist')(process.argv.slice(2), {
1515
'pre-embed-provisioning-profile',
1616
'gatekeeper-assess',
1717
'hardened-runtime',
18-
'restrict',
19-
'traverse-archives'
18+
'restrict'
2019
],
2120
'default': {
2221
'pre-auto-entitlements': true,

sign.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function validateSignOptsAsync (opts) {
6868
opts['type'] = 'distribution'
6969
}
7070

71+
if (opts['traverse-archives'] && typeof opts['traverse-archives'] !== 'boolean' && !(opts['traverse-archives'] instanceof Array)) {
72+
opts['traverse-archives'] = [opts['traverse-archives']]
73+
}
74+
7175
return Promise.map([
7276
validateOptsAppAsync,
7377
validateOptsPlatformAsync,
@@ -141,6 +145,26 @@ function ignoreFilePath (opts, filePath) {
141145
return false
142146
}
143147

148+
/***
149+
* Helper function to facilitate whether to consider traversing a potential archive.
150+
* @function
151+
* @param {Object} opts - Options.
152+
* @param {string} humanReadableFilePath - The file path to check whether to include for traversal.
153+
* @returns {boolean} Whether to consider the potential archive for traversal.
154+
*/
155+
function shouldConsiderTraversingArchive (opts, humanReadableFilePath) {
156+
if (opts['traverse-archives']) {
157+
if (opts['traverse-archives'] === true) return true
158+
return opts['traverse-archives'].some(function (include) {
159+
if (typeof include === 'function') {
160+
return include(humanReadableFilePath)
161+
}
162+
return humanReadableFilePath.match(include)
163+
})
164+
}
165+
return false
166+
}
167+
144168
/**
145169
* Sign a zip-like archive child component of the app bundle.
146170
* This piece of automation helps to traverse zip-like archives and sign any enclosing binary files. See #229.
@@ -224,7 +248,7 @@ function signChildComponentAsync (opts, args, filePath, humanReadableFilePath =
224248
}
225249

226250
var promise
227-
if (opts['traverse-archives']) {
251+
if (shouldConsiderTraversingArchive(opts, humanReadableFilePath)) {
228252
// Sign the child components if the file is an archive
229253
promise = isZipFileAsync(filePath)
230254
.then(function (archive) {

0 commit comments

Comments
 (0)