From 5ab74afad40c3ea605255cefc2d7d9eb2ec3e994 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 27 Apr 2023 14:50:40 +1000 Subject: [PATCH] MDL-77840 lti: Avoid passing nulls to base64_encode --- mod/lti/OAuth.php | 5 +++++ mod/lti/classes/local/ltiopenid/jwks_helper.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mod/lti/OAuth.php b/mod/lti/OAuth.php index dde625452a3..5fb77603a62 100644 --- a/mod/lti/OAuth.php +++ b/mod/lti/OAuth.php @@ -262,6 +262,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';