Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web-eid-app for NixOS: pin1 works, pin2 don't #317

Closed
getreu opened this issue Mar 25, 2024 · 15 comments
Closed

web-eid-app for NixOS: pin1 works, pin2 don't #317

getreu opened this issue Mar 25, 2024 · 15 comments

Comments

@getreu
Copy link

getreu commented Mar 25, 2024

NixOS comes with the package web-eid-app and instructions for Estonians .

With Firefox and the above config for NixOS 23.11, I can authenticate with e.g. https://lhv.ee but I can not sign. Any ideas?

I know, you do not officially support NixOS, but maybe some of you uses it and can help. Here my config:

services.pcscd.enable = true;
programs.firefox.enable = true;
programs.firefox.nativeMessagingHosts.packages = [ pkgs.web-eid-app ];
programs.firefox.policies.SecurityDevices.p11-kit-proxy = "${pkgs.p11-kit}/lib/p11-kit-proxy.so";
environment.etc."chromium/native-messaging-hosts/eu.webeid.json".source = "${pkgs.web-eid-app}/share/web-eid/eu.webeid.json";
environment.etc."opt/chrome/native-messaging-hosts/eu.webeid.json".source = "${pkgs.web-eid-app}/share/web-eid/eu.webeid.json";
environment.etc."pkcs11/modules/opensc-pkcs11".text = ''
  module: ${pkgs.opensc}/lib/opensc-pkcs11.so
'';
@getreu
Copy link
Author

getreu commented Mar 25, 2024

Is this related to #309 ?

@mrts
Copy link
Member

mrts commented Mar 25, 2024

What error do you see?
Can you please turn on native app logging as described here: https://web-eid.eu/ > Debugging and logs and check the log?

@getreu
Copy link
Author

getreu commented Mar 25, 2024

When I press [Authenticate] on https://web-eid.eu/ I get (in pink color):

Authentication failed

[Code]
ERR_WEBEID_EXTENSION_UNAVAILABLE

[Message]
Web-eID extension is not available

Strangely I can authenticate with https://lhv.ee.
After login in into the bank, there is still no log file:

In ~/.local/share/RIA/ is no web-eid.log.

When I start the binary from the console, I get:

$ web-eid 
INFO: "web-eid" app "2.4.0+0" running in command-line mode

Now the log file is created with the contents:

024-03-25T13:11:44.212Z INFO src/controller/controller.cpp:72:void Controller::run() - "web-eid" app "2.4.0+0" running in command-line mode

Is web-eid known to the firefox browser?

@mrts
Copy link
Member

mrts commented Mar 26, 2024

It looks like the extension is not installed in Firefox. Here's how it should look:

image

You can add the extension manually from here:
https://addons.mozilla.org/en-US/firefox/addon/web-eid-webextension/

@getreu
Copy link
Author

getreu commented Mar 26, 2024

It seem it is a NixOS firefox package related problem. I do not manage enable the extension. It does not even show in the browser tab (cf. your screenshot) above. If I get it work, I leave a note here. Thank you so far.

@getreu
Copy link
Author

getreu commented Mar 27, 2024

Screenshot_2024-03-27_15-39-39
Screenshot_2024-03-27_15-35-38

No log entry in web-eid.log, but I can start the app from the command line.
Screenshot_2024-03-27_15-43-38

@sergey-abc
Copy link

@getreu just in case check "Security Devices" section of Firefox settings.
image
Maybe You have to add (or unload and then load again) "onepin-opensc-pkcs11.so", this file can be located in different folder.

@getreu
Copy link
Author

getreu commented Mar 31, 2024

@sergey-abc I have this:
Screenshot_2024-03-31_10-13-24

@getreu
Copy link
Author

getreu commented Mar 31, 2024

Summary of my efforts. Please correct where I am wrong.

Installation

  1. Install the web-eid-app package in NixOS

    Insert in configuration.nix:

     packages = with pkgs; [
       firefox-esr
       web-eid-app
       p11-kit
       opensc
       
     ];

    and below:

    services.pcscd.enable = true;
    programs.firefox.enable = true;
    programs.firefox.package = pkgs.firefox-esr;
    programs.firefox.nativeMessagingHosts.packages = [ pkgs.web-eid-app ];
    programs.firefox.policies.SecurityDevices.p11-kit-proxy = "${pkgs.p11-kit}/lib/p11-kit-proxy.so";
    # Authentification
    environment.etc."pkcs11/modules/opensc-pkcs11".text = ''
      module: ${pkgs.opensc}/lib/opensc-pkcs11.so
    '';
  2. Enable logging (for testing only)

    1. Enable logging:

      echo 'logging=true' > ~/.config/RIA/web-eid.conf
    2. Check success:

      web-eid

      A dialogue About Web eID window appears. Click on [Cancel].

      cat /.local/share/RIA/web-eid/web-eid.log

      You should see something like:

      2024-03-31T06:56:42.804Z INFO src/controller/controller.cpp:72:void Controller::run() - "web-eid" app "2.4.0+0" running in command-line mode
      
  3. Install the browser extension within Firefox from
    Web eID – Get this Extension for Firefox (en-US)

  4. Link the web-eid manifest into the browser configuration

    mkdir -p ~/.mozilla/native-messaging-hosts/
    cd ~/.mozilla/native-messaging-hosts/
    ln -s "$(dirname $(dirname $(realpath $(which web-eid))))/share/web-eid/eu.webeid.json" .
    
  5. Check success

    1. Enable logging:
    2. Insert Estionan ID card.
    3. Check with DigiDoc that the card reader works and the ID card reader and
      driver works. (Ok)
    4. Goto https://web-eid.eu/ and click on [Authenticate].

Result

Unfortunately, I get the following error page in the browser:

Authentication failed
[Code]
ERR_WEBEID_NATIVE_UNAVAILABLE
[Message]
a message from native application was expected, but native application closed connection

Furthermore, no log message in /.local/share/RIA/web-eid/web-eid.log.

@getreu
Copy link
Author

getreu commented Mar 31, 2024

I also filed an issue here: NixOS/nixpkgs#300435

@mrts
Copy link
Member

mrts commented Apr 1, 2024

Thanks for your thorough investigation! The ERR_WEBEID_NATIVE_UNAVAILABLE message indicates that Firefox is unable to locate the native messaging host.

Please check that the native messaging manifest file has the following content:

{
"name": "eu.webeid",
"description": "Web-eid native application",
"path": "/usr/bin/web-eid",
"type": "stdio",
"allowed_extensions": [ "{e68418bc-f2b0-4459-a9ea-3e72b6751b07}" ]
}

Verify the value of allowed_extensions and that /usr/bin/web-eid exists.

If the content is correct, linking the file to ~/.mozilla/native-messaging-hosts/ should indeed work according to https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#linux. Can you check the symlink just in case or even copy the file in case Firefox does not follow symlinks for some reason? If you still get ERR_WEBEID_NATIVE_UNAVAILABLE when trying to authenticate on https://web-eid.eu, then please try the global locations listed in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#linux, start from /usr/lib/mozilla/native-messaging-hosts/eu.webeid.json.

Hope this helps!

@getreu
Copy link
Author

getreu commented Apr 1, 2024

@mrts
The manifest was the problem.

In the manual above, I replaced the line:

ln -s "$(dirname $(dirname $(realpath $(which web-eid))))/share/web-eid/eu.webeid.json" .

with

ls -s "$(dirname $(dirname $(realpath $(which web-eid))))/lib/mozilla/native-messaging-hosts/eu.webeid.json" .

Below you find the tested working procedure.

And authentification and signing works. Thank you a lot!

@getreu
Copy link
Author

getreu commented Apr 1, 2024

Edit: modified according to NixOS/nixpkgs#281710 (comment)

Tested working procedure:

Installation

  1. Install the web-eid-app package in NixOS

    Insert in configuration.nix:

    important: do not add firefox-esr in packages!

     packages = with pkgs; [
       web-eid-app
       p11-kit
       opensc
       
     ];

    and below:

    services.pcscd.enable = true;
    programs.firefox.enable = true;
    programs.firefox.package = pkgs.firefox-esr;
    programs.firefox.nativeMessagingHosts.packages = [ pkgs.web-eid-app ];
    programs.firefox.policies.SecurityDevices.p11-kit-proxy = "${pkgs.p11-kit}/lib/p11-kit-proxy.so";
    # Authentification
    environment.etc."pkcs11/modules/opensc-pkcs11".text = ''
      module: ${pkgs.opensc}/lib/opensc-pkcs11.so
    '';
  2. Enable logging (for testing only)

    1. Enable logging:

      echo 'logging=true' > ~/.config/RIA/web-eid.conf
    2. Check success:

      web-eid

      A dialogue About Web eID window appears. Click on [Cancel].

      cat /.local/share/RIA/web-eid/web-eid.log

      You should see something like:

      2024-03-31T06:56:42.804Z INFO src/controller/controller.cpp:72:void Controller::run() - "web-eid" app "2.4.0+0" running in command-line mode
      
  3. Install the browser extension within Firefox from
    Web eID – Get this Extension for Firefox (en-US)

  4. Check success

    1. Enable logging:

    2. Insert Estionan ID card.

    3. Check with DigiDoc that the card reader works and the ID card reader and
      driver works. (Ok)

    4. Goto https://web-eid.eu/ and click on [Authenticate].

      Type pin1, you should see:

      Digital signing
      Welcome, XXX XXX!
      

      Press the button [Sign document], then type pin2, you should see:

        Digital signing
        Welcome, XXX XXX!
        Signature added: example-for-signing.asice
      

@getreu getreu closed this as completed Apr 1, 2024
@getreu
Copy link
Author

getreu commented Apr 2, 2024

Edit: this workaround is not necessary any more according to NixOS/nixpkgs#281710 (comment)

Addendum

The lines

mkdir -p ~/.mozilla/native-messaging-hosts/
cd ~/.mozilla/native-messaging-hosts/
ls -s "$(dirname $(dirname $(realpath $(which web-eid))))/lib/mozilla/native-messaging-hosts/eu.webeid.json" .

are a workaround until #281710 is fixed.

@getreu
Copy link
Author

getreu commented Apr 3, 2024

Jens Getreu's blog - Sign with your Estonian ID card under NixOS

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

No branches or pull requests

3 participants