[TASK] Add more fixers for php-cs-fixer
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / RsaAuthService.php
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Service "RSA authentication" for the "rsaauth" extension. This service will
21 * authenticate a user using hos password encoded with one time public key. It
22 * uses the standard TYPO3 service to do all dirty work. Firsts, it will decode
23 * the password and then pass it to the parent service ('sv'). This ensures that it
24 * always works, even if other TYPO3 internals change.
25 */
26 class RsaAuthService extends \TYPO3\CMS\Sv\AuthenticationService
27 {
28 /**
29 * @var RsaEncryptionDecoder
30 */
31 protected $rsaEncryptionDecoder = null;
32
33 /**
34 * Standard extension key for the service
35 * The extension key.
36 *
37 * @var string
38 */
39 public $extKey = 'rsaauth';
40
41 /**
42 * Standard prefix id for the service
43 * Same as class name
44 *
45 * @var string
46 */
47 public $prefixId = 'tx_rsaauth_sv1';
48
49 /**
50 * Process the submitted credentials.
51 * In this case decrypt the password if it is RSA encrypted.
52 *
53 * @param array $loginData Credentials that are submitted and potentially modified by other services
54 * @param string $passwordTransmissionStrategy Keyword of how the password has been hashed or encrypted before submission
55 * @return bool
56 */
57 public function processLoginData(array &$loginData, $passwordTransmissionStrategy)
58 {
59 $isProcessed = false;
60 if ($passwordTransmissionStrategy === 'rsa') {
61 $password = $loginData['uident'];
62 if (substr($password, 0, 4) === 'rsa:') {
63 $decryptedPassword = $this->getRsaEncryptionDecoder()->decrypt($password);
64 if ($decryptedPassword !== $password) {
65 $loginData['uident_text'] = $decryptedPassword;
66 $isProcessed = true;
67 } else {
68 if ($this->pObj->writeDevLog) {
69 GeneralUtility::devLog('Process login data: Failed to RSA decrypt password', self::class);
70 }
71 }
72 } else {
73 if ($this->pObj->writeDevLog) {
74 GeneralUtility::devLog('Process login data: passwordTransmissionStrategy has been set to "rsa" but no rsa encrypted password has been found.', self::class);
75 }
76 }
77 }
78 return $isProcessed;
79 }
80
81 /**
82 * Initializes the service.
83 *
84 * @return bool
85 */
86 public function init()
87 {
88 return parent::init() && $this->getRsaEncryptionDecoder()->isAvailable();
89 }
90
91 /**
92 * @return RsaEncryptionDecoder
93 */
94 protected function getRsaEncryptionDecoder()
95 {
96 if ($this->rsaEncryptionDecoder === null) {
97 $this->rsaEncryptionDecoder = GeneralUtility::makeInstance(RsaEncryptionDecoder::class);
98 }
99
100 return $this->rsaEncryptionDecoder;
101 }
102 }