Skip to content

Commit a84de0b

Browse files
committed
Sign all of the Windows executable files
We can actually just supply a custom signing module here to do our signing rather than manually signing things in the afterSign hook. This means all 4 executable files get signed (the main exe, the stub exe, Update.exe and the installer).
1 parent caeae69 commit a84de0b

3 files changed

Lines changed: 68 additions & 53 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@
185185
"win": {
186186
"target": {
187187
"target": "squirrel"
188-
}
188+
},
189+
"sign": "scripts/electron_winSign"
189190
},
190191
"directories": {
191192
"buildResources": "electron_app/build",

‎scripts/electron_afterSign.js‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
const { notarize } = require('electron-notarize');
2-
const { exec, execFile } = require('child_process');
3-
const fs = require('fs');
4-
const shellescape = require('shell-escape');
52

63
exports.default = async function(context) {
74
const { electronPlatformName, appOutDir } = context;
@@ -23,54 +20,5 @@ exports.default = async function(context) {
2320
appleId: userId,
2421
appleIdPassword: '@keychain:NOTARIZE_CREDS',
2522
});
26-
} else if (electronPlatformName === 'win32') {
27-
// This signs the actual Riot executable
28-
const appName = context.packager.appInfo.productFilename;
29-
30-
// get the token passphrase from the keychain
31-
const tokenPassphrase = await new Promise((resolve, reject) => {
32-
execFile(
33-
'security',
34-
['find-generic-password', '-s', 'riot_signing_token', '-w'],
35-
{},
36-
(err, stdout) => {
37-
if (err) {
38-
reject(err);
39-
} else {
40-
resolve(stdout.trim());
41-
}
42-
},
43-
);
44-
});
45-
46-
return new Promise((resolve, reject) => {
47-
let cmdLine = 'osslsigncode sign ';
48-
if (process.env.OSSLSIGNCODE_SIGNARGS) {
49-
cmdLine += process.env.OSSLSIGNCODE_SIGNARGS + ' ';
50-
}
51-
const tmpFile = 'tmp_' + Math.random().toString(36).substring(2, 15) + '.exe';
52-
cmdLine += shellescape([
53-
'-pass', tokenPassphrase,
54-
'-in', `${appOutDir}/${appName}.exe`,
55-
'-out', `${appOutDir}/${tmpFile}`,
56-
]);
57-
58-
const signproc = exec(cmdLine, {}, (error, stdout) => {
59-
console.log(stdout);
60-
});
61-
signproc.on('exit', (code) => {
62-
if (code !== 0) {
63-
reject("osslsigncode failed with code " + code);
64-
return;
65-
}
66-
fs.rename(`${appOutDir}/${tmpFile}`, `${appOutDir}/${appName}.exe`, (err) => {
67-
if (err) {
68-
reject(err);
69-
} else {
70-
resolve();
71-
}
72-
});
73-
});
74-
});
7523
}
7624
};

‎scripts/electron_winSign.js‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const { exec, execFile } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const shellescape = require('shell-escape');
5+
6+
exports.default = async function(options) {
7+
const inPath = options.path;
8+
const appOutDir = path.dirname(inPath);
9+
10+
// get the token passphrase from the keychain
11+
const tokenPassphrase = await new Promise((resolve, reject) => {
12+
execFile(
13+
'security',
14+
['find-generic-password', '-s', 'riot_signing_token', '-w'],
15+
{},
16+
(err, stdout) => {
17+
if (err) {
18+
console.error("Couldn't find signing token in keychain", err);
19+
// electron-builder seems to print '[object Object]' on the
20+
// console whether you reject with an Error or a string...
21+
reject(err);
22+
} else {
23+
resolve(stdout.trim());
24+
}
25+
},
26+
);
27+
});
28+
29+
return new Promise((resolve, reject) => {
30+
let cmdLine = 'osslsigncode sign ';
31+
if (process.env.OSSLSIGNCODE_SIGNARGS) {
32+
cmdLine += process.env.OSSLSIGNCODE_SIGNARGS + ' ';
33+
}
34+
const tmpFile = path.join(
35+
appOutDir,
36+
'tmp_' + Math.random().toString(36).substring(2, 15) + '.exe',
37+
);
38+
const args = [
39+
'-hash', options.hash,
40+
'-pass', tokenPassphrase,
41+
'-in', inPath,
42+
'-out', tmpFile,
43+
];
44+
if (options.isNest) args.push('-nest');
45+
cmdLine += shellescape(args);
46+
47+
const signproc = exec(cmdLine, {}, (error, stdout) => {
48+
console.log(stdout);
49+
});
50+
signproc.on('exit', (code) => {
51+
if (code !== 0) {
52+
console.error("osslsigncode failed with code " + code);
53+
reject("osslsigncode failed with code " + code);
54+
return;
55+
}
56+
fs.rename(tmpFile, inPath, (err) => {
57+
if (err) {
58+
console.error("Error renaming file", err);
59+
reject(err);
60+
} else {
61+
resolve();
62+
}
63+
});
64+
});
65+
});
66+
};

0 commit comments

Comments
 (0)