741c7f655691e4741a3009c494e2b3ec9ddb5918
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Hook / FrontendLoginHook.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 contains a hook to implement RSA authentication for the TYPO3
28 * Frontend. Warning: felogin must be USER_INT for this to work!
29 *
30 * @author Dmitry Dulepov <dmitry@typo3.org>
31 */
32 class FrontendLoginHook {
33
34 /**
35 * Hooks to the felogin extension to provide additional code for FE login
36 *
37 * @return array 0 => onSubmit function, 1 => extra fields and required files
38 */
39 public function loginFormHook() {
40 $result = array(0 => '', 1 => '');
41 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel']) === 'rsa') {
42 $backend = \TYPO3\CMS\Rsaauth\Backend\BackendFactory::getBackend();
43 if ($backend) {
44 $result[0] = 'tx_rsaauth_feencrypt(this);';
45 $javascriptPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('rsaauth') . 'resources/';
46 $files = array(
47 'jsbn/jsbn.js',
48 'jsbn/prng4.js',
49 'jsbn/rng.js',
50 'jsbn/rsa.js',
51 'jsbn/base64.js',
52 'rsaauth_min.js'
53 );
54
55 $additionalHeader = '';
56 foreach ($files as $file) {
57 $additionalHeader .= '<script type="text/javascript" src="' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $javascriptPath . $file . '"></script>';
58 }
59 $GLOBALS['TSFE']->additionalHeaderData['rsaauth_js'] = $additionalHeader;
60
61 // Generate a new key pair
62 $keyPair = $backend->createNewKeyPair();
63 // Save private key
64 $storage = \TYPO3\CMS\Rsaauth\Storage\StorageFactory::getStorage();
65 /** @var $storage \TYPO3\CMS\Rsaauth\Storage\AbstractStorage */
66 $storage->put($keyPair->getPrivateKey());
67 // Add RSA hidden fields
68 $result[1] .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
69 $result[1] .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
70 }
71 }
72 return $result;
73 }
74
75 }