diff --git a/mod/lti/OAuth.php b/mod/lti/OAuth.php index 762d236ae72..3147692dd06 100644 --- a/mod/lti/OAuth.php +++ b/mod/lti/OAuth.php @@ -265,6 +265,11 @@ class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { // Sign using the key $ok = openssl_sign($base_string, $signature, $privatekeyid); + // Avoid passing null values to base64_encode. + if (!$ok) { + throw new OAuthException("OpenSSL unable to sign data"); + } + // TODO: Remove this block once PHP 8.0 becomes required. if (PHP_MAJOR_VERSION < 8) { // Release the key resource diff --git a/mod/lti/classes/local/ltiopenid/jwks_helper.php b/mod/lti/classes/local/ltiopenid/jwks_helper.php index 8c9ed6217f3..56cb474d7a4 100644 --- a/mod/lti/classes/local/ltiopenid/jwks_helper.php +++ b/mod/lti/classes/local/ltiopenid/jwks_helper.php @@ -73,6 +73,11 @@ class jwks_helper { $res = openssl_pkey_get_private($privatekey['key']); $details = openssl_pkey_get_details($res); + // Avoid passing null values to base64_encode. + if (!isset($details['rsa']['e']) || !isset($details['rsa']['n'])) { + throw new \moodle_exception('Error: essential openssl keys not set'); + } + $jwk = array(); $jwk['kty'] = 'RSA'; $jwk['alg'] = 'RS256';