dfrankland / lastpass-node

🔐 Lastpass client for Node.js
28 stars 10 forks source link

digital envelope routines:EVP_DecryptFinal_ex:bad decrypt #1

Closed ciro-webcom closed 6 years ago

ciro-webcom commented 8 years ago

Hi, I'm getting this error while using lpass.getAccounts. I'm not expert in node js but I don't understand why I get this error. The functions I used are :

lpass.loadVault(USERNAME, PASSWORD);
lpass.getVault();
lpass.getAccounts(
      USERNAME,
      PASSWORD,
      SEARCH
    );

With SEARCH = undefined; I take your index.js example and comment out functions I don't need. Can you tell me if I missed something? Thank you

dfrankland commented 8 years ago

So, two things that may be wrong:

  1. Most commands are asynchronous. Are you ensuring that you wait for each one to finish before proceeding with the next? Maybe your code example needs to look something like this:

    // Async Promise
    lpass.loadVault(USERNAME, PASSWORD).then(function () {
     try {
       // Sync
       lpass.getVault();
     } catch (error) {
       console.error(error);
     }
    }).then(function () {
     // Async Promise
     lpass.getAccounts(USERNAME, PASSWORD).then(function (accounts) {
       console.log(accounts);
     }).catch(function (error) {
       console.error(error);
     });
    }).catch(function (error) {
     console.error(error);
    });
  2. This error you are receiving...

    digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

    ...is usually indicative of either a bad USERNAME or PASSWORD. Can you please try to ensure that they are correct?

ciro-webcom commented 8 years ago

Hi, Thank you for your answer. My credentials are correct, the code was the same than the /example/index.js one. I replaced it with the code in your answer, I just added Lastpass initialization and imports:

import Lastpass from '../index';
import { USERNAME, PASSWORD, FILE, SEARCH } from './credentials';

const lpass = new Lastpass(USERNAME);

lpass.loadVault(USERNAME, PASSWORD).then(function () {
  try {
    // Sync
    lpass.getVault();
  } catch (error) {
    console.error(error);
  }
}).then(function () {
  // Async Promise
  lpass.getAccounts(USERNAME, PASSWORD).then(function (accounts) {
    console.log(accounts);
  }).catch(function (error) {
    console.error(error);
  });
}).catch(function (error) {
  console.error(error);
});

Is this correct? Because I get the same error. Sorry but I don't know(for the moment) ES6 specifications, I'm reading that at the moment.

dfrankland commented 8 years ago

I am pretty sure that you are having issues because your USERNAME or PASSWORD is wrong, but just in case it's not, can you please try the following ES5 example?

This is fully compatible with node itself, no need for babel or the like.

  1. Try saving the example to a file like lastpass-test.js and package.json
  2. Replace YOUR USERNAME HERE with your username
  3. Replace YOUR PASSWORD HERE with your password
  4. Run npm install, to install the dependency
  5. Run node ./lastpass-test.js to check if you get the same error

lastpass-test.js

var Lastpass = require('lastpass').default;

var USERNAME = 'YOUR USERNAME HERE';
var PASSWORD = 'YOUR PASSWORD HERE';

var lpass = new Lastpass(USERNAME);

// Async Promise
lpass.loadVault(USERNAME, PASSWORD).then(function () {
  try {
    // Sync
    lpass.getVault();
  } catch (error) {
    console.error('Get vault error:', error);
  }
}).then(function () {
  // Async Promise
  lpass.getAccounts(USERNAME, PASSWORD).then(function (accounts) {
    console.log(accounts);
  }).catch(function (error) {
    console.error('Get accounts error:', error);
  });
}).catch(function (error) {
  console.error('Load vault error:', error);
});

package.json

{
  "scripts": {
    "start": "node ./lastpass-test.js"
  },
  "dependencies": {
    "lastpass": "^1.0.2"
  }
}

Here's a gist if you prefer.

I tested this myself on node version v6.3.1 without any issues. What version of node are you using by the way? You can check by running node -v.

ciro-webcom commented 8 years ago

Hi, Now I have a different error, but from lastpass which block my IP because I tried to connect from another country. I think I will send them an email, or maybe waiting to come back from holidays. Thank you for your time, I think the problem is resolved. I tried again the first script that you sent me and get the same error than with the last one, so I think that the problem was the big number of connection trials and now the different location. Thank you very much for your patience and time and I will inform you if I will have others problem. And obviously, great work!

ciro-webcom commented 8 years ago

Hi, I'm sorry to inform you that I still have problems while getting account : Get accounts error: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt at Error (native) at Decipher.Cipher.final (crypto.js:150:26) at decrypt (/var/www/html/lastpassnobabel/node_modules/lastpass/dist/lib/decryptData.js:12:62)

Maybe it's not aes-256-cbc? I really don't understand, because it connect to lastpass but it can't get account

ciro-webcom commented 8 years ago

I tried with two differents accounts with the same result

dfrankland commented 8 years ago

Can you try to create a Lastpass account that I can help you with? I cannot reproduce this error.

Also, what version of node are you running?

JoelBMatias commented 7 years ago

Hi, this is an old issue but I was able to reproduce this. With my personal account I'm able to decrypt de blob file with me credentials for that account. With an enterprise account, none of the users (they have admin rights) can access the accounts associated with that enterprise account, they always get the error mentioned in this thread.

dfrankland commented 7 years ago

@JoelBMatias, hmmm. I don't have an enterprise account at all so I am not quite sure how to go about solving that...

AndreiSoroka commented 6 years ago

Hello! I have got an enterprise account. And I can't connect to the LastPass. Maby I can help you?

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt at Decipher.final (internal/crypto/cipher.js:104:26) at decrypt (/Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/lib/decryptData.js:12:62) at exports.default (/Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/lib/decryptData.js:25:17) at exports.default (/Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/lib/openAccount.js:28:45) at /Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/lib/openVault.js:32:60 at Generator.next () at step (/Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14 at new Promise () at new F (/Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/node_modules/core-js/library/modules/_export.js:35:28) at /Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12 at exports.default (/Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/lib/openVault.js:43:17) at /Users/andreisoroka/git/data-integrator/node_modules/lastpass/dist/index.js:150:57 at Generator.next () at step (/Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /Users/andreisoroka/git/data-integrator/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

AndreiSoroka commented 6 years ago

I find and fixed. More information https://github.com/nodejs/node/issues/2794#issuecomment-139436581