7e0ec5b7de3af51d36b7582df8f7482bef20e1ac
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / sv1 / backends / class.tx_rsaauth_abstract_backend.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/backends/class.tx_rsaauth_keypair.php'));
26
27 /**
28 * This class contains an abstract SSL backend for the TYPO3 RSA authentication
29 * service.
30 *
31 * There are two steps:
32 * - prepare data for encoding
33 * - decode incoming data
34 *
35 * To prepare data for encoding, the createNewKeyPair() method should be called.
36 * This method returns an instance of tx_rsaauth_keypair class, which contains
37 * the private and public keys. Public key is sent to the client to encode data.
38 * Private key should be stored somewhere (preferrably in user's session).
39 *
40 * To decode data, the decrypt() method should be called with the private key
41 * created at the previous step and the data to decode. If the data is decoded
42 * successfully, the result is a string. Otherwise it is NULL.
43 *
44 * @author Dmitry Dulepov <dmitry@typo3.org>
45 * @package TYPO3
46 * @subpackage tx_rsaauth
47 */
48 abstract class tx_rsaauth_abstract_backend {
49
50 /**
51 * Error message for the last operation. Derieved classes should always set
52 * or clear this variable inside the createNewKeyPair() or decypt().
53 *
54 * @var string
55 */
56 protected $error = '';
57
58 /**
59 * Creates a new key pair for the encryption.
60 *
61 * @return tx_rsaauth_keypair A new key pair or NULL in case of error
62 */
63 abstract public function createNewKeyPair();
64
65 /**
66 * Decripts the data using the private key.
67 *
68 * @param string $privateKey The private key (obtained from a call to createNewKeyPair())
69 * @param string $data Data to decrypt (base64-encoded)
70 * @return string Decrypted data or NULL in case of a error
71 */
72 abstract public function decrypt($privateKey, $data);
73
74 /**
75 * Checks if this backend is available for calling.
76 *
77 * @return void
78 */
79 abstract public function isAvailable();
80
81 /**
82 * Retrieves a error message.
83 *
84 * @return string A error message or empty string if there were no error
85 */
86 public function getLastError() {
87 return $this->error;
88 }
89 }
90
91 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backend/class.tx_rsaauth_abstract_backend.php'])) {
92 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/backend/class.tx_rsaauth_abstract_backend.php']);
93 }
94
95 ?>