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