Skip to content

Commit 8825dea

Browse files
committed
Merge branch 'altcha-lib-20'
2 parents e810565 + f6273c0 commit 8825dea

5 files changed

Lines changed: 39 additions & 24 deletions

File tree

config/services.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ services:
2929
$hmacKeySignature: '%altcha.hmacKeySignature%'
3030
$requestStack: '@request_stack'
3131
$driverKeyProvider: '@Tito10047\AltchaBundle\Service\DriverKeyProviderInterface'
32-
$solveChallengeResolver: '@Tito10047\AltchaBundle\Service\SolveChallengeResolverInterface'
33-
$challengeOptionResolver: '@Tito10047\AltchaBundle\Service\ChallengeResolverInterface'
3432
Tito10047\AltchaBundle\Controller\AltchaChallengeController:
3533
public: true
3634
autowire: true

config/services_sentinel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ services:
1616
$verifySignatureUrl: '%altcha.sentinel.verify_signature_url%'
1717
$httpClient: '@altcha.sentinel.http_client'
1818
$requestStack: '@request_stack'
19-
$hmacKey: '%altcha.hmacKey%'
19+
$driverKeyProvider: '@Tito10047\AltchaBundle\Service\DriverKeyProviderInterface'
2020
calls:
2121
- setLogger: ['@?logger']

src/Service/SolveChallengeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SolveChallengeResolver implements SolveChallengeResolverInterface{
1919
public function __construct(
2020
private readonly ChallengeResolverInterface $challengeResolver,
2121
private readonly string $hmacSignature,
22-
private readonly string $hmacKeySignature,
22+
private readonly ?string $hmacKeySignature,
2323
private readonly float $timeout
2424
) {
2525
}

src/Validator/AltchaSentinelValidator.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
namespace Tito10047\AltchaBundle\Validator;
66

77
use AltchaOrg\Altcha\Altcha;
8+
use AltchaOrg\Altcha\Challenge;
9+
use AltchaOrg\Altcha\ChallengeParameters;
810
use AltchaOrg\Altcha\Payload;
11+
use AltchaOrg\Altcha\Solution;
912
use AltchaOrg\Altcha\VerifySolutionOptions;
1013
use Psr\Log\LoggerAwareInterface;
1114
use Psr\Log\LoggerInterface;
@@ -33,8 +36,6 @@ public function __construct(
3336
private readonly string $hmacSignature,
3437
private readonly string $hmacKeySignature,
3538
private readonly DriverKeyProviderInterface $driverKeyProvider,
36-
private readonly SolveChallengeResolverInterface $solveChallengeResolver,
37-
private readonly ChallengeResolverInterface $challengeOptionResolver
3839
) {
3940
}
4041

@@ -92,15 +93,20 @@ public function validate(mixed $value, Constraint $constraint): void {
9293

9394
return;
9495
}
95-
$solution = $this->solveChallengeResolver->solveChallenge();
96-
$challenge = $this->challengeOptionResolver->getChallenge();
96+
$payload = json_decode($altchaJson, true, 512, JSON_THROW_ON_ERROR);
9797

98-
$payload = new Payload($challenge, $solution);
99-
$result = (new Altcha(
98+
$result = (new Altcha(
10099
hmacSignatureSecret: $this->hmacSignature,
101100
hmacKeySignatureSecret: $this->hmacKeySignature,
102101
))->verifySolution(new VerifySolutionOptions(
103-
payload: $payload,
102+
payload: new Payload(new Challenge(
103+
parameters:ChallengeParameters::fromArray($payload["challenge"]["parameters"]??[]) ,
104+
signature: $payload["challenge"]["signature"]??"",
105+
), new Solution(
106+
counter: $payload["solution"]["counter"]??10,
107+
derivedKey: $payload["solution"]["derivedKey"]??"",
108+
time: $payload["solution"]["time"]??0,
109+
)),
104110
algorithm: $this->driverKeyProvider->getAlgorithm(),
105111
));
106112

src/Validator/AltchaValidator.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
use AltchaOrg\Altcha\Algorithm\Pbkdf2;
88
use AltchaOrg\Altcha\Altcha;
9+
use AltchaOrg\Altcha\Challenge;
10+
use AltchaOrg\Altcha\ChallengeParameters;
911
use AltchaOrg\Altcha\Payload;
12+
use AltchaOrg\Altcha\Solution;
1013
use AltchaOrg\Altcha\VerifySolutionOptions;
14+
use Random\RandomException;
1115
use Symfony\Component\HttpFoundation\RequestStack;
1216
use Symfony\Component\Validator\Constraint;
1317
use Symfony\Component\Validator\ConstraintValidator;
18+
use Tito10047\AltchaBundle\Controller\AltchaChallengeController;
1419
use Tito10047\AltchaBundle\Service\ChallengeResolverInterface;
1520
use Tito10047\AltchaBundle\Service\DriverKeyProviderInterface;
1621
use Tito10047\AltchaBundle\Service\SolveChallengeResolverInterface;
@@ -20,28 +25,28 @@ final class AltchaValidator extends ConstraintValidator
2025
public function __construct(
2126
private readonly bool $enable,
2227
private readonly string $hmacSignature,
23-
private readonly string $hmacKeySignature,
28+
private readonly ?string $hmacKeySignature,
2429
private readonly RequestStack $requestStack,
2530
private readonly DriverKeyProviderInterface $driverKeyProvider,
26-
private readonly SolveChallengeResolverInterface $solveChallengeResolver,
27-
private readonly ChallengeResolverInterface $challengeOptionResolver
2831
) {
2932
}
3033

31-
/**
32-
* Checks if the passed value is valid.
33-
*
34-
* @param mixed $value The value that should be validated
35-
* @param Constraint $constraint The constraint for the validation
36-
*/
34+
/**
35+
* Checks if the passed value is valid.
36+
*
37+
* @param mixed $value The value that should be validated
38+
* @param Constraint $constraint The constraint for the validation
39+
*
40+
* @throws RandomException
41+
*/
3742
public function validate(mixed $value, Constraint $constraint): void
3843
{
3944
if (false === $this->enable) {
4045
return;
4146
}
47+
$request = $this->requestStack->getCurrentRequest();
4248

4349
if (!$value) {
44-
$request = $this->requestStack->getCurrentRequest();
4550
$value = $request?->request->get('altcha');
4651
}
4752

@@ -72,14 +77,20 @@ public function validate(mixed $value, Constraint $constraint): void
7277
return;
7378
}
7479

75-
$solution = $this->solveChallengeResolver->solveChallenge();
76-
$challenge = $this->challengeOptionResolver->getChallenge();
80+
7781

7882
$result = (new Altcha(
7983
hmacSignatureSecret: $this->hmacSignature,
8084
hmacKeySignatureSecret: $this->hmacKeySignature,
8185
))->verifySolution(new VerifySolutionOptions(
82-
payload: new Payload($challenge, $solution),
86+
payload: new Payload(new Challenge(
87+
parameters:ChallengeParameters::fromArray($payload["challenge"]["parameters"]??[]) ,
88+
signature: $payload["challenge"]["signature"]??"",
89+
), new Solution(
90+
counter: $payload["solution"]["counter"]??10,
91+
derivedKey: $payload["solution"]["derivedKey"]??"",
92+
time: $payload["solution"]["time"]??0,
93+
)),
8394
algorithm: $this->driverKeyProvider->getAlgorithm(),
8495
));
8596

0 commit comments

Comments
 (0)