MDL-77840 lti: Avoid passing nulls to base64_encode

This commit is contained in:
David Woloszyn
2023-05-02 13:52:12 +10:00
parent f25ecd9bfa
commit 5ab74afad4
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -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
@@ -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';