-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Failing to sign the Windows build on Linux
Closes #578
- Loading branch information
Showing
13 changed files
with
178 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
dir=${PWD##*/} | ||
rm -rf ../${dir}.7z | ||
7za a -m0=lzma2 -mx=9 -mfb=64 -md=64m -ms=on ../winCodeSign.7z . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { spawn } from "./util/util" | ||
import { rename } from "fs-extra-p" | ||
import * as path from "path" | ||
import { release } from "os" | ||
import { getBin } from "./util/binDownload" | ||
//noinspection JSUnusedLocalSymbols | ||
const __awaiter = require("./util/awaiter") | ||
|
||
const TOOLS_VERSION = "winCodeSign-1.0.0" | ||
|
||
export interface SignOptions { | ||
path: string | ||
cert: string | ||
name?: string | null | ||
password: string | ||
site?: string | null | ||
hash?: Array<string> | null | ||
} | ||
|
||
export async function sign(options: SignOptions) { | ||
let hashes = options.hash | ||
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) | ||
await spawnSign(options, options.path, outputPath, hash, nest) | ||
nest = true | ||
if (!isWin) { | ||
await rename(outputPath, options.path) | ||
} | ||
} | ||
} | ||
|
||
// on windows be aware of http://stackoverflow.com/a/32640183/1910191 | ||
async function spawnSign(options: any, inputPath: string, outputPath: string, hash: string, nest: boolean) { | ||
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" ? "http://timestamp.comodoca.com/rfc3161" : timestampingServiceUrl | ||
] : [ | ||
"-in", inputPath, | ||
"-out", outputPath, | ||
"-t", timestampingServiceUrl | ||
] | ||
|
||
const certExtension = path.extname(options.cert) | ||
if (certExtension === ".p12" || certExtension === ".pfx") { | ||
args.push(isWin ? "/f" : "-pkcs12", options.cert) | ||
} | ||
else { | ||
args.push(isWin ? "/f" : "-certs", options.cert) | ||
// todo win maybe incorrect | ||
args.push(isWin ? "/csp" : "-key", options.key) | ||
} | ||
|
||
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) | ||
} | ||
|
||
if (nest) { | ||
args.push(isWin ? "/as" : "-nest") | ||
} | ||
|
||
if (options.password) { | ||
args.push(isWin ? "/p" : "-pass", options.password) | ||
} | ||
|
||
if (options.passwordPath) { | ||
if (isWin) { | ||
throw new Error("-readpass is not supported on Windows") | ||
} | ||
args.push("-readpass", options.passwordPath) | ||
} | ||
|
||
if (isWin) { | ||
// must be last argument | ||
args.push(inputPath) | ||
} | ||
|
||
return await spawn(await getToolPath(options), args, { | ||
stdio: ["ignore", "ignore", "inherit"], | ||
}) | ||
} | ||
|
||
// 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") | ||
// } | ||
// } | ||
|
||
function getOutputPath(inputPath: string, hash: string) { | ||
const extension = path.extname(inputPath) | ||
return path.join(path.dirname(inputPath), `${path.basename(inputPath, extension)}-signed-${hash}${extension}`) | ||
} | ||
|
||
async function getToolPath(options: any) { | ||
let result = options.signcodePath || process.env.SIGNTOOL_PATH | ||
if (result) { | ||
return result | ||
} | ||
|
||
if (process.env.USE_SYSTEM_SIGNCODE || process.platform === "linux") { | ||
return "osslsigncode" | ||
} | ||
|
||
const vendorPath = await getBin("winCodeSign", TOOLS_VERSION, `https://dl.bintray.com/electron-userland/bin/${TOOLS_VERSION}.7z`, "0e524943dd6f03a9cee4cdaaa235e27d4945a1c9dc80ccee8ff1219e7b73ad88") | ||
if (process.platform === "win32") { | ||
return path.join(vendorPath, `windows-${(release().startsWith("6.") ? "6" : "10")}`, "signtool.exe") | ||
} | ||
else { | ||
return path.join(vendorPath, process.platform, "osslsigncode") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ | |
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
] | ||
], | ||
"no-bitwise": false, | ||
"jsdoc-format": false | ||
} | ||
} |
Oops, something went wrong.