Skip to content

Forking causes an error with PKCS#11 crypto module #550

Closed

Description

@matt-allan

Hi,

I'm not sure if there is anything Psysh can really do about this but I figured I would report the issue in case anyone else runs into it.

If you use Curl in a Psysh shell twice in a row with SSL you will encounter an error like this:

 cURL error 35: A PKCS #11 module returned CKR_DEVICE_ERROR, indicating that a problem has occurred with the token or slot. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'

This appears to be caused (at least in my case) by the NSS libraries. The docs state:

It is an error to try to use a PKCS#11 crypto module in a process before it has been initialized in that process, even if the module was initialized in the parent process. Beginning in NSS 3.12.3, Softoken will detect this error.

I found two workarounds.

1.) Set usePcntl to false in the psysh config file as explained in #511.
2.) set the NSS environment variable NSS_STRICT_NOFORK to DISABLED as explained in the docs linked above, i.e. NSS_STRICT_NOFORK=DISABLED psysh

Reproduction steps:

1.) compile curl with NSS instead of openssl or libressl. It should say something like curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.28.4...
2.) compile php and the curl extension
3.) Install psysh and open a shell
4.) execute the following:

>>> $ch = curl_init()
=> curl resource #930
>>> curl_setopt($ch, CURLOPT_URL, "https://www.example.com/");
=> true
>>> curl_exec($ch)
<!doctype html>...
=> true
>>> curl_exec($ch)
=> false
>>> curl_error($ch)
=> "A PKCS #11 module returned CKR_DEVICE_ERROR, indicating that a problem has occurred with the token or slot."

Activity

  1. bobthecow commented on May 3, 2020

    @bobthecow
    Owner

    I just added a troubleshooting section to the wiki to cover resolution for this sort of thing: https://github.com/bobthecow/psysh/wiki/Troubleshooting

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions