TYPO3 API  SVNRelease
class.tx_rsaauth_feloginhook.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Dmitry Dulepov <dmitry@typo3.org>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * [CLASS/FUNCTION INDEX of SCRIPT]
00027  *
00028  * $Id: class.tx_rsaauth_feloginhook.php 10120 2011-01-18 20:03:36Z ohader $
00029  */
00030 
00031 require_once(t3lib_extMgm::extPath('rsaauth') . 'sv1/backends/class.tx_rsaauth_backendfactory.php');
00032 require_once(t3lib_extMgm::extPath('rsaauth') . 'sv1/storage/class.tx_rsaauth_storagefactory.php');
00033 
00034 /**
00035  * This class contains a hook to implement RSA authentication for the TYPO3
00036  * Frontend. Warning: felogin must be USER_INT for this to work!
00037  *
00038  * @author  Dmitry Dulepov <dmitry@typo3.org>
00039  * @package TYPO3
00040  * @subpackage  tx_rsaauth
00041  */
00042 class tx_rsaauth_feloginhook {
00043 
00044     /**
00045      * Hooks to the felogin extension to provide additional code for FE login
00046      *
00047      * @return  array   0 => onSubmit function, 1 => extra fields and required files
00048      */
00049     public function loginFormHook() {
00050         $result = array(0 => '', 1 => '');
00051 
00052         if ($GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel'] == 'rsa') {
00053             $backend = tx_rsaauth_backendfactory::getBackend();
00054             if ($backend) {
00055                 $result[0] = 'tx_rsaauth_feencrypt(this);';
00056 
00057                 $javascriptPath = t3lib_extMgm::siteRelPath('rsaauth') . 'resources/';
00058                 $files = array(
00059                     'jsbn/jsbn.js',
00060                     'jsbn/prng4.js',
00061                     'jsbn/rng.js',
00062                     'jsbn/rsa.js',
00063                     'jsbn/base64.js',
00064                     'rsaauth_min.js'
00065                 );
00066 
00067                 foreach ($files as $file) {
00068                     $result[1] .= '<script type="text/javascript" src="' .
00069                         t3lib_div::getIndpEnv('TYPO3_SITE_URL') .
00070                         $javascriptPath . $file . '"></script>';
00071                 }
00072 
00073                 // Generate a new key pair
00074                 $keyPair = $backend->createNewKeyPair();
00075 
00076                 // Save private key
00077                 $storage = tx_rsaauth_storagefactory::getStorage();
00078                 /* @var $storage tx_rsaauth_abstract_storage */
00079                 $storage->put($keyPair->getPrivateKey());
00080 
00081                 // Add RSA hidden fields
00082                 $result[1] .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
00083                 $result[1] .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
00084             }
00085         }
00086         return $result;
00087     }
00088 
00089 }
00090 
00091 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_feloginhook.php'])) {
00092     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/hooks/class.tx_rsaauth_feloginhook.php']);
00093 }
00094 
00095 ?>