/** @var AccountManager */
private $accountManager;
+ /** @var string */
+ protected $certPath;
+
/**
* SyncService constructor.
*
$this->userManager = $userManager;
$this->logger = $logger;
$this->accountManager = $accountManager;
+
+ $certManager = \OC::$server->getCertificateManager(null);
+ $certPath = $certManager->getAbsoluteBundlePath();
+ if (file_exists($certPath)) {
+ $this->certPath = $certPath;
+ }
}
/**
* @param string $url
* @param string $userName
* @param string $sharedSecret
- * @param string $syncToken
- * @return array
+ * @return Client
*/
- protected function requestSyncReport($url, $userName, $sharedSecret, $syncToken) {
+ protected function getClient($url, $userName, $sharedSecret) {
$settings = [
'baseUri' => $url . '/',
'userName' => $userName,
$client = new Client($settings);
$client->setThrowExceptions(true);
+ if (strpos($url, 'http://') !== 0 && $this->certPath) {
+ $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
+ }
+
+ return $client;
+ }
+
+ /**
+ * @param string $url
+ * @param string $userName
+ * @param string $sharedSecret
+ * @param string $syncToken
+ * @return array
+ */
+ protected function requestSyncReport($url, $userName, $sharedSecret, $syncToken) {
+ $client = $this->getClient($url, $userName, $sharedSecret);
+
$addressBookUrl = "remote.php/dav/addressbooks/system/system/system";
$body = $this->buildSyncCollectionRequestBody($syncToken);
'Content-Type' => 'application/xml'
]);
- $result = $this->parseMultiStatus($response['body']);
-
- return $result;
+ return $this->parseMultiStatus($response['body']);
}
/**
* @return array
*/
protected function download($url, $sharedSecret, $resourcePath) {
- $settings = [
- 'baseUri' => $url,
- 'userName' => 'system',
- 'password' => $sharedSecret,
- ];
- $client = new Client($settings);
- $client->setThrowExceptions(true);
-
- $response = $client->request('GET', $resourcePath);
- return $response;
+ $client = $this->getClient($url, 'system', $sharedSecret);
+ return $client->request('GET', $resourcePath);
}
/**