Local 7.1.2 default Openssl.cnf not working anymore

What issue or error are you experiencing?

By default the OpenSSL configuration is not referenced correctly anymore. The following call used to give a valid result for a fresh Local site:

 $key_resource = openssl_pkey_new([
            "digest_alg" => 'sha512',
            "private_key_bits" => 4096,
            "private_key_type" => OPENSSL_KEYTYPE_RSA
        ]);
$public_key = openssl_pkey_get_details($key_resource)['key'];

but now only works when explicitly giving a “config” argument pointing to a openssl.cnf.


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

  1. Create new Local site (PHP Version does not seem to matter).
  2. Add a plugin that does the call:
    $key_resource =  openssl_pkey_new([
             "digest_alg" => 'sha512',
             "private_key_bits" => 4096,
             "private_key_type" => OPENSSL_KEYTYPE_RSA
         ]);
    $public_key = openssl_pkey_get_details($key_resource)['key'];
    
  3. See that $key_resource is false and thus openssl_pkey_get_details($key_resource)['key']; returns an error: Uncaught TypeError: openssl_pkey_get_details(): Argument #1 ($key) must be of type OpenSSLAsymmetricKey, bool given

The issue can be fixed using the following steps:

  1. Copy the openssl.cnf from ~\AppData\Roaming\Local\lightning-services\php-8.0.22+6\bin\win64\extras\ssl to a different location (e.g. c:\temp\openssl.cnf)
  2. Edit the call to account for the new location
      $key_resource = openssl_pkey_new([
             "config"=> "c:\\temp\\openssl.cnf",
             "digest_alg" => 'sha512',
             "private_key_bits" => 4096,
             "private_key_type" => OPENSSL_KEYTYPE_RSA
         ]);
    
  3. Verify that $key_resource is no longer false (although it will not be able to create a private key with the using the openssl_pkey_export, but I take it that that’s a problem with the configuration in itself).

System Details

  • Local Version: 7.1.2

  • Operating System (OS) and OS version: Windows 10 (10.0.19045 Build 19045)


Local Logs

Uncaught TypeError: openssl_pkey_get_details(): Argument #1 ($key) must be of type OpenSSLAsymmetricKey, bool given

Hi @Daxez

Just for clarity was this working expectedly before but changed with the update to 7.1.2? Or when did you notice this break in functionality?

Hey @Nick-B,

I’ve tried to pinpoint the version by downgrading back to 6.7.2 and working up. Around the last week of June I’ve used the specific code extensively, not running into problems. I get the error now on earlier versions as well.

One thing that strikes me though, is that in the phpinfo I can see a path to C:\Program Files\Common Files\SSL/openssl.cnf, which seems off and is non-existent. I think I saw another post about this as well when trying to sync with some host (could’ve been WPMuDev, let me see if I can find it and I’ll link it).

The other thing I find interesting is that if I reference the .cnf in the lightning services folder in the local appdata folder through the config parameter, it will generate keyinfo but refuses to generate a private key.

Not sure what the real cause of the problem was, but I created an openssl.cnf in C:\Program Files\Common Files\SSL and that seems to have fixed the problem.

So for anyone running into this issue, default openssl.cnf files can be found on the OpenSSL github or check the Local folder on your machine found (given Windows 10 - 64 bit) at C:\Users\{Your user name}\AppData\Roaming\Local\lightning-services\php-{someversion}\bin\win64\extras\ssl.

1 Like

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.