aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/lib
diff options
context:
space:
mode:
authorC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-01 13:35:14 -0500
committerC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-01 13:35:14 -0500
commitc51a01b43f514fc50c47de1ed78d2bdfb8572621 (patch)
treec191f06bd08833e7b4d70a80ca8d9981c97b3d0d /apps/federation/lib
parent2d68c1b9450d77d21b08fc66436d286996583589 (diff)
parent745fdc48007d5d2f29c62266627731bd0ea0aa3d (diff)
downloadnextcloud-server-c51a01b43f514fc50c47de1ed78d2bdfb8572621.tar.gz
nextcloud-server-c51a01b43f514fc50c47de1ed78d2bdfb8572621.zip
Merge branch 'master' into exclude-custom-data-dir
Diffstat (limited to 'apps/federation/lib')
-rw-r--r--apps/federation/lib/dbhandler.php28
-rw-r--r--apps/federation/lib/syncfederationaddressbooks.php6
-rw-r--r--apps/federation/lib/trustedservers.php16
3 files changed, 45 insertions, 5 deletions
diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php
index 3ea84baa3eb..8720560efc6 100644
--- a/apps/federation/lib/dbhandler.php
+++ b/apps/federation/lib/dbhandler.php
@@ -106,13 +106,35 @@ class DbHandler {
}
/**
+ * get trusted server with given ID
+ *
+ * @param int $id
+ * @return array
+ * @throws \Exception
+ */
+ public function getServerById($id) {
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')->from($this->dbTable)
+ ->where($query->expr()->eq('id', $query->createParameter('id')))
+ ->setParameter('id', $id);
+ $query->execute();
+ $result = $query->execute()->fetchAll();
+
+ if (empty($result)) {
+ throw new \Exception('No Server found with ID: ' . $id);
+ }
+
+ return $result[0];
+ }
+
+ /**
* get all trusted servers
*
* @return array
*/
public function getAllServer() {
$query = $this->connection->getQueryBuilder();
- $query->select(['url', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable);
+ $query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable);
$result = $query->execute()->fetchAll();
return $result;
}
@@ -252,11 +274,11 @@ class DbHandler {
*/
protected function hash($url) {
$normalized = $this->normalizeUrl($url);
- return md5($normalized);
+ return sha1($normalized);
}
/**
- * normalize URL, used to create the md5 hash
+ * normalize URL, used to create the sha1 hash
*
* @param string $url
* @return string
diff --git a/apps/federation/lib/syncfederationaddressbooks.php b/apps/federation/lib/syncfederationaddressbooks.php
index 6419fdddf8e..f9cee9a7137 100644
--- a/apps/federation/lib/syncfederationaddressbooks.php
+++ b/apps/federation/lib/syncfederationaddressbooks.php
@@ -3,6 +3,7 @@
namespace OCA\Federation;
use OCA\DAV\CardDAV\SyncService;
+use OCP\AppFramework\Http;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
@@ -40,7 +41,7 @@ class SyncFederationAddressBooks {
if (is_null($sharedSecret)) {
continue;
}
- $targetBookId = sha1($url);
+ $targetBookId = $trustedServer['url_hash'];
$targetPrincipal = "principals/system/system";
$targetBookProperties = [
'{DAV:}displayname' => $url
@@ -51,6 +52,9 @@ class SyncFederationAddressBooks {
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
}
} catch (\Exception $ex) {
+ if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
+ $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
+ }
$callback($url, $ex);
}
}
diff --git a/apps/federation/lib/trustedservers.php b/apps/federation/lib/trustedservers.php
index 340accfdbdf..6f99a3c6a8c 100644
--- a/apps/federation/lib/trustedservers.php
+++ b/apps/federation/lib/trustedservers.php
@@ -30,6 +30,8 @@ use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
class TrustedServers {
@@ -39,6 +41,8 @@ class TrustedServers {
const STATUS_PENDING = 2;
/** something went wrong, misconfigured server, software bug,... user interaction needed */
const STATUS_FAILURE = 3;
+ /** remote server revoked access */
+ const STATUS_ACCESS_REVOKED = 4;
/** @var dbHandler */
private $dbHandler;
@@ -58,6 +62,9 @@ class TrustedServers {
/** @var IConfig */
private $config;
+ /** @var EventDispatcherInterface */
+ private $dispatcher;
+
/**
* @param DbHandler $dbHandler
* @param IClientService $httpClientService
@@ -65,6 +72,7 @@ class TrustedServers {
* @param IJobList $jobList
* @param ISecureRandom $secureRandom
* @param IConfig $config
+ * @param EventDispatcherInterface $dispatcher
*/
public function __construct(
DbHandler $dbHandler,
@@ -72,7 +80,8 @@ class TrustedServers {
ILogger $logger,
IJobList $jobList,
ISecureRandom $secureRandom,
- IConfig $config
+ IConfig $config,
+ EventDispatcherInterface $dispatcher
) {
$this->dbHandler = $dbHandler;
$this->httpClientService = $httpClientService;
@@ -80,6 +89,7 @@ class TrustedServers {
$this->jobList = $jobList;
$this->secureRandom = $secureRandom;
$this->config = $config;
+ $this->dispatcher = $dispatcher;
}
/**
@@ -154,7 +164,10 @@ class TrustedServers {
* @param int $id
*/
public function removeServer($id) {
+ $server = $this->dbHandler->getServerById($id);
$this->dbHandler->removeServer($id);
+ $event = new GenericEvent($server['url_hash']);
+ $this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event);
}
/**
@@ -222,6 +235,7 @@ class TrustedServers {
*
* @param $status
* @return bool
+ * @throws HintException
*/
protected function checkOwnCloudVersion($status) {
$decoded = json_decode($status, true);