MDL-78072 core: Skip mobile encryption if Sodium is not available

This commit is contained in:
Andrew Nicols 2023-05-09 12:35:00 +08:00
parent d838917d28
commit a1b37845a8
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 11 additions and 6 deletions

View File

@ -24,7 +24,6 @@
* @since Moodle 2.7
*/
require_once($CFG->dirroot . '/message/output/lib.php');
/**
@ -109,6 +108,8 @@ class message_output_airnotifier extends message_output {
// We are sending to message to all devices.
$airnotifiermanager = new message_airnotifier_manager();
$devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $eventdata->userto->id);
$skipsend = $encryptnotifications && $encryptprocessing == message_airnotifier_manager::ENCRYPT_UNSUPPORTED_NOT_SEND;
$encryptionavailable = \core\encryption::is_sodium_installed();
foreach ($devicetokens as $devicetoken) {
if (!$devicetoken->enable) {
@ -116,10 +117,11 @@ class message_output_airnotifier extends message_output {
}
// Check if we should skip sending the notification.
if ($encryptnotifications && empty($devicetoken->publickey) &&
$encryptprocessing == message_airnotifier_manager::ENCRYPT_UNSUPPORTED_NOT_SEND) {
continue; // Avoid sending notifications to devices not supporting encryption.
if ($skipsend) {
// If encryption is not available, do not send notifications.
if (!$encryptionavailable || ($encryptnotifications && empty($devicetoken->publickey))) {
continue;
}
}
// Sending the message to the device.
@ -173,7 +175,7 @@ class message_output_airnotifier extends message_output {
return $payload;
}
if (empty($devicetoken->publickey)) {
if (empty($devicetoken->publickey)|| !\core\encryption::is_sodium_installed()) {
$payload->encrypted = false;
return $payload;
}

View File

@ -23,8 +23,10 @@ use stdClass;
*
* @package core_user
* @covers \core_user\devicekey
* @requires extension sodium
*/
class devicekey_test extends \advanced_testcase {
/**
* Helper to create a device record.
*

View File

@ -29,6 +29,7 @@ use stdClass;
*
* @package core_user
* @covers \core_user\external\update_user_device_public_key
* @requires extension sodium
*/
class update_user_device_public_key_test extends \advanced_testcase {
/**