TYPO3 CMS  TYPO3_8-7
RsaEncryptionEncoder.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Rsaauth;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
32  protected $moduleLoaded = false;
33 
37  protected $pageRenderer = null;
38 
43  {
44  $this->enableRsaEncryption(true);
45  }
46 
52  public function enableRsaEncryption($useRequireJsModule = false)
53  {
54  if ($this->moduleLoaded || !$this->isAvailable()) {
55  return;
56  }
57  $this->moduleLoaded = true;
58  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
59  // Include necessary javascript files
60  if ($useRequireJsModule) {
61  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Rsaauth/RsaEncryptionModule');
62  } else {
63  // Register ajax handler url
64  $code = 'var TYPO3RsaEncryptionPublicKeyUrl = ' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . 'index.php?eID=RsaPublicKeyGenerationController') . ';';
65  $pageRenderer->addJsInlineCode('TYPO3RsaEncryptionPublicKeyUrl', $code);
66  $javascriptPath = ExtensionManagementUtility::siteRelPath('rsaauth') . 'Resources/Public/JavaScript/';
67  if (!$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['debug']) {
68  $files = ['RsaEncryptionWithLib.min.js'];
69  } else {
70  $files = [
71  'RsaLibrary.js',
72  'RsaEncryption.js',
73  ];
74  }
75  foreach ($files as $file) {
76  $pageRenderer->addJsFile($javascriptPath . $file);
77  }
78  }
79  }
80 
84  public function isAvailable()
85  {
86  return trim($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['loginSecurityLevel']) === 'rsa';
87  }
88 
94  public function getRsaPublicKey()
95  {
96  $keyPair = null;
97  $backend = Backend\BackendFactory::getBackend();
98  if ($backend !== null) {
99  $keyPair = $backend->createNewKeyPair();
101  $storage->put($keyPair->getPrivateKey());
102  session_commit();
103  }
104 
105  return $keyPair;
106  }
107 
115  public function getRsaPublicKeyAjaxHandler(ServerRequestInterface $request, ResponseInterface $response)
116  {
117  $keyPair = $this->getRsaPublicKey();
118  if ($keyPair !== null) {
119  $response->getBody()->write(implode('', [
120  'publicKeyModulus' => $keyPair->getPublicKeyModulus(),
121  'spacer' => ':',
122  'exponent' => sprintf('%x', $keyPair->getExponent())
123  ]));
124  $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
125  } else {
126  $response->getBody()->write('No OpenSSL backend could be obtained for rsaauth.');
127  $response = $response->withStatus(500);
128  }
129  return $response;
130  }
131 }
enableRsaEncryption($useRequireJsModule=false)
static makeInstance($className,... $constructorArguments)
getRsaPublicKeyAjaxHandler(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']