2019-11-26 18:24:43 +03:00
|
|
|
const { exec, execFile } = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const shellescape = require('shell-escape');
|
|
|
|
|
|
|
|
exports.default = async function(options) {
|
|
|
|
const inPath = options.path;
|
|
|
|
const appOutDir = path.dirname(inPath);
|
|
|
|
|
|
|
|
// get the token passphrase from the keychain
|
2020-02-26 14:54:20 +03:00
|
|
|
let tokenPassphrase;
|
|
|
|
try {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(
|
|
|
|
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" +
|
|
|
|
"! Skipping Windows signing. !\n" +
|
|
|
|
"! Signing token not found in keychain. !\n" +
|
|
|
|
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
2019-11-26 18:24:43 +03:00
|
|
|
);
|
2020-02-26 14:54:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-11-26 18:24:43 +03:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let cmdLine = 'osslsigncode sign ';
|
|
|
|
if (process.env.OSSLSIGNCODE_SIGNARGS) {
|
|
|
|
cmdLine += process.env.OSSLSIGNCODE_SIGNARGS + ' ';
|
|
|
|
}
|
|
|
|
const tmpFile = path.join(
|
|
|
|
appOutDir,
|
|
|
|
'tmp_' + Math.random().toString(36).substring(2, 15) + '.exe',
|
|
|
|
);
|
|
|
|
const args = [
|
2019-11-27 14:54:33 +03:00
|
|
|
'-h', options.hash,
|
2019-11-26 18:24:43 +03:00
|
|
|
'-pass', tokenPassphrase,
|
|
|
|
'-in', inPath,
|
|
|
|
'-out', tmpFile,
|
|
|
|
];
|
|
|
|
if (options.isNest) args.push('-nest');
|
|
|
|
cmdLine += shellescape(args);
|
|
|
|
|
2019-11-27 15:22:51 +03:00
|
|
|
let signStdout;
|
2019-11-26 18:24:43 +03:00
|
|
|
const signproc = exec(cmdLine, {}, (error, stdout) => {
|
2019-11-27 15:22:51 +03:00
|
|
|
signStdout = stdout;
|
2019-11-26 18:24:43 +03:00
|
|
|
});
|
|
|
|
signproc.on('exit', (code) => {
|
|
|
|
if (code !== 0) {
|
2019-11-27 15:22:51 +03:00
|
|
|
console.log("Running", cmdLine);
|
|
|
|
console.log(signStdout);
|
2019-11-26 18:24:43 +03:00
|
|
|
console.error("osslsigncode failed with code " + code);
|
|
|
|
reject("osslsigncode failed with code " + code);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fs.rename(tmpFile, inPath, (err) => {
|
|
|
|
if (err) {
|
|
|
|
console.error("Error renaming file", err);
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|