[TASK] Use autoloader in rsaauth system extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / hooks / class.tx_rsaauth_feloginhook.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
26 /**
27 * This class contains a hook to implement RSA authentication for the TYPO3
28 * Frontend. Warning: felogin must be USER_INT for this to work!
29 *
30 * @author Dmitry Dulepov <dmitry@typo3.org>
31 * @package TYPO3
32 * @subpackage tx_rsaauth
33 */
34 class tx_rsaauth_feloginhook {
35
36 /**
37 * Hooks to the felogin extension to provide additional code for FE login
38 *
39 * @return array 0 => onSubmit function, 1 => extra fields and required files
40 */
41 public function loginFormHook() {
42 $result = array(0 => '', 1 => '');
43
44 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel'] == 'rsa') {
45 $backend = tx_rsaauth_backendfactory::getBackend();
46 if ($backend) {
47 $result[0] = 'tx_rsaauth_feencrypt(this);';
48
49 $javascriptPath = t3lib_extMgm::siteRelPath('rsaauth') . 'resources/';
50 $files = array(
51 'jsbn/jsbn.js',
52 'jsbn/prng4.js',
53 'jsbn/rng.js',
54 'jsbn/rsa.js',
55 'jsbn/base64.js',
56 'rsaauth_min.js'
57 );
58
59 foreach ($files as $file) {
60 $result[1] .= '<script type="text/javascript" src="' .
61 t3lib_div::getIndpEnv('TYPO3_SITE_URL') .
62 $javascriptPath . $file . '"></script>';
63 }
64
65 // Generate a new key pair
66 $keyPair = $backend->createNewKeyPair();
67
68 // Save private key
69 $storage = tx_rsaauth_storagefactory::getStorage();
70 /* @var $storage tx_rsaauth_abstract_storage */
71 $storage->put($keyPair->getPrivateKey());
72
73 // Add RSA hidden fields
74 $result[1] .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
75 $result[1] .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
76 }
77 }
78 return $result;
79 }
80
81 }
82
83 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_feloginhook.php'])) {
84 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_feloginhook.php']);
85 }
86
87 ?>