aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2016-02-26 17:02:13 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2016-02-26 20:00:13 +0100
commiteccd7cf6548e1ea639aea48cbf7e52e95dc98c11 (patch)
tree68c58394c820e1ce6bc8eee07e4747875da08be0
parent62d7885c3b13d7d2acf33f80e91016a82cc8a7c0 (diff)
downloadnextcloud-server-eccd7cf6548e1ea639aea48cbf7e52e95dc98c11.tar.gz
nextcloud-server-eccd7cf6548e1ea639aea48cbf7e52e95dc98c11.zip
reuse the url_hash instead of calculating a new hash for the address book
-rw-r--r--apps/federation/appinfo/database.xml3
-rw-r--r--apps/federation/lib/dbhandler.php6
-rw-r--r--apps/federation/lib/syncfederationaddressbooks.php2
-rw-r--r--apps/federation/tests/lib/dbhandlertest.php14
-rw-r--r--apps/federation/tests/lib/syncfederationaddressbookstest.php2
5 files changed, 14 insertions, 13 deletions
diff --git a/apps/federation/appinfo/database.xml b/apps/federation/appinfo/database.xml
index 05b7fb12b49..61c3b8ac6d8 100644
--- a/apps/federation/appinfo/database.xml
+++ b/apps/federation/appinfo/database.xml
@@ -27,8 +27,7 @@
<type>text</type>
<default></default>
<notnull>true</notnull>
- <length>32</length>
- <comments>md5 hash of the url without the protocol</comments>
+ <comments>sha1 hash of the url without the protocol</comments>
</field>
<field>
<name>token</name>
diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php
index 3ea84baa3eb..df36228c760 100644
--- a/apps/federation/lib/dbhandler.php
+++ b/apps/federation/lib/dbhandler.php
@@ -112,7 +112,7 @@ class DbHandler {
*/
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 +252,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..886f6505b20 100644
--- a/apps/federation/lib/syncfederationaddressbooks.php
+++ b/apps/federation/lib/syncfederationaddressbooks.php
@@ -40,7 +40,7 @@ class SyncFederationAddressBooks {
if (is_null($sharedSecret)) {
continue;
}
- $targetBookId = sha1($url);
+ $targetBookId = $trustedServer['url_hash'];
$targetPrincipal = "principals/system/system";
$targetBookProperties = [
'{DAV:}displayname' => $url
diff --git a/apps/federation/tests/lib/dbhandlertest.php b/apps/federation/tests/lib/dbhandlertest.php
index 6fe5d9ea8ef..ee28da8e02a 100644
--- a/apps/federation/tests/lib/dbhandlertest.php
+++ b/apps/federation/tests/lib/dbhandlertest.php
@@ -89,9 +89,9 @@ class DbHandlerTest extends TestCase {
public function dataTestAddServer() {
return [
- ['http://owncloud.org', 'http://owncloud.org', md5('owncloud.org')],
- ['https://owncloud.org', 'https://owncloud.org', md5('owncloud.org')],
- ['http://owncloud.org/', 'http://owncloud.org', md5('owncloud.org')],
+ ['http://owncloud.org', 'http://owncloud.org', sha1('owncloud.org')],
+ ['https://owncloud.org', 'https://owncloud.org', sha1('owncloud.org')],
+ ['http://owncloud.org/', 'http://owncloud.org', sha1('owncloud.org')],
];
}
@@ -233,10 +233,10 @@ class DbHandlerTest extends TestCase {
public function dataTestHash() {
return [
- ['server1', md5('server1')],
- ['http://server1', md5('server1')],
- ['https://server1', md5('server1')],
- ['http://server1/', md5('server1')],
+ ['server1', sha1('server1')],
+ ['http://server1', sha1('server1')],
+ ['https://server1', sha1('server1')],
+ ['http://server1/', sha1('server1')],
];
}
diff --git a/apps/federation/tests/lib/syncfederationaddressbookstest.php b/apps/federation/tests/lib/syncfederationaddressbookstest.php
index 770896535fa..9290bad8bd6 100644
--- a/apps/federation/tests/lib/syncfederationaddressbookstest.php
+++ b/apps/federation/tests/lib/syncfederationaddressbookstest.php
@@ -19,6 +19,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
willReturn([
[
'url' => 'https://cloud.drop.box',
+ 'url_hash' => 'sha1',
'shared_secret' => 'iloveowncloud',
'sync_token' => '0'
]
@@ -47,6 +48,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
willReturn([
[
'url' => 'https://cloud.drop.box',
+ 'url_hash' => 'sha1',
'shared_secret' => 'iloveowncloud',
'sync_token' => '0'
]