electron-builder
Version:
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box
179 lines (154 loc) • 6.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sign = undefined;
var _bluebirdLstC;
function _load_bluebirdLstC() {
return _bluebirdLstC = require("bluebird-lst-c");
}
let sign = exports.sign = (() => {
var _ref = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (options) {
let hashes = options.hash;
// msi does not support dual-signing
if ((_path || _load_path()).extname(options.path) === ".msi") {
hashes = [hashes != null && !(hashes.indexOf("sha1") !== -1) ? "sha256" : "sha1"];
} else {
if (hashes == null) {
hashes = ["sha1", "sha256"];
} else {
hashes = Array.isArray(hashes) ? hashes.slice() : [hashes];
}
}
const isWin = process.platform === "win32";
let nest = false;
//noinspection JSUnusedAssignment
let outputPath = "";
for (let hash of hashes) {
outputPath = isWin ? options.path : getOutputPath(options.path, hash);
yield spawnSign(options, options.path, outputPath, hash, nest);
nest = true;
if (!isWin) {
yield (0, (_fsExtraP || _load_fsExtraP()).rename)(outputPath, options.path);
}
}
});
return function sign(_x) {
return _ref.apply(this, arguments);
};
})();
// on windows be aware of http://stackoverflow.com/a/32640183/1910191
let spawnSign = (() => {
var _ref2 = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* (options, inputPath, outputPath, hash, nest) {
const timestampingServiceUrl = "http://timestamp.verisign.com/scripts/timstamp.dll";
const isWin = process.platform === "win32";
const args = isWin ? ["sign", nest || hash === "sha256" ? "/tr" : "/t", nest || hash === "sha256" ? options.tr || "http://timestamp.comodoca.com/rfc3161" : timestampingServiceUrl] : ["-in", inputPath, "-out", outputPath, "-t", timestampingServiceUrl];
const certificateFile = options.cert;
if (certificateFile == null) {
if (process.platform !== "win32") {
throw new Error("certificateSubjectName supported only on Windows");
}
args.push("/n", options.subjectName);
} else {
const certExtension = (_path || _load_path()).extname(certificateFile);
if (certExtension === ".p12" || certExtension === ".pfx") {
args.push(isWin ? "/f" : "-pkcs12", certificateFile);
} else {
throw new Error(`Please specify pkcs12 (.p12/.pfx) file, ${ certificateFile } is not correct`);
}
}
if (!isWin || hash !== "sha1") {
args.push(isWin ? "/fd" : "-h", hash);
if (isWin) {
args.push("/td", "sha256");
}
}
if (options.name) {
args.push(isWin ? "/d" : "-n", options.name);
}
if (options.site) {
args.push(isWin ? "/du" : "-i", options.site);
}
// msi does not support dual-signing
if (nest) {
args.push(isWin ? "/as" : "-nest");
}
if (options.password) {
args.push(isWin ? "/p" : "-pass", options.password);
}
if (isWin) {
// must be last argument
args.push(inputPath);
}
return yield (0, (_util || _load_util()).exec)((yield getToolPath()), args);
});
return function spawnSign(_x2, _x3, _x4, _x5, _x6) {
return _ref2.apply(this, arguments);
};
})();
// async function verify(options: any) {
// const out = await exec(await getToolPath(options), [
// "verify",
// "-in", options.path,
// "-require-leaf-hash", options.hash
// ])
// if (out.includes("No signature found.")) {
// throw new Error("No signature found")
// }
// else if (out.includes("Leaf hash match: failed")) {
// throw new Error("Leaf hash match failed")
// }
// }
let getToolPath = (() => {
var _ref3 = (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
if (process.env.USE_SYSTEM_SIGNCODE) {
return "osslsigncode";
}
let result = process.env.SIGNTOOL_PATH;
if (result) {
return result;
}
const vendorPath = yield getSignVendorPath();
if (process.platform === "win32") {
return (_path || _load_path()).join(vendorPath, `windows-${ (0, (_os || _load_os()).release)().startsWith("6.") ? "6" : "10" }`, "signtool.exe");
} else if (process.platform === "darwin" && process.env.CI) {
return (_path || _load_path()).join(vendorPath, process.platform, "ci", "osslsigncode");
} else {
return (_path || _load_path()).join(vendorPath, process.platform, "osslsigncode");
}
});
return function getToolPath() {
return _ref3.apply(this, arguments);
};
})();
//# sourceMappingURL=windowsCodeSign.js.map
exports.getSignVendorPath = getSignVendorPath;
var _util;
function _load_util() {
return _util = require("./util/util");
}
var _fsExtraP;
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
}
var _path;
function _load_path() {
return _path = _interopRequireWildcard(require("path"));
}
var _os;
function _load_os() {
return _os = require("os");
}
var _binDownload;
function _load_binDownload() {
return _binDownload = require("./util/binDownload");
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
const TOOLS_VERSION = "1.4.2";
function getSignVendorPath() {
return (0, (_binDownload || _load_binDownload()).getBinFromBintray)("winCodeSign", TOOLS_VERSION, "ca94097071ce6433a2e18a14518b905ac162afaef82ed88713a8a91c32a55b21");
}
function getOutputPath(inputPath, hash) {
const extension = (_path || _load_path()).extname(inputPath);
return (_path || _load_path()).join((_path || _load_path()).dirname(inputPath), `${ (_path || _load_path()).basename(inputPath, extension) }-signed-${ hash }${ extension }`);
}