25b4fe3e3e88e3ab194e25f7f656ece00a429c11
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / sv1 / storage / class.tx_rsaauth_session_storage.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Dmitry Dulepov <dmitry@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once(t3lib_extMgm::extPath('rsaauth', 'sv1/storage/class.tx_rsaauth_abstract_storage.php'));
26
27 /**
28 * This class contains a session-based storage for private keys. This storage
29 * is not secure enough because its implementation stores keys completely in the
30 * PHP sessions. PHP sessions usually store data in the file system and it is
31 * easy to extract. This storage is useful only as an example. It is better to
32 * use "split" storage for keys.
33 *
34 * @author Dmitry Dulepov <dmitry@typo3.org>
35 * @package TYPO3
36 * @subpackage tx_rsaauth
37 */
38 class tx_rsaauth_session_storage extends tx_rsaauth_abstract_storage {
39
40 /**
41 * Creates an instance of this class. It checks and initializes PHP
42 * sessions if necessary.
43 *
44 * @return void
45 */
46 public function __construct() {
47 if (!isset($_SESSION) || !is_array($_SESSION)) {
48 session_start();
49 }
50 }
51
52 /**
53 * Obtains key from the session
54 *
55 * @return string The key or NULL
56 * @see tx_rsaauth_abstract_storage::get()
57 */
58 public function get() {
59 return (isset($_SESSION['tx_rsaauth_key']) ? $_SESSION['tx_rsaauth_key'] : NULL);
60 }
61
62 /**
63 * Puts key to the session
64 *
65 * @param string $key The key
66 * @see tx_rsaauth_abstract_storage::put()
67 */
68 public function put($key) {
69 $_SESSION['tx_rsaauth_key'] = $key;
70 }
71 }
72
73 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/storage/class.tx_rsaauth_session_storage.php'])) {
74 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/storage/class.tx_rsaauth_session_storage.php']);
75 }
76
77 ?>