Skip to content

Commit

Permalink
Makes sure password hasn't expired when verifying a share's password.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
StCyr committed Mar 6, 2022
1 parent 71ae5a0 commit 9ef1c59
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 109 deletions.
1 change: 0 additions & 1 deletion apps/files_sharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Turning the feature off removes shared files and folders on the server for all s
<job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
<job>OCA\Files_Sharing\ExpireSharesJob</job>
<job>OCA\Files_Sharing\BackgroundJob\FederatedSharesDiscoverJob</job>
<job>OCA\Files_Sharing\BackgroundJob\ResetExpiredPasswordsJob</job>
</background-jobs>

<repair-steps>
Expand Down
108 changes: 0 additions & 108 deletions apps/files_sharing/lib/BackgroundJob/ResetExpiredPasswordsJob.php

This file was deleted.

1 change: 1 addition & 0 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ protected function createShareObject($data) {
$share->setShareTime($shareTime);
$share->setSharedWith($data['share_with']);
$share->setPassword($data['password']);
$share->setPasswordExpirationTime($data['password_expiration_time']);
$share->setLabel($data['label']);
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
$share->setHideDownload((bool)$data['hide_download']);
Expand Down
10 changes: 10 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,16 @@ public function checkPassword(IShare $share, $password) {
return false;
}

// Makes sure password hasn't expired
$expirationTime = $share->getPasswordExpirationTime();
if ($expirationTime !== null) {
$expirationDateTime = new \DateTime($expirationTime);
$now = new \DateTime();
if ($expirationDateTime < $now) {
return false;
}
}

$newHash = '';
if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
return false;
Expand Down
17 changes: 17 additions & 0 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Share implements IShare {
private $expireDate;
/** @var string */
private $password;
/** @var string */
private $passwordExpirationTime;
/** @var bool */
private $sendPasswordByTalk = false;
/** @var string */
Expand Down Expand Up @@ -461,6 +463,21 @@ public function getPassword() {
return $this->password;
}

/**
* @inheritdoc
*/
public function setPasswordExpirationTime($passwordExpirationTime) {
$this->passwordExpirationTime = $passwordExpirationTime;
return $this;
}

/**
* @inheritdoc
*/
public function getPasswordExpirationTime() {
return $this->passwordExpirationTime;
}

/**
* @inheritdoc
*/
Expand Down
13 changes: 13 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,19 @@ public function setPassword($password);
*/
public function getPassword();

/**
* Set the password's expiration time of this share.
*
* @return \OCP\Share\IShare The modified object
*/
public function setPasswordExpirationTime($passwordExpirationTime);

/**
* Get the password's expiration time of this share.
*
* @return string
*/
public function getPasswordExpirationTime();

/**
* Set if the recipient can start a conversation with the owner to get the
Expand Down

0 comments on commit 9ef1c59

Please sign in to comment.