Skip to content

Commit

Permalink
feat: Specify patterns for archive traversals
Browse files Browse the repository at this point in the history
  • Loading branch information
sethlu committed Jul 19, 2020
1 parent f302e83 commit 942acd3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Default to `true`.
The keychain name.
Default to system default keychain.

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

Regex, function or an array of regex's and functions that signal skipping signing a file.
Elements of other types are treated as `RegExp`.
Expand Down Expand Up @@ -250,8 +250,9 @@ Default to `true`.
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.
Disable the timestamp service with `none`.

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

`type` - *String*
Expand Down
7 changes: 4 additions & 3 deletions bin/electron-osx-sign-usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DESCRIPTION
--identity-validation, --no-identity-validation
Flag to enable/disable validation for the signing identity.

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

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

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

--type=type
Expand Down
3 changes: 1 addition & 2 deletions bin/electron-osx-sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ var args = require('minimist')(process.argv.slice(2), {
'pre-embed-provisioning-profile',
'gatekeeper-assess',
'hardened-runtime',
'restrict',
'traverse-archives'
'restrict'
],
'default': {
'pre-auto-entitlements': true,
Expand Down
27 changes: 26 additions & 1 deletion sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function validateSignOptsAsync (opts) {
opts['type'] = 'distribution'
}

if (opts['traverse-archives'] && typeof opts['traverse-archives'] !== 'boolean' && !(opts['traverse-archives'] instanceof Array)) {
opts['traverse-archives'] = [opts['traverse-archives']]
}

return Promise.map([
validateOptsAppAsync,
validateOptsPlatformAsync,
Expand Down Expand Up @@ -141,6 +145,27 @@ function ignoreFilePath (opts, filePath) {
return false
}

/***
* Helper function to facilitate whether to consider traversing a potential archive.
* @function
* @param {Object} opts - Options.
* @param {string} humanReadableFilePath - The file path to check whether to include for traversal.
* @returns {boolean} Whether to consider the potential archive for traversal.
*/
function shouldConsiderTraversingArchive (opts, humanReadableFilePath) {
console.log(opts['traverse-archives'])
if (opts['traverse-archives']) {
if (opts['traverse-archives'] === true) return true
return opts['traverse-archives'].some(function (include) {
if (typeof include === 'function') {
return include(humanReadableFilePath)
}
return humanReadableFilePath.match(include)
})
}
return false
}

/**
* Sign a zip-like archive child component of the app bundle.
* This piece of automation helps to traverse zip-like archives and sign any enclosing binary files. See #229.
Expand Down Expand Up @@ -224,7 +249,7 @@ function signChildComponentAsync (opts, args, filePath, humanReadableFilePath =
}

var promise
if (opts['traverse-archives']) {
if (shouldConsiderTraversingArchive(opts, humanReadableFilePath)) {
// Sign the child components if the file is an archive
promise = isZipFileAsync(filePath)
.then(function (archive) {
Expand Down

0 comments on commit 942acd3

Please sign in to comment.