2019-10-09 15:29:24 +00:00
|
|
|
const { notarize } = require('electron-notarize');
|
2019-10-11 11:01:50 +00:00
|
|
|
const { exec, execFile } = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
const shellescape = require('shell-escape');
|
2019-10-09 15:29:24 +00:00
|
|
|
|
|
|
|
exports.default = async function(context) {
|
2019-10-09 15:40:31 +00:00
|
|
|
const { electronPlatformName, appOutDir } = context;
|
2019-10-09 15:29:24 +00:00
|
|
|
|
2019-10-11 11:01:50 +00:00
|
|
|
if (electronPlatformName === 'darwin') {
|
|
|
|
const appName = context.packager.appInfo.productFilename;
|
|
|
|
// We get the password from keychain. The keychain stores
|
|
|
|
// user IDs too, but apparently altool can't get the user ID
|
|
|
|
// from the keychain, so we need to get it from the environment.
|
|
|
|
const userId = process.env.NOTARIZE_APPLE_ID;
|
|
|
|
if (userId === undefined) {
|
2019-11-19 15:55:03 +00:00
|
|
|
throw new Error("User ID not found. Set NOTARIZE_APPLE_ID.");
|
2019-10-11 11:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Notarising macOS app. This may be some time.");
|
|
|
|
return await notarize({
|
|
|
|
appBundleId: 'im.riot.app',
|
|
|
|
appPath: `${appOutDir}/${appName}.app`,
|
|
|
|
appleId: userId,
|
|
|
|
appleIdPassword: '@keychain:NOTARIZE_CREDS',
|
|
|
|
});
|
|
|
|
} else if (electronPlatformName === 'win32') {
|
|
|
|
// This signs the actual Riot executable
|
|
|
|
const appName = context.packager.appInfo.productFilename;
|
2019-10-09 15:40:31 +00:00
|
|
|
|
2019-10-11 11:01:50 +00:00
|
|
|
// get the token passphrase from the keychain
|
|
|
|
const tokenPassphrase = await new Promise((resolve, reject) => {
|
|
|
|
execFile(
|
|
|
|
'security',
|
|
|
|
['find-generic-password', '-s', 'riot_signing_token', '-w'],
|
|
|
|
{},
|
|
|
|
(err, stdout) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve(stdout.trim());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2019-10-09 15:40:31 +00:00
|
|
|
|
2019-10-11 11:01:50 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let cmdLine = 'osslsigncode sign ';
|
|
|
|
if (process.env.OSSLSIGNCODE_SIGNARGS) {
|
2019-10-11 11:21:28 +00:00
|
|
|
cmdLine += process.env.OSSLSIGNCODE_SIGNARGS + ' ';
|
2019-10-11 11:01:50 +00:00
|
|
|
}
|
|
|
|
const tmpFile = 'tmp_' + Math.random().toString(36).substring(2, 15) + '.exe';
|
|
|
|
cmdLine += shellescape([
|
|
|
|
'-pass', tokenPassphrase,
|
|
|
|
'-in', `${appOutDir}/${appName}.exe`,
|
|
|
|
'-out', `${appOutDir}/${tmpFile}`,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const signproc = exec(cmdLine, {}, (error, stdout) => {
|
|
|
|
console.log(stdout);
|
|
|
|
});
|
|
|
|
signproc.on('exit', (code) => {
|
|
|
|
if (code !== 0) {
|
|
|
|
reject("osslsigncode failed with code " + code);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fs.rename(`${appOutDir}/${tmpFile}`, `${appOutDir}/${appName}.exe`, (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2019-10-09 15:29:24 +00:00
|
|
|
};
|