Skip to content
This repository has been archived by the owner on May 27, 2019. It is now read-only.

"Error: Native host has exited" on Chrome and NixOS #175

Closed
Sophia-Gold opened this issue Oct 8, 2017 · 27 comments
Closed

"Error: Native host has exited" on Chrome and NixOS #175

Sophia-Gold opened this issue Oct 8, 2017 · 27 comments

Comments

@Sophia-Gold
Copy link

NixOS 17.03
Chrome 55.0.2883.87
Browserpass 2.04

Browserpass says "Error: Native host has exited" immediately upon clicking on the icon in Chrome. Trying to look up an entry in my password file has no effect.

I initially tried to install it with Nix, but got an error it couldn't locate the package. I then used the Chrome Web Store and, after the problem first appeared, downloaded it and used your install script to see if that would make a difference (even though the versions are currently the same).

The problem persists even when Chrome is launched from root and the paths seems correct so I'm not sure what could be causing the extension to crash.

@maximbaz
Copy link
Member

maximbaz commented Oct 8, 2017

First run this and see how many results you have, should be one or two if you installed browserpass only for one browser:

$ locate com.dannyvankooten.browserpass.json

Then look into one of those files that is in the native-messaging-hosts folder - take the path from it to the binary. That is the binary that extension will try to use, /usr/bin/browserpass in my case.

Judging by your error, Chrome tries to execute this app, but fails for some reason. Check permissions on the file, can you execute it as a normal user?

Download this file and try this command - this is exactly what browser extension is doing when it wants to search for github.com passwords, see what this returns:

$ /usr/bin/browserpass < request.hex.txt

@Sophia-Gold
Copy link
Author

The path inside ~/.config/google-chrome/NativeMessagingHosts/com.dannyvankooten.browserpass.json is /home/sophia/.browserpass/browserpass-linux64, which is correct (this was the first thing I checked).

I didn't think to check its permissions, but they're currently set to rwx for myself and r-x for all other users so that doesn't seem to be the problem.

However, if I try to direct your request to the browserpass executable, i.e. /home/sophia/.browserpass/browserpass-linux64 < request.hex.txt, then I get "browserpass-linux64: command not found" despite it very clearly being marked as executable.

@Sophia-Gold
Copy link
Author

I also just installed it for Firefox and get the analogous "Error: Attempt to postMessage on disconnected port" message so it doesn't seem to be a browser issue 😕

@maximbaz
Copy link
Member

maximbaz commented Oct 8, 2017

.... then I get "browserpass-linux64: command not found" ....

This is very strange 🤔 It is definitely the cause of your issue, if you can't execute this app via terminal, browsers cannot execute it too...

Not knowing much about NixOS, I'm wondering if the binary formats are compatible with other linuxes? And a stupid question, do you have 64bit OS?

@maximbaz
Copy link
Member

maximbaz commented Oct 8, 2017

If you want, you can also compile a binary directly on your hardware to see if it works. If you don't want to spend time on installing Go, dep and the rest of prerequisites, I suggest to use Docker, you only need to run two commands, build an image and compile frontend+backend (instructions here). This will generate browserpass executable file, which then you can try to run and feed it the same request.hex.txt file.

@Sophia-Gold
Copy link
Author

NixOS doesn't use any weird binary formats. You could run apt on it if you wanted and it would work fine. Sometimes there are path issues when things with dependencies are installed through other means (although I find that's much more common when using Nix on Darwin), which is why that was the first thing I check here. And, yes, x86-64 🙂

I even reset privileges for good measure. I should probably also mention that if I try directing your request to the full path of the executable rather than from inside the directory then I get a "No such file or directory" error from bash. I thought it could be because it's in a dot directory, but I still get the error when changing that. I also tried updating the JSON file native-messaging-hosts accordingly to see if that solved the issue, but nope.

Not sure what else to try other than a manual build...

@Sophia-Gold
Copy link
Author

I'm not sure what the "allowed_origins" field does in the native messaging JSON file. I currently have two:

chrome-extension://naepdomgkenhinolocfifgehidddafch/
chrome-extension://klfoddkbhleoaabpmiigbmpbjfljimgb/

@maximbaz
Copy link
Member

maximbaz commented Oct 8, 2017

These are correct entries for "allowed_origins". Besides trying a manual build, I have only one idea - I'm attaching a hello-world app compiled on the same machine where I compiled browserpass-linux64 with the same parameters. Could you try to put it in the same folder where you have browserpass-linux64 and execute it, and see if it works? The .txt extension is only needed to fool Github, you can remove it, it is a binary. I'm trying to find out if the problem is specifically with browserpass binary, or with any binary that I am distributing.

hello-world.txt

@Sophia-Gold
Copy link
Author

That executes fine if I remove the extension and call chmod +x on it. But browserpass-linux64 < request.hex (with the exact same permissions as your hello-world) gives me "browserpass-linux64: command not found."

Just to be clear: it doesn't need to be run with any flags or anything before directing that request? Fwiw, I also tried browserpass-linux64 .{"action":"search","domain":"github.com"}, with and without the dot before the opening brace, and get the same error.

@maximbaz
Copy link
Member

maximbaz commented Oct 8, 2017

Hmm... No, I can't think of anything extra, it should just work...

"Command not found" is very confusing to me, it sounds as if OS cannot find the binary at the provided location. Did you have browserpass-linux64 and hello-world in the same folders? If not, try putting browserpass-linux64 to the folder where you had hello-world. I'm asking this because recently someone had exactly this problem, they put browserpass-linux64 in a folder which was mounted without executable flag. Otherwise... I don't know, maybe try to rename browserpass-linux64 to hello-world, in case the file name is for some reasons not acceptable (although I can't think of any reason for that).

@Sophia-Gold
Copy link
Author

Apologies, but I think this is a red herring: it's not currently in my path and I didn't call it with ./. However ./browserpass-linux64 < request.hex returns nothing at all.

I just moved the browserpass folder to ~/bin, which is on my path, but I still need need to launch the binary as ./browserpass-linux64 and it's still crashing according to Chrome and Firefox.

@maximbaz
Copy link
Member

maximbaz commented Oct 9, 2017

Do you have a password stored for github.com for this request.hex to find? If not, maybe empty result is a correct response. It's not super obvious how to compose this request.hex, but you can try to change domain to something else in the file and see if it can discover the password. This tool is also good, it simplified testing a lot.

When you moved the browserpass to ~/bin, did you adjust the com.dannyvankooten.browserpass.json to point to the new path? Browser will not look in $PATH, it will look only in that file.

@maximbaz
Copy link
Member

Hey @Sophia-Gold, did you have a chance to investigate this further? I can't think of anything I could do on my side to help you right now, so far it looks like you had some success moving the executable from one folder to another, hopefully it's only a matter of adjusting the json file now. Let me know how it goes.

@Sophia-Gold
Copy link
Author

I haven't had time yet, although I did modify the path in the json file when moving the browserpass directory. And I do have an entry for github.com, although even if I didn't that wouldn't explain Chrome telling me the native host is crashing.

I haven't been able to troubleshoot this further since I've been at work where I use OS X. I did install browserpass there as well, via the same means. While it does recognize when I'm on a site that I have a password stored for, but when still gives me "Error: Native host has exited" when it tries to look them up.

@maximbaz
Copy link
Member

maximbaz commented Oct 11, 2017

Okay, thanks. Not having an entry wouldn't explain the Chrome crash indeed, but it could have explained why you see empty result from the host application itself. I still believe this is the key to your issue on NixOS, find out why the host app doesn't work, make it work via terminal and then Chrome will also be able to make use of it.

As for issues on Mac, the folks in #13 would be able to give you some hints, I don't have a Mac myself, but I picked up that starting browser from terminal and having GPGtools installed helped many people - I recommend heading to #13 if you want to also investigate issues on OS X.

@kamilchm
Copy link

@Sophia-Gold you can't run binaries from other systems on NixOS.
Try to run ldd /home/sophia/.browserpass/browserpass-linux64 and look at the ld-linux path. It doesn't exists on NixOS and this is why you see command not found.

You need to patch it with https://nixos.org/patchelf.html.
You can find more at:

@maximbaz
Copy link
Member

Wow, thanks, that's interesting to know.

Thinking out loud, it would be awesome if someone from the community would create a package for NixOS, just like there is AUR package for ArchLinux - that way no one would need to patch anything.

@maximbaz
Copy link
Member

maximbaz commented Oct 11, 2017

Hey, isn't this a browserpass package for NixOS? The version is quite old, but at least it already exists. @Sophia-Gold wanna try it out? The new browserpass-ce extension will be incompatible with it, but the old browserpass should work.

@Sophia-Gold
Copy link
Author

I was about to say...there is a Nix package (I also use Nix on OS X), but when I tried to install it at home Nix couldn't find it on channel NixOS 17.03 😕

@kamilchm
Copy link

kamilchm commented Oct 11, 2017

There's 17.09 now (with browserpass), so why not update your system, especially having atomic updates and rollbacks :) You can't break NixOS.

@maximbaz
Copy link
Member

maximbaz commented Oct 11, 2017

@Sophia-Gold if you don't see the package even after upgrade as @kamilchm suggests, could you perhaps follow up on this with folks at NixOS/nixpkgs/? Making this package available would benefit everyone, and you wouldn't need to patch anything. Also, they should update the version to 2.x, there have been soo many improvements since v1 🙂

@maximbaz
Copy link
Member

I'll close the ticket since the mystery seems to be solved and there is nothing to do in this repo. Thanks to both of you for reporting, doing experiments and eventually finding the answer!

@Sophia-Gold
Copy link
Author

Somehow I totally missed @kamilchm's comments earlier in the week. Thanks for explaining the dynamic linking issue.

I just had to switch channels to 17.09 and then upgrade to get Browserpass. Although in response to "You can't break NixOS"... I've had to rollback to a 16.03 build from May every time I reboot, likely due to Nvidia issues and the lovely fact that I can't disable graphics (even integrated) in BIOS on this machine.

Anyway, the issue with Browserpass remains, but I suspect it's because the rebuild wiped out a ton of stuff...including my chrome config and pass itself...

@infinisil
Copy link
Contributor

Because I just spent a couple hours debugging this:

I was getting the error "Error: Attempt to postMessage on disconnected port" on NixOS. I was using the firefox-beta-bin version, which doesn't work! Browserpass only works with non--bin versions on NixOS.

Why? These -bin versions of firefox are pretty much just fetched directly from mozilla and patched up to work on NixOS. The non--bin versions however are built from source. If we don't build from source, we can't get this patch which makes firefox look at the correct place for the native-messaging-hosts jsons.

So, these are the final instructions on how to install browserpass on NixOS:

  • Install the extension like normal
  • On NixOS: Make sure you have this in your /etc/nixos/configuration.nix:
    { pkgs, ... }: {
      # Note: firefox*-bin versions won't work with browserpass
      environment.systemPackages = [ pkgs.firefox ];
      programs.browserpass.enable = true;
    }
    and rebuild your system.
  • On non-NixOS: Make sure you have this in your ~/.config/nixpkgs/config.nix:
    {
      firefox.enableBrowserpass = true;
    }
    and reinstall firefox with nix-env -iA nixpkgs.firefox (alternatively nix-env -iA nixos.firefox on NixOS)
  • Running a browserpass-enabled firefox without installing:
    $(nix-build --no-out-link '<nixpkgs>' -A firefox \
      --arg config '{ firefox.enableBrowserpass = true; }')/bin/firefox

@maximbaz These instructions would be well suited for a small NixOS section in the readme

@maximbaz
Copy link
Member

Nice job @infinisil, have a look at #307, is there anything you want me to add?

@maximbaz
Copy link
Member

Specifically, I'm curious if this only applies to Firefox or also to Chrome?

@Sophia-Gold
Copy link
Author

Thank you @infinisil. It's now working for me in both Firefox and Chrome.

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

No branches or pull requests

4 participants