-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. To check the preconditions 2. To verify that the Subject NameID matches the SecondFactor Identifier used to start the authentication.
- Loading branch information
Showing
8 changed files
with
375 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Surfnet/StepupGateway/SecondFactorOnlyBundle/Exception/RuntimeException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2018 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupGateway\SecondFactorOnlyBundle\Exception; | ||
|
||
use RuntimeException as BaseRuntimeException; | ||
|
||
class RuntimeException extends BaseRuntimeException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Surfnet/StepupGateway/SecondFactorOnlyBundle/Service/Gateway/ResponseValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2023 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupGateway\SecondFactorOnlyBundle\Service\Gateway; | ||
|
||
use Surfnet\SamlBundle\Http\PostBinding; | ||
use Surfnet\StepupBundle\Service\SecondFactorTypeService; | ||
use Surfnet\StepupBundle\Value\SecondFactorType; | ||
use Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor; | ||
use Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\ProviderRepository; | ||
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Exception\RuntimeException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ResponseValidator | ||
{ | ||
/** @var SecondFactorTypeService */ | ||
private $secondFactorTypeService; | ||
|
||
/** @var ProviderRepository */ | ||
private $providerRepository; | ||
|
||
/** @var PostBinding */ | ||
private $postBinding; | ||
|
||
public function __construct( | ||
SecondFactorTypeService $secondFactorTypeService, | ||
ProviderRepository $providerRepository, | ||
PostBinding $postBinding | ||
) { | ||
$this->secondFactorTypeService = $secondFactorTypeService; | ||
$this->providerRepository = $providerRepository; | ||
$this->postBinding = $postBinding; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function validate(Request $request, SecondFactor $secondFactor, string $nameIdFromState) | ||
{ | ||
$secondFactorType = new SecondFactorType($secondFactor->secondFactorType); | ||
$hasSamlResponse = $request->request->has('SAMLResponse'); | ||
// When dealing with a GSSP response. It is advised to receive the SAML response through POST Binding, | ||
// testing the preconditions. | ||
if ($hasSamlResponse && $this->secondFactorTypeService->isGssf($secondFactorType)) { | ||
$provider = $this->providerRepository->get($secondFactorType->getSecondFactorType()); | ||
// Receive the response via POST Binding, this will test all the regular pre-conditions | ||
$samlResponse = $this->postBinding->processResponse( | ||
$request, | ||
$provider->getRemoteIdentityProvider(), | ||
$provider->getServiceProvider() | ||
); | ||
$nameIdFromResponse = $samlResponse->getNameId()->getValue(); | ||
// Additionally test if the name id from the GSSP matches the SF identifier that we have in state | ||
if ($nameIdFromResponse !== $secondFactor->secondFactorIdentifier) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'The nameID recieved from the GSSP (%s) did not match the selected second factor (%s). This '. | ||
'might be an indication someone is tampering with a GSSP. The authentication was started by %s', | ||
$nameIdFromResponse, | ||
$secondFactor->secondFactorIdentifier, | ||
$nameIdFromState | ||
) | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.