Skip to content

Commit

Permalink
[BUGFIX] Do not deprecate RsaEncryptionEncoder::getRsaPublicKey()
Browse files Browse the repository at this point in the history
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 <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
mbrodala authored and bmack committed Mar 20, 2018
1 parent 35f04e6 commit 811d281
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Expand Up @@ -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
Expand All @@ -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
Expand Up @@ -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 = [
Expand Down
8 changes: 3 additions & 5 deletions typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Rsaauth;

/*
Expand Down Expand Up @@ -89,15 +90,12 @@ public function isAvailable()
* Gets RSA Public Key.
*
* @return Keypair|null
*
* @deprecated since TYPO3 v9. Will be removed in v10.
*/
public function getRsaPublicKey()
public function getRsaPublicKey(): ?Keypair
{
trigger_error('Method getRsaPublicKey() will be removed in v10.', E_USER_DEPRECATED);

$keyPair = null;
$backend = Backend\BackendFactory::getBackend();

if ($backend !== null) {
$keyPair = $backend->createNewKeyPair();
$storage = Storage\StorageFactory::getStorage();
Expand Down

0 comments on commit 811d281

Please sign in to comment.