Skip to content

Commit bfcece3

Browse files
committed
[!!!][TASK] Added TYPO3 12 compatibility
Signed-off-by: Torben Hansen <derhansen@gmail.com>
1 parent bd5afd3 commit bfcece3

File tree

20 files changed

+156
-166
lines changed

20 files changed

+156
-166
lines changed

.github/workflows/CodeQuality.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ jobs:
1010
strategy:
1111
matrix:
1212
env:
13-
- { php: 7.4, coverage: 1}
14-
- { php: 8.0, coverage: 0}
1513
- { php: 8.1, coverage: 0}
14+
- { php: 8.2, coverage: 0}
1615

1716
env: ${{ matrix.env }}
1817

@@ -29,7 +28,7 @@ jobs:
2928
run: composer validate
3029

3130
- name: Cache dependencies
32-
uses: actions/cache@v1
31+
uses: actions/cache@v3
3332
with:
3433
path: ~/.composer/cache
3534
key: dependencies-composer-${{ hashFiles('composer.json') }}
@@ -40,12 +39,12 @@ jobs:
4039
4140
- name: PHP lint
4241
run: |
43-
.Build/bin/phplint
42+
.Build/bin/phplint
4443
4544
- name: Validate PHP coding guidelines
4645
run: |
4746
.Build/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no
4847
4948
- name: Run phpstan checks
5049
run: |
51-
.Build/bin/phpstan
50+
.Build/bin/phpstan

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ jobs:
1010
strategy:
1111
matrix:
1212
env:
13-
- { php: 7.4, coverage: 1}
14-
- { php: 8.0, coverage: 0}
1513
- { php: 8.1, coverage: 0}
14+
- { php: 8.2, coverage: 0}
1615

1716
env: ${{ matrix.env }}
1817

@@ -25,11 +24,6 @@ jobs:
2524
php-version: ${{ matrix.env.php }}
2625
tools: composer:v2
2726

28-
- name: Update Composer
29-
run: |
30-
sudo composer self-update
31-
composer --version
32-
3327
- name: Validate composer.json and composer.lock
3428
run: composer validate
3529

@@ -39,4 +33,4 @@ jobs:
3933
4034
- name: Unit Tests
4135
run: |
42-
.Build/bin/phpunit
36+
.Build/bin/phpunit

Classes/Authentication/YubikeyAuthService.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public function __construct(YubikeyService $yubikeyService)
3535
* - 0 - authentication failure
3636
* - 100 - just go on. User is not authenticated but there is still no reason to stop
3737
* - 200 - the service was able to authenticate the user
38-
*
39-
* @param array $user Array containing the userdata
40-
* @return int authentication statuscode, one of 0, 100 and 200
4138
*/
4239
public function authUser(array $user): int
4340
{
@@ -61,7 +58,7 @@ public function authUser(array $user): int
6158
);
6259

6360
// Get Yubikey OTP
64-
$yubikeyOtp = GeneralUtility::_GP('t3-yubikey');
61+
$yubikeyOtp = (string)($_POST['t3-yubikey'] ?? $_GET['t3-yubikey'] ?? '');
6562
$this->logger->debug('Yubikey: ' . $yubikeyOtp);
6663
$tempYubiKeyIds = GeneralUtility::trimExplode(
6764
chr(10),
@@ -73,7 +70,7 @@ public function authUser(array $user): int
7370
$yubiKeyIds[] = substr($tempYubiKeyId, 0, 12);
7471
}
7572
// Check, if Yubikey-ID does match with users Yubikey-ID
76-
if (in_array(substr($yubikeyOtp, 0, 12), $yubiKeyIds)) {
73+
if (in_array(substr($yubikeyOtp, 0, 12), $yubiKeyIds, true)) {
7774
$clientId = $this->extConf['yubikeyClientId'] ?? 'none';
7875
$this->logger->debug('Yubikey config - ClientId: ' . $clientId);
7976

@@ -135,7 +132,7 @@ private function isYubikeyCheckEnabled(): bool
135132
$yubikeyCheckEnabled = true;
136133
} elseif (isset($this->extConf['yubikeyEnableFE']) &&
137134
(bool)$this->extConf['yubikeyEnableFE'] &&
138-
$this->pObj->loginType == 'FE'
135+
$this->pObj->loginType === 'FE'
139136
) {
140137
$yubikeyCheckEnabled = true;
141138
}

Classes/Command/CheckYubiKeyOtpCommand.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Derhansen\SfYubikey\Service\YubikeyService;
1313
use Symfony\Component\Console\Command\Command;
14-
use Symfony\Component\Console\Input\InputArgument;
1514
use Symfony\Component\Console\Input\InputInterface;
1615
use Symfony\Component\Console\Output\OutputInterface;
1716
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -29,38 +28,21 @@ public function __construct(YubikeyService $yubikeyService)
2928
parent::__construct();
3029
}
3130

32-
/**
33-
* Configuring the command options
34-
*/
35-
public function configure()
36-
{
37-
$this
38-
->setDescription('Checks the given OTP against the configured YubiKey endpoints')
39-
->addArgument(
40-
'otp',
41-
InputArgument::REQUIRED,
42-
'The YubiKey OTP'
43-
);
44-
}
45-
4631
/**
4732
* Execute the command
48-
*
49-
* @param InputInterface $input
50-
* @param OutputInterface $output
51-
* @return int|void|null
5233
*/
53-
protected function execute(InputInterface $input, OutputInterface $output)
34+
protected function execute(InputInterface $input, OutputInterface $output): int
5435
{
5536
$io = new SymfonyStyle($input, $output);
5637
$io->title($this->getDescription());
5738

5839
$otp = $input->getArgument('otp');
5940
if ($this->yubikeyService->verifyOtp($otp) === true) {
6041
$io->success('OK: ' . $otp . ' has been successfully validated.');
61-
return 0;
42+
return self::SUCCESS;
6243
}
44+
6345
$io->error($otp . ' could not be validated. Reasons: ' . implode(' / ', $this->yubikeyService->getErrors()));
64-
return 1;
46+
return self::FAILURE;
6547
}
6648
}

Classes/Hooks/UserSettings.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,27 @@
99
* LICENSE.txt file that was distributed with this source code.
1010
*/
1111

12+
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
13+
1214
/**
1315
* User Settings class
1416
*/
1517
class UserSettings
1618
{
1719
/**
1820
* Returns a textarea with the YubiKey IDs
19-
*
20-
* @return string
2121
*/
2222
public function userYubikeyId(): string
2323
{
2424
return '<textarea id="field_tx_sfyubikey_yubikey_id" name="data[be_users][tx_sfyubikey_yubikey_id]"
2525
rows="5" class="form-control t3js-formengine-textarea formengine-textarea">' .
26-
htmlspecialchars($GLOBALS['BE_USER']->user['tx_sfyubikey_yubikey_id'] ?? '') . '</textarea>';
26+
htmlspecialchars($this->getBackendUser()->user['tx_sfyubikey_yubikey_id'] ?? '') . '</textarea>';
2727
}
2828

2929
/**
3030
* Returns the current BE user.
31-
*
32-
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
3331
*/
34-
protected function getBackendUser()
32+
protected function getBackendUser(): BackendUserAuthentication
3533
{
3634
return $GLOBALS['BE_USER'];
3735
}

Classes/LoginProvider/YubikeyLoginProvider.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ class YubikeyLoginProvider extends UsernamePasswordLoginProvider
2222
{
2323
/**
2424
* Renders the login fields
25-
*
26-
* @param StandaloneView $view
27-
* @param PageRenderer $pageRenderer
28-
* @param LoginController $loginController
2925
*/
30-
public function render(StandaloneView $view, PageRenderer $pageRenderer, LoginController $loginController)
26+
public function render(StandaloneView $view, PageRenderer $pageRenderer, LoginController $loginController): void
3127
{
3228
parent::render($view, $pageRenderer, $loginController);
3329
$view->setTemplatePathAndFilename(

Classes/Service/YubikeyService.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
use Psr\Http\Client\NetworkExceptionInterface;
1717
use Psr\Http\Message\RequestFactoryInterface;
1818
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
19+
use TYPO3\CMS\Core\Crypto\Random;
1920
use TYPO3\CMS\Core\Utility\GeneralUtility;
2021

2122
/**
22-
* Provides YubiKey authentication using the yubico YubiCloud
23+
* Provides YubiKey authentication using the Yubico YubiCloud
2324
*/
2425
class YubikeyService
2526
{
@@ -49,10 +50,6 @@ public function __construct(
4950

5051
/**
5152
* Verify HMAC-SHA1 signature on result received from Yubico server
52-
*
53-
* @param string $response
54-
* @param string $yubicoClientKey
55-
* @return bool
5653
*/
5754
public function verifyHmac(string $response, string $yubicoClientKey): bool
5855
{
@@ -92,15 +89,12 @@ public function verifyHmac(string $response, string $yubicoClientKey): bool
9289

9390
/**
9491
* Call the Auth API at Yubico server
95-
*
96-
* @param string $otp
97-
* @return bool
9892
*/
9993
public function verifyOtp(string $otp): bool
10094
{
10195
$requestParams['id'] = $this->yubikeyClientId;
10296
$requestParams['otp'] = trim($otp);
103-
$requestParams['nonce'] = md5(uniqid((string)rand()));
97+
$requestParams['nonce'] = md5((new Random())->generateRandomHexString(32));
10498
ksort($requestParams);
10599
$parameters = '';
106100
foreach ($requestParams as $p => $v) {

Configuration/Services.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ services:
1313
Derhansen\SfYubikey\Command\CheckYubiKeyOtpCommand:
1414
tags:
1515
- name: 'console.command'
16+
description: 'Checks the given OTP against the configured YubiKey endpoints'
1617
command: 'sf_yubikey:checkyubikeyotp'
17-
schedulable: false
18+
schedulable: false

Configuration/TCA/Overrides/be_users.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
defined('TYPO3') or die();
44

5+
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
6+
57
// Prepare new columns for be_users table
68
$tempColumns = [
79
'tx_sfyubikey_yubikey_enable' => [
@@ -28,11 +30,11 @@
2830
],
2931
];
3032

31-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
33+
ExtensionManagementUtility::addTCAcolumns(
3234
'be_users',
3335
$tempColumns
3436
);
35-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
37+
ExtensionManagementUtility::addToAllTCAtypes(
3638
'be_users',
3739
'--div--;YubiKey,tx_sfyubikey_yubikey_enable, tx_sfyubikey_yubikey_id'
3840
);

Configuration/TCA/Overrides/fe_users.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
defined('TYPO3') or die();
44

5+
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
6+
57
// Prepare new columns for fe_users table
68
$tempColumns = [
79
'tx_sfyubikey_yubikey_enable' => [
@@ -28,11 +30,11 @@
2830
],
2931
];
3032

31-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
33+
ExtensionManagementUtility::addTCAcolumns(
3234
'fe_users',
3335
$tempColumns
3436
);
35-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
37+
ExtensionManagementUtility::addToAllTCAtypes(
3638
'fe_users',
3739
'--div--;YubiKey,tx_sfyubikey_yubikey_enable, tx_sfyubikey_yubikey_id'
3840
);

0 commit comments

Comments
 (0)