Closed schoolmeister closed 2 years ago
@schoolmeister, unfortunately, PKCS#11 does not inherently save the algorithm used in key generation or have a way to specify how a key was generated.
WebCrypto requires that the caller specify the hash algorithm to be specified on generation and import.
It is technically possible in the PKCS#11 specification to set properties on a key, for example, we could according to the specification set what hash algorithm was used as a property. This would be proprietary as there is no standard for it but even if we did this many PKCS#11 libraries do not support this.
As a result, we currently hard-code the use of SHA-256 due to security concerns over prolonging the use of SHA-1.
This value can be overridden as is done here.
It's possible to set hash algorithm on key getting using importKey
arguments
https://github.com/PeculiarVentures/node-webcrypto-p11/blob/master/src/key_storage.ts#L51
await crypto.keyStorage.getItem(publicKeyID, algorithm, false, ["sign"]);
Issue
No matter which hashing algorithm is filled in when generating an RSA keypair, after saving it to the keyStore and retrieving it again, the hashing algorithm is always set to SHA-256. Using such a corrupt key for encryption/decryption raises a
CKR_ARGUMENTS_BAD:7
error.Temporary workaround
After retrieving, manually setting
algorithm.hash.name
to SHA-1 seems to fix the error.Example code