Skip to content

Commit

Permalink
MDL-36903 Verify the SSL certificate of available updates provider
Browse files Browse the repository at this point in the history
From now on, Moodle verifies the available updates provider server. To
make it work, either there must be a valid CA certificate available in
the operating system, or the administrator has to upload the valid CA
certificate to moodledata/moodleorgca.crt (PEM format) file manually.
  • Loading branch information
mudrd8mz committed Nov 30, 2012
1 parent 47dfbd9 commit 4785c45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lang/en/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
$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';
Expand Down
29 changes: 28 additions & 1 deletion lib/pluginlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,11 @@ protected function get_response() {
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']);
Expand Down Expand Up @@ -1069,6 +1073,29 @@ protected function prepare_request_params() {
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
*
Expand Down

0 comments on commit 4785c45

Please sign in to comment.