diff --git a/lang/en/plugin.php b/lang/en/plugin.php index f21667ff020..e9712348fa6 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -30,7 +30,9 @@ $string['availability'] = 'Availability'; $string['checkforupdates'] = 'Check for available updates'; $string['checkforupdateslast'] = 'Last check done on {$a}'; $string['displayname'] = 'Plugin name'; +$string['err_response_curl'] = 'Unable to fetch available updates data - unexpected cURL error.'; $string['err_response_format_version'] = 'Unexpected version of the response format. Please try to re-check for available updates.'; +$string['err_response_http_code'] = 'Unable to fetch available updates data - unexpected HTTP response code.'; $string['filterall'] = 'Show all'; $string['filtercontribonly'] = 'Show contributions only'; $string['filtercontribonlyactive'] = 'Showing contributions only'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 7383d7b8898..6feda47da97 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -826,7 +826,11 @@ class available_update_checker { require_once($CFG->libdir.'/filelib.php'); $curl = new curl(array('proxy' => true)); - $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params()); + $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params(), $this->prepare_request_options()); + $curlerrno = $curl->get_errno(); + if (!empty($curlerrno)) { + throw new available_update_checker_exception('err_response_curl', 'cURL error '.$curlerrno.': '.$curl->error); + } $curlinfo = $curl->get_info(); if ($curlinfo['http_code'] != 200) { throw new available_update_checker_exception('err_response_http_code', $curlinfo['http_code']); @@ -1069,6 +1073,29 @@ class available_update_checker { return $params; } + /** + * Returns the list of cURL options to use when fetching available updates data + * + * @return array of (string)param => (string)value + */ + protected function prepare_request_options() { + global $CFG; + + $options = array( + 'CURLOPT_SSL_VERIFYHOST' => 2, // this is the default in {@link curl} class but just in case + 'CURLOPT_SSL_VERIFYPEER' => true, + ); + + $cacertfile = $CFG->dataroot.'/moodleorgca.crt'; + if (is_readable($cacertfile)) { + // Do not use CA certs provided by the operating system. Instead, + // use this CA cert to verify the updates provider. + $options['CURLOPT_CAINFO'] = $cacertfile; + } + + return $options; + } + /** * Returns the current timestamp *