Fixing Issue #6301 on master branch

Added private var $certPath to store the user root cert

Move logic to determine the $certPath path to the constructor and modify to get the path from OC_User::getHome()

Add curl options to use the certificate to avoid certificate errors with self-signed certicates in the downdload/upload method so we don't get blank files
This commit is contained in:
Carlos Cerrillo 2013-12-15 17:22:52 +01:00
parent 77b68505c2
commit 7c264c88fe

View file

@ -14,6 +14,7 @@ class DAV extends \OC\Files\Storage\Common{
private $host;
private $secure;
private $root;
private $certPath;
private $ready;
/**
* @var \Sabre_DAV_Client
@ -40,6 +41,12 @@ class DAV extends \OC\Files\Storage\Common{
} else {
$this->secure = false;
}
if ($this->secure === true) {
$certPath=\OC_User::getHome(\OC_User::getUser()) . '/files_external/rootcerts.crt';
if (file_exists($certPath)) {
$this->certPath=$certPath;
}
}
$this->root=isset($params['root'])?$params['root']:'/';
if ( ! $this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
@ -66,12 +73,8 @@ class DAV extends \OC\Files\Storage\Common{
$this->client = new \Sabre_DAV_Client($settings);
$caview = \OCP\Files::getStorage('files_external');
if ($caview) {
$certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
if ($this->certPath) {
$this->client->addTrustedCertificates($this->certPath);
}
}
@ -166,6 +169,11 @@ class DAV extends \OC\Files\Storage\Common{
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().str_replace(' ', '%20', $path));
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
if($this->certPath){
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
}
curl_exec ($curl);
curl_close ($curl);
@ -254,6 +262,11 @@ class DAV extends \OC\Files\Storage\Common{
curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($path));
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
if($this->certPath){
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
}
curl_exec ($curl);
curl_close ($curl);
}
@ -331,3 +344,4 @@ class DAV extends \OC\Files\Storage\Common{
}
}
}