Skip to content

unable to use p11-kit for pkcs#11 modules #171978

Closed

Description

@flokli

Reading b9bb98c, I assumed I'm able to "load PKCS#11 modules without ad-hoc configuration".

I created a /etc/pkcs11/pkcs11.conf with the following contents:

  environment.etc."pkcs11/pkcs11.conf".text = ''
    module: ${pkgs.opensc}/lib/onepin-opensc-pkcs11.so
    critical: yes
    log-calls: yes
  '';

p11-kit list-modules now prints a ton of debug info (so above config file is honored, and the log-calls: yes in there definitely makes a difference), but it seems it's not possible to load this pkcs11 module.

p11-kit list-modules doesn't show it: (output without log-calls for readability):

[nix-shell:~]$ P11_KIT_DEBUG=all p11-kit list-modules
(p11-kit:1047280) p11_library_init_impl: initializing library
(p11-kit:1047280) p11_kit_modules_load: in
(p11-kit:1047280) _p11_conf_parse_file: reading config file: /etc/pkcs11/pkcs11.conf
(p11-kit:1047280) _p11_conf_parse_file: config value: module: /nix/store/5syfwkyrvpc4x82wa57ih3m3ajak7sqp-opensc-0.22.0/lib/onepin-opensc-pkcs11.so
(p11-kit:1047280) _p11_conf_parse_file: config value: critical: yes
(p11-kit:1047280) _p11_conf_parse_file: reading config file: /home/flokli/.config/pkcs11/pkcs11.conf
(p11-kit:1047280) _p11_conf_parse_file: config file does not exist
(p11-kit:1047280) load_configs_from_directory: loading module configs in: /home/flokli/.config/pkcs11/modules
(p11-kit:1047280) load_configs_from_directory: module configs do not exist
(p11-kit:1047280) load_configs_from_directory: loading module configs in: /etc/pkcs11/modules
(p11-kit:1047280) load_configs_from_directory: module configs do not exist
(p11-kit:1047280) load_configs_from_directory: loading module configs in: /nix/store/qwbf9ps8cy74f8sz8zplq2qxr1wng73g-p11-kit-0.24.1/share/p11-kit/modules
(p11-kit:1047280) _p11_conf_parse_file: reading config file: /nix/store/qwbf9ps8cy74f8sz8zplq2qxr1wng73g-p11-kit-0.24.1/share/p11-kit/modules/p11-kit-trust.module
(p11-kit:1047280) _p11_conf_parse_file: config value: module: p11-kit-trust.so
(p11-kit:1047280) _p11_conf_parse_file: config value: priority: 1
(p11-kit:1047280) _p11_conf_parse_file: config value: trust-policy: yes
(p11-kit:1047280) _p11_conf_parse_file: config value: x-trust-lookup: pkcs11:library-description=PKCS%2311%20Kit%20Trust%20Module
(p11-kit:1047280) _p11_conf_parse_file: config value: disable-in: p11-kit-proxy
(p11-kit:1047280) _p11_conf_parse_file: config value: x-init-reserved: 
(p11-kit:1047280) is_module_enabled_unlocked: enabled module 'p11-kit-trust' running in 'p11-kit'
(p11-kit:1047280) load_module_from_file_inlock: module path is relative, loading from: /nix/store/qwbf9ps8cy74f8sz8zplq2qxr1wng73g-p11-kit-0.24.1/lib/pkcs11
(p11-kit:1047280) load_module_from_file_inlock: loading module p11-kit-trust from path: /nix/store/qwbf9ps8cy74f8sz8zplq2qxr1wng73g-p11-kit-0.24.1/lib/pkcs11/p11-kit-trust.so
(p11-kit:1047280) p11_library_init_impl: initializing library
(p11-kit:1047280) dlopen_and_get_function_list: opened module: /nix/store/qwbf9ps8cy74f8sz8zplq2qxr1wng73g-p11-kit-0.24.1/lib/pkcs11/p11-kit-trust.so
(p11-kit:1047280) is_module_enabled_unlocked: enabled module 'p11-kit-trust' running in 'p11-kit'
(p11-kit:1047280) p11_kit_modules_load: out: success
(p11-kit:1047280) managed_C_Initialize: in
(p11-kit:1047280) initialize_module_inlock_reentrant: C_Initialize: calling
(p11-kit:1047280) sys_C_Initialize: in
(p11-kit:1047280) sys_C_Initialize: doing initialization
(p11-kit:1047280) create_tokens_inlock: using paths: /etc/ssl/trust-source:/etc/ssl/certs/ca-certificates.crt:/etc/pki/tls/certs/ca-bundle.crt
(p11-kit:1047280) p11_token_new: token: System Trust: /etc/ssl/trust-source
(p11-kit:1047280) p11_token_new: token: ca-certificates.crt: /etc/ssl/certs/ca-certificates.crt
(p11-kit:1047280) p11_token_new: token: ca-bundle.crt: /etc/pki/tls/certs/ca-bundle.crt
(p11-kit:1047280) sys_C_Initialize: out: 0x0
(p11-kit:1047280) initialize_module_inlock_reentrant: C_Initialize: result: 0
(p11-kit:1047280) managed_C_Initialize: out: 0
p11-kit-trust: p11-kit-trust.so
(p11-kit:1047280) sys_C_GetInfo: in
(p11-kit:1047280) sys_C_GetInfo: out: 0x0
    library-description: PKCS#11 Kit Trust Module
    library-manufacturer: PKCS#11 Kit
    library-version: 0.24
(p11-kit:1047280) sys_C_GetSlotList: in
(p11-kit:1047280) sys_C_GetSlotList: out: 0x0
(p11-kit:1047280) sys_C_GetTokenInfo: in
(p11-kit:1047280) sys_C_GetTokenInfo: out: 0x0
    token: System Trust
        manufacturer: PKCS#11 Kit
        model: p11-kit-trust
        serial-number: 1
        hardware-version: 0.24
        flags:
               write-protected
               token-initialized
(p11-kit:1047280) sys_C_GetTokenInfo: in
(p11-kit:1047280) sys_C_GetTokenInfo: out: 0x0
    token: ca-certificates.crt
        manufacturer: PKCS#11 Kit
        model: p11-kit-trust
        serial-number: 1
        hardware-version: 0.24
        flags:
               write-protected
               token-initialized
(p11-kit:1047280) sys_C_GetTokenInfo: in
(p11-kit:1047280) sys_C_GetTokenInfo: out: 0x0
    token: ca-bundle.crt
        manufacturer: PKCS#11 Kit
        model: p11-kit-trust
        serial-number: 1
        hardware-version: 0.24
        flags:
               write-protected
               token-initialized
(p11-kit:1047280) managed_C_Finalize: in
(p11-kit:1047280) sys_C_Finalize: in
(p11-kit:1047280) sys_C_Finalize: doing finalization
(p11-kit:1047280) sys_C_Finalize: out: 0x0
(p11-kit:1047280) managed_C_Finalize: out: 0
(p11-kit:1047280) p11_kit_modules_release: in
(p11-kit:1047280) uninit_common: uninitializing library
(p11-kit:1047280) p11_kit_modules_release: out
(p11-kit:1047280) uninit_common: uninitializing library

Activity

  1. added
    0.kind: bug
    on May 7, 2022
  2. flokli commented on May 7, 2022

    @flokli
    MemberAuthor

    Okay, apparently I read the manpage wrong, and individual module configs need to go into /etc/pkcs11/modules/$name, not /etc/pkcs11/pkcs11.conf.

    With

      environment.etc."pkcs11/modules/onepin-opensc-pkcs11".text = ''
        module: ${pkgs.opensc}/lib/onepin-opensc-pkcs11.so
        critical: yes
      '';
    

    I get p11-kit list-modules to show the module, and p11tool --list-tokens to show the token.

    However, firefox still doesn't seem to be using p11-kit. Time to debug that…

  3. flokli commented on May 7, 2022

    @flokli
    MemberAuthor

    Firefox needs to be convinced to use p11-kit-proxy by running a command like this:

    modutil -add p11-kit-proxy -libfile ${p11-kit}/lib/p11-kit-proxy.so -dbdir ~/.mozilla/firefox/*.default
    

    I was also able to accomplish the same by making use of extraPolciies when overriding the firefox package:

            extraPolicies = {
              SecurityDevices.p11-kit-proxy = "${pkgs.p11-kit}/lib/p11-kit-proxy.so";
            };
    
  4. wamserma commented on May 7, 2022

    @wamserma
    Member

    @flokli Can you put a note into the Wiki or the Firefox section of the the manual?

  5. flokli commented on May 7, 2022

    @flokli
    MemberAuthor

    @wamserma the manual seems incorrect - I couldn't get to use wrapFirefox, had to use my

    firefox.override {
      extraPolciies = {
        …
      };
    }
    

    When trying to use the example in doc/builders/packages/firefox.section.md (only setting extraPolicies), it failed evaluation, as browser.gtk3 didn't exist.

    I don't want to document something I can't reproduce, and don't want to change the documentation to something that might be discouraged to use.

    Can you take a look if you can get the example to build?

    Happy to add a small section there afterwards.

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

Metadata

Metadata

Assignees

Labels

0.kind: bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions