LTI not working in 4.5 on Windows

LTI not working in 4.5 on Windows

Christoph Künkel írta időpontban
Válaszok szám: 1

Not sure if this is the right place, so forgive me if not.

I was trying to implement LTI sharing (both ends) in my all-new moodle 4.5 installation.  This failed just exactly as described in https://moodle.org/mod/forum/discuss.php?d=433995. This is because on my windows, the default ssl config file directory is underneath the PHP installation directory where I certainly do not want to allow access for the IUSR user (which is the one IIS happens to run with). 

However, the proposed fix (setting $CFG->opensslcnf) doesn't work as this configuration option is used inconsistently in moodle 4.5.

It works as expected for mnet, as there is the following code there (e.g. mnet/lib.php):

  if (!empty($CFG->opensslcnf)) { 
//allow specification of openssl.cnf especially for Windows installs $new_key = openssl_pkey_new(array("config" => $CFG->opensslcnf)); } else { $new_key = openssl_pkey_new(); }

However, in all other places, $CFG->opensslcnf is not used. For example (mod\lti\upgradelib.php):

        $config = array(
            "digest_alg" => "sha256",
            "private_key_bits" => 2048,
            "private_key_type" => OPENSSL_KEYTYPE_RSA,
        );
        $res = openssl_pkey_new($config);

I did not see another solution than patching the core source: 

$config = [
    "digest_alg" => "sha256",
"private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA, ] + (empty($CFG->opensslcnf) ? [] : ["config" => $CFG->opensslcnf]);

I would suggest that all occurences of openssl_pkey_new(), openssl_csr_new(), openssl_csr_sign(), openssl_pkcs12_export() and openssl_pkcs12_create() should be fixed accordingly. 

Or is there a better solution I overlooked?

Regards, Christoph

PS: I also tried to set windows global environment OPENSSL_CONF but it did not work and also, I wouldn't want to change the value for all applications running on my host

Értékelések átlaga: -
Válasz erre: Christoph Künkel

Re: LTI not working in 4.5 on Windows

Christoph Künkel írta időpontban
Unfortunately I was too quick to post this. Although my proposed solution works for the call to openssl_pkey_new(), it subsequently fails for the call to openssl_sign() in lib\php-jwt\src\JWT.php. This function does not have a $config option.

Ok, then bite the bullet I thought and gave the web server access to the default path (which I apparently can't change). Then, the calls to openssl_pkey_new() work without providing the "config" member in $conf. 

However, the call to openssl_sign() now fails with a new/different error code returned by openssl_error_string():
 
error:24070079:random number generator:RAND_write_file:Cannot open file
 
I have no idea where this file is meant to be created. As it seems to be a temporary file, I checked both $_SERVER['TMP'] and $_SERVER['TEMP'] but both exist and are writable to the web server.
 
Any help appreciated, Christoph