electron-wix-msi icon indicating copy to clipboard operation
electron-wix-msi copied to clipboard

Unable to configure library to work with EV certificate

Open kkaimtl opened this issue 10 months ago • 0 comments

Hi! When configuring electron-wix-msi to work with EV certificate, there's a need to provide signtool parameters through signWithParams option. Sample signWithParams value that works for our token:

/f "${process.env.MSI_SIGNTOOL_CERT}" /csp "eToken Base Cryptographic Provider" /k "${process.env.MSI_SIGNTOOL_CONTAINER}" /fd sha256 /td sha256

Unfortunately, attached options doesn't work when used with your library (they are fine in cmd). This is because cmd.exe escapes leading/trailing quotes, where your library parses them as they are:

const signWithParams = '/f "cert.cer" /csp "eToken Base"'
signWithParams.match(/(?:[^\s"]+|"[^"]*")+/g) // evaluates to: ['/f', '"cert.cer"', '/csp', '"eToken Base"']

This causes signtool to not be able to find certificate (as it thinks quotes are part of the certificate file name) and later locate private key.

In order to fix this issue I'm proposing a simple patch that removes leading/trailing quotes when they are found:

diff --git a/node_modules/electron-wix-msi/lib/creator.js b/node_modules/electron-wix-msi/lib/creator.js
index 89d0e8e..ddde315 100644
--- a/node_modules/electron-wix-msi/lib/creator.js
+++ b/node_modules/electron-wix-msi/lib/creator.js
@@ -263,7 +263,7 @@ class MSICreator {
                 throw new Error('You must provide a certificatePassword with a certificateFile');
             }
             const args = signWithParams
-                ? signWithParams.match(/(?:[^\s"]+|"[^"]*")+/g)
+                ? signWithParams.match(/(?:[^\s"]+|"[^"]*")+/g).map(el => el.startsWith("\"") ? el.substring(1) : el).map(el => el.endsWith("\"") ? el.substring(0, el.length - 1) : el)
                 : ['/a', '/f', path.resolve(certificateFile), '/p', certificatePassword];
             const { code, stderr, stdout } = yield (0, spawn_1.spawnPromise)(signToolPath, ['sign', ...args, msiFile], {
                 env: process.env,

This issue body was partially generated by patch-package.

kkaimtl avatar Sep 20 '23 20:09 kkaimtl