df31d30974e1836d14e8cbbf14840b356e2d5211
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / hooks / class.tx_rsaauth_loginformhook.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 provides a hook to the login form to add extra javascript code
28 * and supply a proper form tag.
29 *
30 * @author Dmitry Dulepov <dmitry@typo3.org>
31 * @package TYPO3
32 * @subpackage tx_rsaauth
33 */
34 class tx_rsaauth_loginformhook {
35
36 /**
37 * Adds RSA-specific JavaScript and returns a form tag
38 *
39 * @return string Form tag
40 */
41 public function getLoginFormTag(array $params, SC_index& $pObj) {
42 $form = NULL;
43 if ($pObj->loginSecurityLevel == 'rsa') {
44
45 // If we can get the backend, we can proceed
46 $backend = tx_rsaauth_backendfactory::getBackend();
47 if (!is_null($backend)) {
48
49 // Add form tag
50 $form = '<form action="index.php" method="post" name="loginform" onsubmit="tx_rsaauth_encrypt();">';
51
52 // Generate a new key pair
53 $keyPair = $backend->createNewKeyPair();
54
55 // Save private key
56 $storage = tx_rsaauth_storagefactory::getStorage();
57 /* @var $storage tx_rsaauth_abstract_storage */
58 $storage->put($keyPair->getPrivateKey());
59
60 // Add RSA hidden fields
61 $form .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
62 $form .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
63 }
64 }
65 return $form;
66 }
67
68
69 /**
70 * Provides form code for the superchallenged authentication.
71 *
72 * @param array $params Parameters to the script
73 * @param SC_index $pObj Calling object
74 * @return string The code for the login form
75 */
76 public function getLoginScripts(array $params, SC_index &$pObj) {
77 $content = '';
78
79 if ($pObj->loginSecurityLevel == 'rsa') {
80 $javascriptPath = t3lib_extMgm::siteRelPath('rsaauth') . 'resources/';
81 $files = array(
82 'jsbn/jsbn.js',
83 'jsbn/prng4.js',
84 'jsbn/rng.js',
85 'jsbn/rsa.js',
86 'jsbn/base64.js',
87 'rsaauth_min.js'
88 );
89
90 $content = '';
91 foreach ($files as $file) {
92 $content .= '<script type="text/javascript" src="' .
93 t3lib_div::getIndpEnv('TYPO3_SITE_URL') .
94 $javascriptPath . $file . '"></script>';
95 }
96 }
97
98 return $content;
99 }
100 }
101
102 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_loginformhook.php'])) {
103 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_loginformhook.php']);
104 }
105
106 ?>