66
77use AltchaOrg \Altcha \Algorithm \Pbkdf2 ;
88use AltchaOrg \Altcha \Altcha ;
9+ use AltchaOrg \Altcha \Challenge ;
10+ use AltchaOrg \Altcha \ChallengeParameters ;
911use AltchaOrg \Altcha \Payload ;
12+ use AltchaOrg \Altcha \Solution ;
1013use AltchaOrg \Altcha \VerifySolutionOptions ;
14+ use Random \RandomException ;
1115use Symfony \Component \HttpFoundation \RequestStack ;
1216use Symfony \Component \Validator \Constraint ;
1317use Symfony \Component \Validator \ConstraintValidator ;
18+ use Tito10047 \AltchaBundle \Controller \AltchaChallengeController ;
1419use Tito10047 \AltchaBundle \Service \ChallengeResolverInterface ;
1520use Tito10047 \AltchaBundle \Service \DriverKeyProviderInterface ;
1621use 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