From 811d28101850a0879b8566c20f2df67b31123bb5 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Tue, 20 Mar 2018 12:34:43 +0100 Subject: [PATCH] [BUGFIX] Do not deprecate RsaEncryptionEncoder::getRsaPublicKey() Also use this API in the RSA public key controller to avoid code duplication. Change-Id: Ief09eff9fb8f2370d545f93ec8187ae64b1c3f1a Resolves: #84497 Releases: master Reviewed-on: https://review.typo3.org/56378 Reviewed-by: Nicole Cordes Tested-by: Nicole Cordes Tested-by: TYPO3com Reviewed-by: Benni Mack Tested-by: Benni Mack --- ...AXRequestMethodsInRsaEncryptionEncoder.rst | 8 +++--- .../RsaPublicKeyGenerationController.php | 27 ++++++++++++------- .../rsaauth/Classes/RsaEncryptionEncoder.php | 8 +++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84407-AJAXRequestMethodsInRsaEncryptionEncoder.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84407-AJAXRequestMethodsInRsaEncryptionEncoder.rst index ccfe68079dbf..baf9f8ea6f34 100644 --- a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84407-AJAXRequestMethodsInRsaEncryptionEncoder.rst +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84407-AJAXRequestMethodsInRsaEncryptionEncoder.rst @@ -12,7 +12,6 @@ Description All methods related to AJAX requests in :php:`\TYPO3\CMS\Rsaauth\RsaEncryptionEncoder` have been deprecated: -* :php:`getRsaPublicKey()` * :php:`getRsaPublicKeyAjaxHandler()` The ``rsa_publickey`` AJAX route has been adapted to use the @@ -23,20 +22,19 @@ RSA key retrieval via eID in the frontend. Impact ====== -Calling one of the above methods on an instance of :php:`RsaEncryptionEncoder` will throw a +Calling the above method on an instance of :php:`RsaEncryptionEncoder` will throw a deprecation warning in v9 and a PHP fatal in v10. Affected Installations ====================== -All extensions that call the deprecated methods are affected. +All extensions that call the deprecated method are affected. Migration ========= -Extensions should not use the deprecated methods but directly request a key pair via the RSA -backend API. +Extensions should use the AJAX route `rsa_publickey` instead of the deprecated method. .. index:: Backend, Frontend, PHP-API, FullyScanned diff --git a/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php b/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php index c9a49eeed9b2..5bc9338c6ceb 100644 --- a/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php +++ b/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php @@ -18,33 +18,40 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Http\Response; -use TYPO3\CMS\Rsaauth\Backend\BackendFactory; -use TYPO3\CMS\Rsaauth\Storage\StorageFactory; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Rsaauth\RsaEncryptionEncoder; /** * eID script "RsaPublicKeyGenerationController" to generate an rsa key */ class RsaPublicKeyGenerationController { + /** + * @var RsaEncryptionEncoder + */ + protected $encoder; + + /** + * Set up dependencies + */ + public function __construct(RsaEncryptionEncoder $encoder = null) + { + $this->encoder = $encoder ?: GeneralUtility::makeInstance(RsaEncryptionEncoder::class); + } + /** * @param ServerRequestInterface $request * @return ResponseInterface */ public function processRequest(ServerRequestInterface $request): ResponseInterface { - /** @var \TYPO3\CMS\Rsaauth\Backend\AbstractBackend $backend */ - $backend = BackendFactory::getBackend(); + $keyPair = $this->encoder->getRsaPublicKey(); - if ($backend === null) { + if ($keyPair === null) { // add a HTTP 500 error code, if an error occurred return new JsonResponse(null, 500); } - $keyPair = $backend->createNewKeyPair(); - $storage = StorageFactory::getStorage(); - $storage->put($keyPair->getPrivateKey()); - session_commit(); - switch ($request->getHeaderLine('content-type')) { case 'application/json': $data = [ diff --git a/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php b/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php index 1383328d41d3..26aff53bd456 100644 --- a/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php +++ b/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php @@ -1,4 +1,5 @@ createNewKeyPair(); $storage = Storage\StorageFactory::getStorage();