Skip to content

Commit fd26e63

Browse files
committed
Merge pull request #24 from 10gen/kangas-sign-electron
fix(electron): delegate 'sign' to darwin-sign-app.sh
2 parents f95d63a + 7272893 commit fd26e63

File tree

2 files changed

+82
-16
lines changed

2 files changed

+82
-16
lines changed

scout-electron/darwin-sign-app.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
#
3+
# Use Apple's codesign(1) utility to ensure that users can run Scout immediately after downloading
4+
#
5+
# References:
6+
# man 1 codesign
7+
# https://developer.apple.com/library/mac/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html
8+
# https://developer.apple.com/library/mac/technotes/tn2206/_index.html
9+
#
10+
# TODO: replace with native gulp tasks
11+
# TODO: consider using productbuild(1) to build a .pkg. It takes care of invoking codesign
12+
#
13+
14+
set -o errexit
15+
16+
if [ "$#" -ne "2" ]
17+
then
18+
echo "Usage: darwin-sign-app.sh <identity> <path to .app>"
19+
exit 1
20+
fi
21+
22+
# Assume two arguments; identity, path-to-app
23+
IDENTITY="${1}"
24+
APP_PATH="${2}"
25+
26+
test -d ${APP_PATH}
27+
28+
# IDENTITY is the SHA-1 signature of a Code Signing Identity obtained from Apple
29+
# which must be accessible via the user/system keychain
30+
31+
(
32+
cd $(dirname "${APP_PATH}")
33+
APP=$(basename "${APP_PATH}")
34+
35+
# Clean up ".cstemp" files from previous attempts
36+
find "${APP}" -name \*.cstemp -type f -delete
37+
38+
for FRAMEWORK in "${APP}"/Contents/Frameworks/*
39+
do
40+
echo "• Signing framework: $FRAMEWORK"
41+
codesign -s ${IDENTITY} -vvv --deep --force "$FRAMEWORK"
42+
done
43+
44+
echo "• Signing executable"
45+
codesign -s ${IDENTITY} -vvv --force "${APP}/Contents/MacOS/Scout"
46+
47+
echo "• Signing app bundle"
48+
codesign -s ${IDENTITY} --deep -vvv --force "${APP}"
49+
50+
echo
51+
echo "• Verify"
52+
codesign --verify -vvv "${APP}"
53+
)

scout-electron/gulpfile.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,29 +206,42 @@ gulp.task('build', [
206206
]);
207207

208208
// https://github.com/atom/electron-starter/blob/master/build/tasks/codesign-task.coffee
209-
function unlockKeychain(done) {
210-
var cmd = util.format('security unlock-keychain -p %s',
211-
process.env.XCODE_KEYCHAIN_PASSWORD, process.env.XCODE_KEYCHAIN);
212-
proc.exec(cmd, done);
213-
}
214-
function signApp(done) {
215-
if (PLATFORM === 'darwin') {
216-
var cmd = util.format('codesign --deep --force --verbose --sign %s %s',
217-
process.env.XCODE_SIGNING_IDENTITY, APP);
209+
function unlockKeychainDarwin(done) {
210+
if (process.env.XCODE_KEYCHAIN_PASSWORD) {
211+
var cmd = util.format('security unlock-keychain -p %s',
212+
process.env.XCODE_KEYCHAIN_PASSWORD, process.env.XCODE_KEYCHAIN);
218213
proc.exec(cmd, done);
219214
} else {
220215
done();
221216
}
222217
}
223-
gulp.task('sign', function(done) {
224-
if (process.platform() === 'darwin' && process.env.XCODE_KEYCHAIN) {
225-
unlockKeychain(function(err) {
226-
if (err) return done(err);
227-
signApp(done);
228-
});
218+
function signAppDarwin(done) {
219+
if (process.env.XCODE_SIGNING_IDENTITY) {
220+
// var cmd = util.format('codesign --deep --force --verbose --sign %s %s',
221+
// process.env.XCODE_SIGNING_IDENTITY, APP);
222+
223+
// Use a shell script until we rewrite it in gulp
224+
var logData = function(data) {
225+
console.log((''+ data).trim());
226+
};
227+
228+
var script = proc.spawn("./darwin-sign-app.sh",
229+
[process.env.XCODE_SIGNING_IDENTITY, APP]);
230+
script.stdout.on('data', logData);
231+
script.stderr.on('data', logData);
232+
script.on('close', done);
229233
} else {
230-
return done();
234+
done(new Error("process.env.XCODE_SIGNING_IDENTITY not specified"));
231235
}
236+
}
237+
gulp.task('sign', function(done) {
238+
if (PLATFORM !== 'darwin') {
239+
done(new Error("sign only implemented for OS X"));
240+
}
241+
unlockKeychainDarwin(function(err) {
242+
if (err) return done(err);
243+
signAppDarwin(done);
244+
});
232245
});
233246

234247
// gulp.task('get mongo', function(cb) {

0 commit comments

Comments
 (0)