Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
afterAllArtifactBuild: () => {
if (process.platform !== 'win32') {
return [];
}
// Create .appxbundle for backward compability
// http://www.jonathanantoine.com/2016/04/12/windows-app-bundles-and-the-subsequent-submissions-must-continue-to-contain-a-windows-phone-8-1-appxbundle-error-message/
// https://docs.microsoft.com/en-us/windows/msix/package/create-app-package-with-makeappx-tool
// https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/src/targets/AppxTarget.ts
const appxBundlePath = path.join('dist', `Translatium ${appVersion}.appxbundle`);
const appxPath = path.join(__dirname, 'dist', `Translatium ${appVersion}.appx`);
const bundleDirPath = path.join(__dirname, 'dist', 'appx_bundle');
const appxDestPath = path.join(bundleDirPath, 'Translatium.appx');
return getSignVendorPath()
.then((vendorPath) => {
console.log(`Creating ${appxBundlePath}...`);
fs.ensureDirSync(bundleDirPath);
fs.copyFileSync(appxPath, appxDestPath);
return new Promise((resolve) => {
const makeAppxPath = path.join(vendorPath, 'windows-10', 'x64', 'makeappx.exe');
runCmd(makeAppxPath, ['bundle', '/p', appxBundlePath, '/d', bundleDirPath, '/o'], (text) => {
console.log(text);
resolve();
});
})
.then(() => {
console.log(`Created ${appxBundlePath} successfully`);
return [appxBundlePath];
});
});
export async function createSelfSignedCert(publisher: string) {
const tmpDir = new TmpDir("create-self-signed-cert")
const targetDir = process.cwd()
const tempPrefix = path.join(await tmpDir.getTempDir({prefix: "self-signed-cert-creator"}), sanitizeFileName(publisher))
const cer = `${tempPrefix}.cer`
const pvk = `${tempPrefix}.pvk`
log.info(chalk.bold('When asked to enter a password ("Create Private Key Password"), please select "None".'))
try {
await ensureDir(path.dirname(tempPrefix))
const vendorPath = path.join(await getSignVendorPath(), "windows-10", process.arch)
await exec(path.join(vendorPath, "makecert.exe"),
["-r", "-h", "0", "-n", `CN=${quoteString(publisher)}`, "-eku", "1.3.6.1.5.5.7.3.3", "-pe", "-sv", pvk, cer])
const pfx = path.join(targetDir, `${sanitizeFileName(publisher)}.pfx`)
await unlinkIfExists(pfx)
await exec(path.join(vendorPath, "pvk2pfx.exe"), ["-pvk", pvk, "-spc", cer, "-pfx", pfx])
log.info({file: pfx}, `created. Please see https://electron.build/code-signing how to use it to sign.`)
const certLocation = "Cert:\\LocalMachine\\TrustedPeople"
log.info({file: pfx, certLocation}, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`)
await spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", ""])
}
finally {
await tmpDir.cleanup()
}
}