[CLEANUP] Remove security_level option from Authentications
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Hook / LoginFormHook.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Dmitry Dulepov <dmitry@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
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 */
32 class LoginFormHook {
33
34 /**
35 * Adds RSA-specific JavaScript and returns a form tag
36 *
37 * @param array $params
38 * @param \TYPO3\CMS\Backend\Controller\LoginController $pObj
39 * @return string Form tag
40 * @throws \TYPO3\CMS\Core\Error\Exception
41 */
42 public function getLoginFormTag(array $params, \TYPO3\CMS\Backend\Controller\LoginController &$pObj) {
43 $form = NULL;
44 if ($pObj->loginSecurityLevel == 'rsa') {
45 // If we can get the backend, we can proceed
46 $backend = \TYPO3\CMS\Rsaauth\Backend\BackendFactory::getBackend();
47 if (!is_null($backend)) {
48 // Add form tag
49 $form = '<form action="index.php" method="post" name="loginform" onsubmit="tx_rsaauth_encrypt();">';
50 // Generate a new key pair
51 $keyPair = $backend->createNewKeyPair();
52 // Save private key
53 $storage = \TYPO3\CMS\Rsaauth\Storage\StorageFactory::getStorage();
54 /** @var $storage \TYPO3\CMS\Rsaauth\Storage\AbstractStorage */
55 $storage->put($keyPair->getPrivateKey());
56 // Add RSA hidden fields
57 $form .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
58 $form .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
59 } else {
60 throw new \TYPO3\CMS\Core\Error\Exception('No OpenSSL backend could be obtained for rsaauth.', 1318283565);
61 }
62 }
63 return $form;
64 }
65
66 /**
67 * Provides form code for the superchallenged authentication.
68 *
69 * @param array $params Parameters to the script
70 * @param \TYPO3\CMS\Backend\Controller\LoginController $pObj Calling object
71 * @return string The code for the login form
72 */
73 public function getLoginScripts(array $params, \TYPO3\CMS\Backend\Controller\LoginController &$pObj) {
74 $content = '';
75 if ($pObj->loginSecurityLevel == 'rsa') {
76 $javascriptPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('rsaauth') . 'resources/';
77 $files = array(
78 'jsbn/jsbn.js',
79 'jsbn/prng4.js',
80 'jsbn/rng.js',
81 'jsbn/rsa.js',
82 'jsbn/base64.js',
83 'rsaauth_min.js'
84 );
85 $content = '';
86 foreach ($files as $file) {
87 $content .= '<script type="text/javascript" src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $javascriptPath . $file . '"></script>';
88 }
89 }
90 return $content;
91 }
92
93 }