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