jet2jet / resedit-js-cli

Node.js command line tool for editing Windows Resource data
MIT License
7 stars 0 forks source link

Using HSM for signing #12

Open maxpain opened 2 years ago

maxpain commented 2 years ago

Hello. Is it possible use HSM (for example Google Cloud KMS/HSM) for signing Windows executables?

jet2jet commented 2 years ago

No, currently resedit-js does not support any HSMs. I think it is good to support, but it may take some time to implement (also it may not be fully tested).

maxpain commented 2 years ago

I am looking for signing my electron application in GitLab CI with our EV certificate on Google Cloud KMS. I could use jsign, but it requires to build our own docker image with gcloud-sdk, jsign itself and electron-builder rather than using pure electron-builder image.

So it will be cool to use this npm module to do that right in the electron-builder config.

Can I implement HSM signing utilizing current API of this package?

jet2jet commented 2 years ago

Sounds good. If you use @google-cloud/kms, please set it as optional dependency because this feature would be an optional feature.

maxpain commented 2 years ago

So, can I implement HSM signing utilizing current API of this package? Honestly, I'm not very familiar with crypto stuff

jet2jet commented 2 years ago

It's OK. I think it's not so easy, but I think all we need is implement ResEdit.SignerObject, especially three methods: getEncryptionAlgorithm, getCertificateData, and encryptData (other methods would be the same implementations as MySignerObject: https://github.com/jet2jet/resedit-js-cli/blob/main/src/main/signing/index.ts#L20).

The asymmetric-sign sample may help you to understand and implement this: https://github.com/googleapis/nodejs-kms/blob/HEAD/samples/signAsymmetric.js
(More information about signature creation: https://cloud.google.com/kms/docs/create-validate-signatures )

maxpain commented 2 years ago

encryptData implementation would be to call asymmetric sign process as followings:

  • @google-cloud/kms package: client.asymmetricSign()

asymmetricSign just returns digital signature of provided payload, but encryptData method of ResEdit.SignerObject class must return whole encrypted payload, right? If so, ResEdit.SignerObject must let me provide some signData method.

jet2jet commented 2 years ago

Yes, you are right (I missed it). I'll work to add signData-like method to SignerObject.

jet2jet commented 2 years ago

I updated resedit package and resedit-js-cli repository.
Now signData method is to be used during signing process, so please implement signData method in SignerObject.

maxpain commented 2 years ago

Thank you! Will try it today.

maxpain commented 2 years ago

@jet2jet Is it possible to use returned value of digestData and pass it as an argument in signData?

jet2jet commented 2 years ago

Is it possible to use returned value of digestData and pass it as an argument in signData?

No. But for asymmetricSign, digest parameter should be the digest data calculated from the parameter dataIterator of signData.
Pseudo code would be:

  d = createDigest(algorithm);
  d.update(...dataIterator);
  digest = d.digest();
  asymmetricSign(digest := digest, ...<other parameters>);