-
-
Notifications
You must be signed in to change notification settings - Fork 551
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 #4465 from nilsteampassnet/crypt_session
Crypt session
- Loading branch information
Showing
14 changed files
with
257 additions
and
67 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
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
86 changes: 86 additions & 0 deletions
86
includes/libraries/teampassclasses/sessionmanager/src/EncryptedSessionProxy.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,86 @@ | ||
<?php | ||
namespace TeampassClasses\SessionManager; | ||
|
||
/** | ||
* Teampass - a collaborative passwords manager. | ||
* --- | ||
* This file is part of the TeamPass project. | ||
* | ||
* TeamPass is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3 of the License. | ||
* | ||
* TeamPass 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* Certain components of this file may be under different licenses. For | ||
* details, see the `licenses` directory or individual file headers. | ||
* --- | ||
* @file EncryptedSessionProxy.php | ||
* @author Nils Laumaillé ([email protected]) | ||
* @copyright 2009-2024 Teampass.net | ||
* @license GPL-3.0 | ||
* @see https://www.teampass.net | ||
*/ | ||
|
||
use Defuse\Crypto\Crypto; | ||
use Defuse\Crypto\Key; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; | ||
|
||
class EncryptedSessionProxy extends SessionHandlerProxy | ||
{ | ||
protected $handler; | ||
private $key; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \SessionHandlerInterface $handler | ||
* @param Key $key | ||
*/ | ||
public function __construct( | ||
\SessionHandlerInterface $handler, | ||
Key $key | ||
) { | ||
parent::__construct($handler); | ||
$this->key = $key; | ||
} | ||
|
||
/** | ||
* Decrypt the session data after reading it from the session handler. | ||
* | ||
* @param string $id | ||
* | ||
* @return string | ||
*/ | ||
public function read($id): string | ||
{ | ||
$data = parent::read($id); | ||
|
||
if ($data !== '') { | ||
return Crypto::decrypt($data, $this->key); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* Encrypt the session data before writing it to the session handler. | ||
* | ||
* @param string $id | ||
* @param string $data | ||
* | ||
* @return bool | ||
*/ | ||
public function write($id, $data): bool | ||
{ | ||
$data = Crypto::encrypt($data, $this->key); | ||
|
||
return parent::write($id, $data); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.