Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Bad Request #1

Closed
dunnkers opened this issue Jan 6, 2018 · 10 comments
Closed

Bad Request #1

dunnkers opened this issue Jan 6, 2018 · 10 comments

Comments

@dunnkers
Copy link

dunnkers commented Jan 6, 2018

Hello! Thanks for this seemingly handy module. I cannot get it to work, however. The error I get when I try to client.associate() is:

{ Error: Bad Request
    at new NetworkResponseStatusCodeError (/Users/me/Documents/git/project/node_modules/keepasshttp-client/model/common.js:36:28)
    at KeePassHttpClient.<anonymous> (/Users/me/Documents/git/project node_modules/keepasshttp-client/client.js:133:35)
    at step (/Users/me/Documents/git/project/node_modules/tslib/tslib.js:131:27)
    at Object.next (/Users/me/Documents/git/project/node_modules/tslib/tslib.js:112:57)
    at fulfilled (/Users/me/Documents/git/project/node_modules/tslib/tslib.js:102:62)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) statusCode: 400 }

I'm using MacPass along with the MacPassHTTP plugin.

Help is appreciated!

@vladimiry
Copy link
Owner

vladimiry commented Jan 6, 2018

Hi @dunnkers, can you set NODE_DEBUG=http environment variable before running your code, that would allow to get more information for analysis. Then attach the console output here.

Besides it won't hurt if you install the Mac/DMG KeePassXC version from here https://github.com/keepassxreboot/keepassxc/releases and try to associate with it instead of MacPass. MacPass should be closed before running KeePassXC, as most likely both tools will try to listen on the same 19455 port (default keepasshttp listening port). You will need to explicitly enable the keepasshttp feature in the KeePassXC settings (Browser Integration settings tab).

PS module has been tried and successfully worked with original KeePass on Windows and KeePassXC on Linux, I've not tried running it with MacPass / MacPassHTTP stuff.

@dunnkers
Copy link
Author

This is the shell output:

$$ NODE_DEBUG=http node test-keepass.js
HTTP 1944: call onSocket 0 0
HTTP 1944: createConnection localhost:19455: { servername: 'localhost',
  auth: null,
  path: null,
  port: '19455',
  hostname: 'localhost',
  protocol: 'http:',
  _abort: false,
  _raw: [],
  timeout: 0,
  size: 0,
  bodyUsed: false,
  body: '{"TriggerUnlock":false,"Nonce":"asdf33Ak3#JFIa==","Verifier":"HFo2fRrdfasP97Wddjb5yW+84asdfsNkYsRv3311d+I=","RequestType":"associate","Key":"FFeRaaaP6L4fsasdf382mrkdfasoNIC63aeQL+o+klVQA="}',
  agent: undefined,
  counter: 0,
  compress: true,
  follow: 20,
  url: 'http://localhost:19455',
  headers:
   { 'accept-encoding': [ 'gzip,deflate' ],
     'user-agent': [ 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' ],
     connection: [ 'close' ],
     accept: [ '*/*' ],
     'content-length': [ 195 ] },
  redirect: 'follow',
  method: 'POST',
  host: 'localhost',
  _agentKey: 'localhost:19455:' }
HTTP 1944: sockets localhost:19455: 1
HTTP 1944: write ret = false
HTTP 1944: outgoing message end.
HTTP 1944: AGENT incoming response!
HTTP 1944: AGENT isHeadResponse false
{ Error: Bad Request
    at new NetworkResponseStatusCodeError (/Users/dunnkers/Documents/git/ing-api/ing-api/node_modules/keepasshttp-client/model/common.js:36:28)
    at KeePassHttpClient.<anonymous> (/Users/dunnkers/Documents/git/ing-api/ing-api/node_modules/keepasshttp-client/client.js:133:35)
    at step (/Users/dunnkers/Documents/git/ing-api/ing-api/node_modules/tslib/tslib.js:131:27)
    at Object.next (/Users/dunnkers/Documents/git/ing-api/ing-api/node_modules/tslib/tslib.js:112:57)
    at fulfilled (/Users/dunnkers/Documents/git/ing-api/ing-api/node_modules/tslib/tslib.js:102:62)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) statusCode: 400 }
HTTP 1944: CLIENT socket onClose
HTTP 1944: removeSocket localhost:19455: writable: false
HTTP 1944: HTTP socket close

When running this code:

const { KeePassHttpClient } = require("keepasshttp-client");
const client = new KeePassHttpClient();

client.associate()
    .then(() => client.getLogins({ url: 'twitter.com' }))
    .then((records) => console.log(JSON.stringify(records, null, 2)))
    .catch((err) => console.error(err));

Thanks for diving into this. There has to be some small miscommunication between keepasshttp-client and the MacPass KeePassHTTP Plugin's Server. This is weird because it should all run the same KeePassHTTP protocol. MacPass does work with Safari plugins passafari, KeePassHelper and Chrome plugins chromeIPass, KeePass Tusk for example, which suggests that there is no error in the protocol on MacPass's side. There might be a protocol error somewhere else?

Regards. ✌🏻

@dunnkers
Copy link
Author

dunnkers commented Jan 14, 2018

BTW my KeePassHTTP Server was running in the execution of that code 👆🏻

@vladimiry
Copy link
Owner

@dunnkers Just tried to debug it running the same code. I get outgoing message end. after key entering dialog window showing and AGENT isHeadResponse false line after entering key name in that dialog window and clicking "ok" (MacPass might have another button name). So applying the same log lines sequence to your case I can assume that you got key entering dialog shown, did you?

What happens if you run just associate? Such code:

const {KeePassHttpClient} = require("keepasshttp-client");
const client = new KeePassHttpClient(/*{url: "http://localhost:19455"}*/);

client.associate()
    .then(console.log)
    .catch(console.error);

Also try to execute getLogins method with uri scheme specified, like .getLogins({url: "https://twitter.com"}); or .getLogins({url: "http://twitter.com"});.

Btw try to use previous version of your plugin/tools MacPass/MacPassHTTP#48

@dunnkers
Copy link
Author

Using your code to only just run associate() already throws a Bad Request error. The keepass-http-client package, however, does work correctly with MacPass. There's probably a difference in implementation in that package and yours?

@vladimiry
Copy link
Owner

vladimiry commented Jan 22, 2018

The apparent difference is in http request libraries used, I prefer to use much more lightweight library than request-promise-native. Here is the revision of this module 9d9da85 that used request-promise-native module if you want to try it. Meanwhile going to debug the http request difference, I guess it's in the request headers.

vladimiry added a commit that referenced this issue Jan 22, 2018
@vladimiry
Copy link
Owner

@dunnkers can you try just recently posted 2.2.5 version.

@dunnkers
Copy link
Author

Excellent! It works now!

kapture 2018-01-23 at 0 45 19

After obtaining a key from MacPass, I'm able to retrieve some example username/password. Nice ✌🏻

@vladimiry
Copy link
Owner

Ok, closing then.

@dunnkers
Copy link
Author

I think we can consider this issue closed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants