ursa-optional error handling not working #3

Closed
opened 2018-12-28 06:17:05 +00:00 by Ghost · 2 comments

In 'generate-privkey.js', the following code has been written to provide a fallback if ursa fails to build:

 try {
    return require('./generate-privkey-node.js')(bitlen, exp);
  } catch(e) {
    if (!/generateKeyPairSync is not a function/.test(e.message)) {
      throw e;
    }
    try {
      return require('./generate-privkey-ursa.js')(bitlen, exp);
    } catch(e) {
      if (e.code !== 'MODULE_NOT_FOUND') {
        throw e;
      }
      if (!oldver) {
        oldver = true;
        console.warn("[WARN] rsa-compat: Your version of node does not have crypto.generateKeyPair()");
        console.warn("[WARN] rsa-compat: Please update to node >= v10.12 or 'npm install ursa'");
        console.warn("[WARN] rsa-compat: Using node-forge as a fallback, but it may be unacceptably slow.");

However, due to the check if (e.code !== 'MODULE_NOT_FOUND'), this code fails to fall back to forge in the event that the module "installs" but dosen't "build". I am not well versed enough in ursa to even know if that should be possible, but it has given me hell this evening, as the result is a cryptic error and a stalled server. Commenting out that check caused the module to fallback on forge and work as expected.

In 'generate-privkey.js', the following code has been written to provide a fallback if ursa fails to build: ``` try { return require('./generate-privkey-node.js')(bitlen, exp); } catch(e) { if (!/generateKeyPairSync is not a function/.test(e.message)) { throw e; } try { return require('./generate-privkey-ursa.js')(bitlen, exp); } catch(e) { if (e.code !== 'MODULE_NOT_FOUND') { throw e; } if (!oldver) { oldver = true; console.warn("[WARN] rsa-compat: Your version of node does not have crypto.generateKeyPair()"); console.warn("[WARN] rsa-compat: Please update to node >= v10.12 or 'npm install ursa'"); console.warn("[WARN] rsa-compat: Using node-forge as a fallback, but it may be unacceptably slow."); ``` However, due to the check `if (e.code !== 'MODULE_NOT_FOUND')`, this code fails to fall back to forge in the event that the module "installs" but dosen't "build". I am not well versed enough in ursa to even know if that should be possible, but it has given me hell this evening, as the result is a cryptic error and a stalled server. Commenting out that check caused the module to fallback on forge and work as expected.
Owner

Thanks for the report. That is a very strange condition.

Can you copy/paste the cryptic error message to me or give me a summary of what it said?

Thanks for the report. That is a very strange condition. Can you copy/paste the cryptic error message to me or give me a summary of what it said?
Owner

Closing due to inactivity.

Closing due to inactivity.
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: coolaj86/rsa-compat.js#3
No description provided.