File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212class RequestObject extends ParsedJws
1313{
1414 /**
15+ * Get Algorithm. Overridden to allow the 'none' algorithm.
16+ *
17+ * @return ?non-empty-string
1518 * @throws \SimpleSAML\OpenID\Exceptions\JwsException
16- * @throws \SimpleSAML\OpenID\Exceptions\RequestObjectException
1719 * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
1820 */
19- public function isProtected (): bool
21+ public function getAlgorithm (): ? string
2022 {
21- $ algHeader = $ this ->helpers ->type ()->ensureString (
22- $ this ->getHeaderClaim (ClaimsEnum::Alg->value ) ?? throw new RequestObjectException (
23- 'Alg header is missing. ' ,
24- ),
23+ $ claimKey = ClaimsEnum::Alg->value ;
24+
25+ $ alg = $ this ->getHeaderClaim ($ claimKey );
26+
27+ if (is_null ($ alg )) {
28+ throw new RequestObjectException ('Missing Algorithm header claim. ' );
29+ }
30+
31+ $ alg = $ this ->helpers ->type ()->ensureNonEmptyString ($ alg , $ claimKey );
32+
33+ SignatureAlgorithmEnum::tryFrom ($ alg ) ?? throw new RequestObjectException (
34+ 'Invalid Algorithm header claim. ' ,
2535 );
2636
27- return $ algHeader !== SignatureAlgorithmEnum::none->value ;
37+ return $ alg ;
38+ }
39+
40+
41+ /**
42+ * @throws \SimpleSAML\OpenID\Exceptions\JwsException
43+ * @throws \SimpleSAML\OpenID\Exceptions\RequestObjectException
44+ * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
45+ */
46+ public function isProtected (): bool
47+ {
48+ return $ this ->getAlgorithm () !== SignatureAlgorithmEnum::none->value ;
2849 }
2950}
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ protected function setUp(): void
7070 $ this ->helpersMock ->method ('type ' )->willReturn ($ typeHelperMock );
7171
7272 $ typeHelperMock ->method ('ensureString ' )->willReturnArgument (0 );
73+ $ typeHelperMock ->method ('ensureNonEmptyString ' )->willReturnArgument (0 );
7374
7475 $ this ->claimFactoryMock = $ this ->createMock (ClaimFactory::class);
7576 }
You can’t perform that action at this time.
0 commit comments