b9b8c0f9b58b55a4a060005f6d083b1c29dc84f9
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Backend / AbstractBackend.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Backend;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Dmitry Dulepov <dmitry@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This class contains an abstract SSL backend for the TYPO3 RSA authentication
28 * service.
29 *
30 * There are two steps:
31 * - prepare data for encoding
32 * - decode incoming data
33 *
34 * To prepare data for encoding, the createNewKeyPair() method should be called.
35 * This method returns an instance of \TYPO3\CMS\Rsaauth\Keypair class, which contains
36 * the private and public keys. Public key is sent to the client to encode data.
37 * Private key should be stored somewhere (preferably in user's session).
38 *
39 * To decode data, the decrypt() method should be called with the private key
40 * created at the previous step and the data to decode. If the data is decoded
41 * successfully, the result is a string. Otherwise it is NULL.
42 *
43 * @author Dmitry Dulepov <dmitry@typo3.org>
44 */
45 abstract class AbstractBackend {
46
47 /**
48 * Error message for the last operation. Derived classes should always set
49 * or clear this variable inside the createNewKeyPair() or decypt().
50 *
51 * @var string
52 */
53 protected $error = '';
54
55 /**
56 * Creates a new key pair for the encryption or gets the existing key pair (if one already has been generated).
57 *
58 * There should only be one key pair per request because the second private key would overwrites the first private
59 * key. So the submitting the form with the first public key would not work anymore.
60 *
61 * @return \TYPO3\CMS\Rsaauth\Keypair|NULL a 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 }