Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to configure library to work with EV certificate #170

Open
kkaimtl opened this issue Sep 20, 2023 · 0 comments
Open

Unable to configure library to work with EV certificate #170

kkaimtl opened this issue Sep 20, 2023 · 0 comments

Comments

@kkaimtl
Copy link

kkaimtl commented Sep 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant