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