‪TYPO3CMS  9.5
RsaEncryptionEncoder.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 namespace ‪TYPO3\CMS\Rsaauth;
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
24 
29 {
33  protected ‪$moduleLoaded = false;
34 
38  protected ‪$pageRenderer;
39 
44  {
45  $this->‪enableRsaEncryption(true);
46  }
47 
53  public function ‪enableRsaEncryption($useRequireJsModule = false)
54  {
55  if ($this->moduleLoaded || !$this->‪isAvailable()) {
56  return;
57  }
58  $this->moduleLoaded = true;
59  ‪$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
60  // Include necessary javascript files
61  if ($useRequireJsModule) {
62  ‪$pageRenderer->‪loadRequireJsModule('TYPO3/CMS/Rsaauth/RsaEncryptionModule');
63  } else {
64  // Register ajax handler url
65  $code = 'var TYPO3RsaEncryptionPublicKeyUrl = ' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . 'index.php?eID=RsaPublicKeyGenerationController') . ';';
66  ‪$pageRenderer->‪addJsInlineCode('TYPO3RsaEncryptionPublicKeyUrl', $code);
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('EXT:rsaauth/Resources/Public/JavaScript/' . $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(): ?‪Keypair
95  {
96  $keyPair = null;
98 
99  if ($backend !== null) {
100  $keyPair = $backend->createNewKeyPair();
102  $storage->put($keyPair->getPrivateKey());
103  session_commit();
104  }
105 
106  return $keyPair;
107  }
108 
116  public function ‪getRsaPublicKeyAjaxHandler(): ResponseInterface
117  {
118  trigger_error('Method getRsaPublicKeyAjaxHandler() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
119 
120  $keyPair = $this->‪getRsaPublicKey();
121  if ($keyPair !== null) {
122  return new ‪HtmlResponse(
123  implode('', [
124  'publicKeyModulus' => $keyPair->getPublicKeyModulus(),
125  'spacer' => ':',
126  'exponent' => sprintf('%x', $keyPair->getExponent())
127  ])
128  );
129  }
130 
131  $response = new ‪Response('php://temp', 500, ['Content-Type' => 'application/json; charset=utf-8']);
132  $response->getBody()->write('No OpenSSL backend could be obtained for rsaauth.');
133  return $response;
134  }
135 }
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\$moduleLoaded
‪bool $moduleLoaded
Definition: RsaEncryptionEncoder.php:32
‪TYPO3\CMS\Rsaauth\Storage\StorageFactory\getStorage
‪static TYPO3 CMS Rsaauth Storage AbstractStorage getStorage()
Definition: StorageFactory.php:47
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\$pageRenderer
‪PageRenderer $pageRenderer
Definition: RsaEncryptionEncoder.php:36
‪TYPO3\CMS\Rsaauth\Backend\BackendFactory\getBackend
‪static AbstractBackend getBackend()
Definition: BackendFactory.php:55
‪TYPO3\CMS\Core\Page\PageRenderer\loadRequireJsModule
‪loadRequireJsModule($mainModuleName, $callBackFunction=null)
Definition: PageRenderer.php:1593
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:28
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\isAvailable
‪bool isAvailable()
Definition: RsaEncryptionEncoder.php:82
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\getRsaPublicKey
‪Keypair null getRsaPublicKey()
Definition: RsaEncryptionEncoder.php:92
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder
Definition: RsaEncryptionEncoder.php:29
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\getRsaPublicKeyAjaxHandler
‪ResponseInterface getRsaPublicKeyAjaxHandler()
Definition: RsaEncryptionEncoder.php:114
‪TYPO3\CMS\Rsaauth\Keypair
Definition: Keypair.php:22
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\enableRsaEncryption
‪enableRsaEncryption($useRequireJsModule=false)
Definition: RsaEncryptionEncoder.php:51
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Page\PageRenderer\addJsInlineCode
‪addJsInlineCode($name, $block, $compress=true, $forceOnTop=false)
Definition: PageRenderer.php:1226
‪TYPO3\CMS\Core\Page\PageRenderer\addJsFile
‪addJsFile($file, $type='text/javascript', $compress=true, $forceOnTop=false, $allWrap='', $excludeFromConcatenation=false, $splitChar='|', $async=false, $integrity='', $defer=false, $crossorigin='')
Definition: PageRenderer.php:1157
‪TYPO3\CMS\Rsaauth\RsaEncryptionEncoder\enableEncryptionFromBackendControllerPostConstructor
‪enableEncryptionFromBackendControllerPostConstructor()
Definition: RsaEncryptionEncoder.php:41
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Rsaauth