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

Honour hash algo and set salt length when generating RSA-PSS key pairs #51

Open
gnarea opened this issue Apr 30, 2022 · 0 comments
Open
Assignees

Comments

@gnarea
Copy link

gnarea commented Apr 30, 2022

As shown in the snipped below, this library isn't currently honouring the hashing algorithm or setting a salt length when generating RSA-PSS keys, as it wasn't supported in older versions of Node.js:

const keys = crypto.generateKeyPairSync("rsa", {
modulusLength: algorithm.modulusLength,
publicExponent,
publicKeyEncoding: {
format: "der",
type: "spki",
},
privateKeyEncoding: {
format: "der",
type: "pkcs8",
},
});

I think this crypto.generateKeyPairSync() call should be changed to set the type to rsa-pss (only if using RSA-PSS) and add the following options if the current Node.js version is >= 16.10.0:

  • hashAlgorithm and mgf1HashAlgorithm: This value is already available in the context (algorithm.hash.name).
  • saltLength: Should match the length of the digest from hashAlgorithm (e.g., 32 for SHA-256), following industry best practices (see, for example, TLS 1.3 and GCP KMS key algorithms).

I suspect this might be a breaking change in those apps/libs using the default values of MGF1 with SHA-1 and saltLength=20 (I think PKI.js' SignedData and Certificate might be affected from a cursory look at CryptoEngine but haven't had the time to double check).

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

2 participants