Index: branches/5.2.x/core/units/helpers/curl_helper.php =================================================================== diff -u -r16752 -r16790 --- branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 16752) +++ branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 16790) @@ -1,6 +1,6 @@ debugMode = kUtil::constOn('DBG_CURL'); + + $this->_resetSettings(); } /** @@ -164,6 +174,8 @@ $this->requestHeaders = Array (); $this->responseHeaders = Array (); $this->options = Array (); + $this->sslCertificatesFile = CaBundle::getSystemCaRootBundlePath(); + $this->verifySslCertificate = true; } /** @@ -206,14 +218,20 @@ CURLOPT_REFERER => PROTOCOL.SERVER_NAME, CURLOPT_MAXREDIRS => 5, - // don't verify SSL certificates - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_SSL_VERIFYHOST => false, - // Prevents CURL from adding "Expect: 100-continue" header for POST requests. CURLOPT_HTTPHEADER => Array ('Expect:'), ); + if ( $this->verifySslCertificate ) { + $default_options[CURLOPT_SSL_VERIFYHOST] = 2; + $default_options[CURLOPT_SSL_VERIFYPEER] = true; + $default_options[CURLOPT_CAINFO] = $this->sslCertificatesFile; + } + else { + $default_options[CURLOPT_SSL_VERIFYHOST] = false; + $default_options[CURLOPT_SSL_VERIFYPEER] = false; + } + if ( isset($_SERVER['HTTP_USER_AGENT']) ) { $default_options[CURLOPT_USERAGENT] = $_SERVER['HTTP_USER_AGENT']; } @@ -340,6 +358,37 @@ } /** + * Disables SSL certificate validation. + * + * @return void + */ + public function disableSslCertificateVerification() + { + $this->verifySslCertificate = false; + } + + /** + * Enable SSL certificate validation. + * + * @param string|null $certificates_file Certificates file. + * + * @return void + * @throws RuntimeException When given certificates file doesn't exist on disk. + */ + public function enableSslCertificateVerification($certificates_file = null) + { + $this->verifySslCertificate = true; + + if ( $certificates_file !== null ) { + if ( !file_exists($certificates_file) ) { + throw new RuntimeException('The "' . $certificates_file . '" file does not exist.'); + } + + $this->sslCertificatesFile = $certificates_file; + } + } + + /** * Performs CURL request and returns it's result * * @param string $url