[BUGFIX] Login fails silently, when no backend for rsaauth is available
[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 } else {
64 throw new t3lib_error_Exception(
65 'No OpenSSL backend could be obtained for rsaauth.',
66 1318283565
67 );
68 }
69 }
70 return $form;
71 }
72
73
74 /**
75 * Provides form code for the superchallenged authentication.
76 *
77 * @param array $params Parameters to the script
78 * @param SC_index $pObj Calling object
79 * @return string The code for the login form
80 */
81 public function getLoginScripts(array $params, SC_index &$pObj) {
82 $content = '';
83
84 if ($pObj->loginSecurityLevel == 'rsa') {
85 $javascriptPath = t3lib_extMgm::siteRelPath('rsaauth') . 'resources/';
86 $files = array(
87 'jsbn/jsbn.js',
88 'jsbn/prng4.js',
89 'jsbn/rng.js',
90 'jsbn/rsa.js',
91 'jsbn/base64.js',
92 'rsaauth_min.js'
93 );
94
95 $content = '';
96 foreach ($files as $file) {
97 $content .= '<script type="text/javascript" src="' .
98 t3lib_div::getIndpEnv('TYPO3_SITE_URL') .
99 $javascriptPath . $file . '"></script>';
100 }
101 }
102
103 return $content;
104 }
105 }
106
107 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_loginformhook.php'])) {
108 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_loginformhook.php']);
109 }
110
111 ?>