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