Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-osx-sign

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-osx-sign - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

165

index.js

@@ -55,16 +55,25 @@ var fs = require('fs')

function signDarwinApplication (opts, callback) {
function signApplication (opts, callback) {
var operations = []
var appFrameworksPath = generateAppFrameworksPath(opts)
var childPaths = [
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
path.join(appFrameworksPath, 'Electron Framework.framework'),
path.join(appFrameworksPath, 'Mantle.framework', 'Versions', 'A', 'Mantle'),
path.join(appFrameworksPath, 'Mantle.framework'),
path.join(appFrameworksPath, 'ReactiveCocoa.framework', 'Versions', 'A', 'ReactiveCocoa'),
path.join(appFrameworksPath, 'ReactiveCocoa.framework'),
path.join(appFrameworksPath, 'Squirrel.framework', 'Versions', 'A', 'Squirrel'),
path.join(appFrameworksPath, 'Squirrel.framework')
]
var childPaths
if (opts.platform === 'mas') {
childPaths = [
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
path.join(appFrameworksPath, 'Electron Framework.framework')
]
} else if (opts.platform === 'darwin') {
childPaths = [
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
path.join(appFrameworksPath, 'Electron Framework.framework'),
path.join(appFrameworksPath, 'Mantle.framework', 'Versions', 'A', 'Mantle'),
path.join(appFrameworksPath, 'Mantle.framework'),
path.join(appFrameworksPath, 'ReactiveCocoa.framework', 'Versions', 'A', 'ReactiveCocoa'),
path.join(appFrameworksPath, 'ReactiveCocoa.framework'),
path.join(appFrameworksPath, 'Squirrel.framework', 'Versions', 'A', 'Squirrel'),
path.join(appFrameworksPath, 'Squirrel.framework')
]
}
var helperPath = generateHelperAppPath(opts, 'helper-path', null, callback)

@@ -92,4 +101,21 @@ if (helperPath) {

if (opts.entitlements) {
// TODO: Signing darwin builds with entitlements
return callback(new Error('Entitlements not yet supported for darwin.'))
if (opts.platform === 'mas') {
// Sign with entitlements
childPaths.forEach(function (path) {
operations.push(function (cb) {
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
+ '--entitlements "' + opts['entitlements-inherit'] + '" \ '
+ '"' + path + '"'
, cb)
})
})
operations.push(function (cb) {
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
+ '--entitlements "' + opts.entitlements + '" \ '
+ '"' + opts.app + '"'
, cb)
})
} else if (opts.platform === 'darwin') {
// TODO: Signing darwin builds with entitlements
}
} else {

@@ -110,2 +136,3 @@ // Otherwise normally

}
// Lastly verify codesign

@@ -117,68 +144,14 @@ operations.push(function (cb) {

})
series(operations, function (err) {
if (err) return callback(err)
callback()
})
}
function signMASApplication (opts, callback) {
var operations = []
var appFrameworksPath = generateAppFrameworksPath(opts)
var childPaths = [
path.join(appFrameworksPath, 'Electron Framework.framework', 'Versions', 'A', 'Electron Framework'),
path.join(appFrameworksPath, 'Electron Framework.framework')
]
var helperPath = generateHelperAppPath(opts, 'helper-path', null, callback)
if (helperPath) {
var helperExecutablePath = generateHelperAppExecutablePath(opts, helperPath, null, callback)
if (helperExecutablePath) childPaths.unshift(helperExecutablePath, helperPath)
else return callback(new Error('Missing Electron Helper, stopped.'))
}
var helperEHPath = generateHelperAppPath(opts, 'helper-eh-path', ' EH', callback)
if (helperEHPath) {
var helperEHExecutablePath = generateHelperAppExecutablePath(opts, helperEHPath, ' EH', callback)
if (helperEHExecutablePath) childPaths.unshift(helperEHExecutablePath, helperEHPath)
else return callback(new Error('Missing Electron Helper EH, stopped.'))
}
var helperNPPath = generateHelperAppPath(opts, 'helper-np-path', ' NP', callback)
if (helperNPPath) {
var helperNPExecutablePath = generateHelperAppExecutablePath(opts, helperNPPath, ' NP', callback)
if (helperNPExecutablePath) childPaths.unshift(helperNPExecutablePath, helperNPPath)
else return callback(new Error('Missing Electron Helper NP, stopped.'))
}
// Sign with entitlements
childPaths.forEach(function (path) {
if (opts.entitlements) {
// Check entitlements
operations.push(function (cb) {
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
+ '--entitlements "' + opts['entitlements-inherit'] + '" \ '
+ '"' + path + '"'
, cb)
child.exec('codesign -d --entitlements - \ '
+ '"' + opts.app + '"'
, function (err, stdout, stderr) {
if (err) return cb(err)
if (!stdout) return cb(new Error('Entitlements failed to be signed.'))
cb()
})
})
})
operations.push(function (cb) {
child.exec('codesign -f -s "' + opts.identity + '" -fv \ '
+ '--entitlements "' + opts.entitlements + '" \ '
+ '"' + opts.app + '"'
, cb)
})
// Lastly verify codesign
operations.push(function (cb) {
child.exec('codesign -v --verbose=4 \ '
+ '"' + opts.app + '"'
, cb)
})
// And check entitlements
operations.push(function (cb) {
child.exec('codesign -d --entitlements - \ '
+ '"' + opts.app + '"'
, function (err, stdout, stderr) {
if (err) return cb(err)
if (!stdout) return cb(new Error('Entitlements failed to be signed.'))
cb()
})
})
}
series(operations, function (err) {

@@ -191,10 +164,20 @@ if (err) return callback(err)

module.exports = function sign (app, opts, cb) {
if (!opts) opts = {}
opts.app = app
if (!opts) opts = {app: app}
if (!cb) cb = function () {}
if (!opts.app) return cb(new Error('Path to aplication must be specified.'))
if (!fs.existsSync(opts.app)) return cb(new Error('Application not found.'))
if (!opts.platform || opts.platform === 'darwin') {
opts.platform = 'darwin' // fallback to darwin if no platform specified
} else if (opts.platform === 'mas') {
// Match platform if none is provided
if (!opts.platform) {
var appFrameworksPath = generateAppFrameworksPath(opts)
if (!fs.existsSync(path.join(appFrameworksPath, 'Mantle.framework'))
&& !fs.existsSync(path.join(appFrameworksPath, 'ReactiveCocoa.framework'))
&& !fs.existsSync(path.join(appFrameworksPath, 'Squirrel.framework'))) {
// These frameworks do not exist in an Mac App Store version
opts.platform = 'mas'
} else {
opts.platform = 'darwin'
}
}
if (opts.platform === 'mas') {
// To sign apps for Mac App Store, an entitlements file is required,

@@ -208,2 +191,5 @@ // especially for app sandboxing (as well some other services).

if (!opts['entitlements-inherit']) opts['entitlements-inherit'] = path.join(__dirname, 'mas.inherit.default.plist')
} else if (opts.platform === 'darwin') {
// Not necessary to have entitlements for non Mac App Store distribution
if (opts.entitlements) return cb(new Error('Unable to sign for darwin platform with entitlements.'))
} else {

@@ -214,2 +200,3 @@ return cb(new Error('Only platform darwin and mas are supported.'))

function (cb) {
// Checking identity with series for async execution of child process
if (!opts.identity) {

@@ -222,4 +209,4 @@ child.exec('security find-identity', function (err, stdout, stderr) {

var line = lines[i]
if (opts.platform === 'darwin') {
location = line.indexOf('Developer ID Application')
if (opts.platform === 'mas') {
location = line.indexOf('3rd Party Mac Developer Application')
if (location >= 0) {

@@ -229,4 +216,4 @@ opts.identity = line.substring(location, line.length - 1)

}
} else if (opts.platform === 'mas') {
location = line.indexOf('3rd Party Mac Developer Application')
} else if (opts.platform === 'darwin') {
location = line.indexOf('Developer ID Application')
if (location >= 0) {

@@ -245,8 +232,4 @@ opts.identity = line.substring(location, line.length - 1)

if (err) return cb(err)
if (opts.platform === 'darwin') {
return signDarwinApplication(opts, cb)
} else if (opts.platform === 'mas') {
return signMASApplication(opts, cb)
}
return signApplication(opts, cb)
})
}
{
"name": "electron-osx-sign",
"version": "0.1.0",
"version": "0.1.1",
"description": "Codesign for Electron-packed apps",

@@ -5,0 +5,0 @@ "main": "index.js",

# electron-osx-sign
Code signing for Electron-packed OS X apps
Code signing for Electron-packed OS X apps [![npm][npm_img]][npm_url]

@@ -8,6 +8,8 @@ ## Installation

```sh
# for use in npm scripts
# For use in npm scripts
npm install electron-osx-sign --save-dev
```
# for use from cli
```sh
# For use from cli
npm install electron-osx-sign -g

@@ -21,6 +23,6 @@ ```

```sh
electron-sign <app> [optional flags...]
electron-osx-sign <app> [optional flags...]
```
For details on the optional flags, run `electron-sign --help` or see [usage.txt](https://github.com/sethlu/electron-sign/blob/master/usage.txt).
For details on the optional flags, run `electron-osx-sign --help` or see [usage.txt](https://github.com/sethlu/electron-sign/blob/master/usage.txt).

@@ -51,3 +53,3 @@ ### Programmatic API

Path to child entitlements file for signing frameworks and bundles of Mac App Store application.
Path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. *This option only applies when signing with `entitlements` provided, or for a `mas` platform version.*
See [mas.inherit.default.plist](https://github.com/sethlu/electron-sign/blob/master/mas.inherit.default.plist) for default.

@@ -58,2 +60,3 @@

Path to `Electron Helper.app`, which may be renamed.
Default to detect from application package.

@@ -63,2 +66,3 @@ `helper-eh-path` - *String*

Path to `Electron Helper EH.app`, which may be renamed.
Default to detect from application package.

@@ -68,2 +72,3 @@ `helper-np-path` - *String*

Path to `Electron Helper NP.app`, which may be renamed.
Default to detect from application package.

@@ -77,7 +82,9 @@ *Note: `helper-path`, `helper-eh-path`, `helper-np-path` needn't provided unless error thrown for not able to find any of them automatically.*

Signing platform `mas` will look for `3rd Party Mac Developer Application: * <*>`, and platform `darwin` will look for `Developer ID Application: * <*>` by default.
`platform` - *String*
Build platform of Electron.
Allowed values: *darwin, mas*
Default: *darwin*
Allowed values: `darwin`, `mas`.
Default to auto detect from presence of `Mantle.framework`, `ReactiveCocoa.framework`, and `Squirrel.framework` within the application package.

@@ -100,4 +107,60 @@ ##### callback

A successful testing should look something like:
```
$ npm test
> electron-sign@0.1.1 test electron-osx-sign
> standard && tape test
Calling electron-download before running tests...
Running tests...
TAP version 13
# setup
# defaults-test:v0.24.0-darwin-x64
ok 1 app signed
# defaults-test:v0.25.0-darwin-x64
ok 2 app signed
# defaults-test:v0.26.0-darwin-x64
ok 3 app signed
# defaults-test:v0.27.0-darwin-x64
ok 4 app signed
# defaults-test:v0.28.0-darwin-x64
ok 5 app signed
# defaults-test:v0.29.0-darwin-x64
ok 6 app signed
# defaults-test:v0.30.0-darwin-x64
ok 7 app signed
# defaults-test:v0.31.0-darwin-x64
ok 8 app signed
# defaults-test:v0.32.0-darwin-x64
ok 9 app signed
# defaults-test:v0.33.0-darwin-x64
ok 10 app signed
# defaults-test:v0.34.0-darwin-x64
ok 11 app signed
# defaults-test:v0.34.0-mas-x64
ok 12 app signed
# defaults-test:v0.35.0-darwin-x64
ok 13 app signed
# defaults-test:v0.35.0-mas-x64
ok 14 app signed
# defaults-test:v0.36.0-darwin-x64
ok 15 app signed
# defaults-test:v0.36.0-mas-x64
ok 16 app signed
# teardown
1..16
# tests 16
# pass 16
# ok
```
## Related
- [electron-packager](https://github.com/maxogden/electron-packager) - package your electron app in OS executables (.app, .exe, etc) via JS or CLI
[npm_img]: https://img.shields.io/npm/v/electron-osx-sign.svg
[npm_url]: https://npmjs.org/package/electron-osx-sign

@@ -13,3 +13,3 @@ var sign = require('..')

var app = util.generateAppPath(release)
var opts = Object.create(release)
var opts = null // test with no options

@@ -16,0 +16,0 @@ waterfall([

@@ -12,2 +12,2 @@

identity Name of certificate to use when signing. Default to retrieve from `login.keychain`.
platform Build platform of Electron. Allowed values: darwin, mas. Default darwin.
platform Build platform of Electron. Allowed values: darwin, mas. Default to auto detect from application package.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc