TYPO3 CMS  TYPO3_7-6
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 
44  public function enableRsaEncryption($useRequireJsModule = false)
45  {
46  if ($this->moduleLoaded || !$this->isAvailable()) {
47  return;
48  }
49  $this->moduleLoaded = true;
50  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
51  // Include necessary javascript files
52  if ($useRequireJsModule) {
53  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Rsaauth/RsaEncryptionModule');
54  } else {
55  // Register ajax handler url
56  $code = 'var TYPO3RsaEncryptionPublicKeyUrl = ' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'index.php?eID=RsaPublicKeyGenerationController') . ';';
57  $pageRenderer->addJsInlineCode('TYPO3RsaEncryptionPublicKeyUrl', $code);
58  $javascriptPath = ExtensionManagementUtility::siteRelPath('rsaauth') . 'Resources/Public/JavaScript/';
59  if (!$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['debug']) {
60  $files = ['RsaEncryptionWithLib.min.js'];
61  } else {
62  $files = [
63  'RsaLibrary.js',
64  'RsaEncryption.js',
65  ];
66  }
67  foreach ($files as $file) {
68  $pageRenderer->addJsFile($javascriptPath . $file);
69  }
70  }
71  }
72 
76  public function isAvailable()
77  {
78  return trim($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['loginSecurityLevel']) === 'rsa';
79  }
80 
86  public function getRsaPublicKey()
87  {
88  $keyPair = null;
89  $backend = Backend\BackendFactory::getBackend();
90  if ($backend !== null) {
91  $keyPair = $backend->createNewKeyPair();
93  $storage->put($keyPair->getPrivateKey());
94  session_commit();
95  }
96 
97  return $keyPair;
98  }
99 
107  public function getRsaPublicKeyAjaxHandler(ServerRequestInterface $request, ResponseInterface $response)
108  {
109  $keyPair = $this->getRsaPublicKey();
110  if ($keyPair !== null) {
111  $response->getBody()->write(implode('', [
112  'publicKeyModulus' => $keyPair->getPublicKeyModulus(),
113  'spacer' => ':',
114  'exponent' => sprintf('%x', $keyPair->getExponent())
115  ]));
116  $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
117  } else {
118  $response->getBody()->write('No OpenSSL backend could be obtained for rsaauth.');
119  $response = $response->withStatus(500);
120  }
121  return $response;
122  }
123 }
enableRsaEncryption($useRequireJsModule=false)
getRsaPublicKeyAjaxHandler(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']