-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38376 from owncloud/owncloud-web-password-public-…
…share pre-signed download urls for password protected public links
- Loading branch information
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* @author David Christofas <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2021, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\Files\PublicFiles; | ||
|
||
class PublicShareSigner { | ||
private $token; | ||
private $fileName; | ||
private $validUntil; | ||
private $signingKey; | ||
|
||
public function __construct(String $token, String $fileName, \DateTime $validUntil, String $signingKey) { | ||
$this->token = $token; | ||
$this->fileName = $fileName; | ||
$this->validUntil = $validUntil->format(\DateTime::ATOM); | ||
$this->signingKey = $signingKey; | ||
} | ||
|
||
public function getSignature() { | ||
return \hash_hmac('sha512/256', \implode('|', [$this->token, $this->fileName, $this->validUntil]), $this->signingKey, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
apps/dav/tests/unit/Files/PublicFiles/PublicShareSignerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* @author David Christofas <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2021, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\Tests\Unit\Files\PublicFiles; | ||
|
||
use OCA\DAV\Files\PublicFiles\PublicShareSigner; | ||
use Test\TestCase; | ||
|
||
class PublicShareSignerTest extends TestCase { | ||
public function testGet() { | ||
$s = new PublicShareSigner('someToken', 'someFileName', new \DateTime(), 'somekey'); | ||
$hash = $s->getSignature(); | ||
self::assertIsString($hash); | ||
self::assertEquals(64, \strlen($hash)); | ||
} | ||
|
||
public function testVerify() { | ||
$expectedHash = 'd67966402971bd3eb18aea62faf122a30e2dd5c9101aa9e106a56574cc535c6c'; | ||
$date = \DateTime::createFromFormat(\DateTime::ATOM, '2009-01-03T18:15:05Z'); | ||
$s = new PublicShareSigner('someToken', 'someFileName', $date, 'somekey'); | ||
self::assertEquals($expectedHash, $s->getSignature()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Implement pre-signed download urls for public links | ||
|
||
Added pre-signed download urls for password protected public links to support clients which don't use cookies. | ||
|
||
https://github.com/owncloud/core/pull/38376 |