Skip to content

Commit 9ef1c59

Browse files
committed
Makes sure password hasn't expired when verifying a share's password.
This also deletes the ResetExpiredPasswordsJob.php as it is not needed anymore. This commit is part of #31005 Signed-off-by: Cyrille Bollu <cyrpub@bollu.be>
1 parent 71ae5a0 commit 9ef1c59

6 files changed

Lines changed: 41 additions & 109 deletions

File tree

apps/files_sharing/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Turning the feature off removes shared files and folders on the server for all s
3030
<job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
3131
<job>OCA\Files_Sharing\ExpireSharesJob</job>
3232
<job>OCA\Files_Sharing\BackgroundJob\FederatedSharesDiscoverJob</job>
33-
<job>OCA\Files_Sharing\BackgroundJob\ResetExpiredPasswordsJob</job>
3433
</background-jobs>
3534

3635
<repair-steps>

apps/files_sharing/lib/BackgroundJob/ResetExpiredPasswordsJob.php

Lines changed: 0 additions & 108 deletions
This file was deleted.

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ protected function createShareObject($data) {
10331033
$share->setShareTime($shareTime);
10341034
$share->setSharedWith($data['share_with']);
10351035
$share->setPassword($data['password']);
1036+
$share->setPasswordExpirationTime($data['password_expiration_time']);
10361037
$share->setLabel($data['label']);
10371038
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
10381039
$share->setHideDownload((bool)$data['hide_download']);

lib/private/Share20/Manager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,16 @@ public function checkPassword(IShare $share, $password) {
15561556
return false;
15571557
}
15581558

1559+
// Makes sure password hasn't expired
1560+
$expirationTime = $share->getPasswordExpirationTime();
1561+
if ($expirationTime !== null) {
1562+
$expirationDateTime = new \DateTime($expirationTime);
1563+
$now = new \DateTime();
1564+
if ($expirationDateTime < $now) {
1565+
return false;
1566+
}
1567+
}
1568+
15591569
$newHash = '';
15601570
if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
15611571
return false;

lib/private/Share20/Share.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Share implements IShare {
7373
private $expireDate;
7474
/** @var string */
7575
private $password;
76+
/** @var string */
77+
private $passwordExpirationTime;
7678
/** @var bool */
7779
private $sendPasswordByTalk = false;
7880
/** @var string */
@@ -461,6 +463,21 @@ public function getPassword() {
461463
return $this->password;
462464
}
463465

466+
/**
467+
* @inheritdoc
468+
*/
469+
public function setPasswordExpirationTime($passwordExpirationTime) {
470+
$this->passwordExpirationTime = $passwordExpirationTime;
471+
return $this;
472+
}
473+
474+
/**
475+
* @inheritdoc
476+
*/
477+
public function getPasswordExpirationTime() {
478+
return $this->passwordExpirationTime;
479+
}
480+
464481
/**
465482
* @inheritdoc
466483
*/

lib/public/Share/IShare.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ public function setPassword($password);
448448
*/
449449
public function getPassword();
450450

451+
/**
452+
* Set the password's expiration time of this share.
453+
*
454+
* @return \OCP\Share\IShare The modified object
455+
*/
456+
public function setPasswordExpirationTime($passwordExpirationTime);
457+
458+
/**
459+
* Get the password's expiration time of this share.
460+
*
461+
* @return string
462+
*/
463+
public function getPasswordExpirationTime();
451464

452465
/**
453466
* Set if the recipient can start a conversation with the owner to get the

0 commit comments

Comments
 (0)