1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupRa\RaBundle\Controller\Vetting; |
20
|
|
|
|
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
22
|
|
|
use Surfnet\StepupRa\RaBundle\Command\VerifyU2fPublicIdCommand; |
23
|
|
|
use Surfnet\StepupRa\RaBundle\Service\VettingService; |
24
|
|
|
use Surfnet\StepupU2fBundle\Dto\SignResponse; |
25
|
|
|
use Surfnet\StepupU2fBundle\Form\Type\VerifyDeviceAuthenticationType; |
26
|
|
|
use Symfony\Component\HttpFoundation\Request; |
27
|
|
|
use Symfony\Component\HttpFoundation\Response; |
28
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
29
|
|
|
|
30
|
|
|
class U2fController extends SecondFactorController |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @Template |
34
|
|
|
* @param Request $request |
35
|
|
|
* @param string $procedureId |
36
|
|
|
* @return array|Response |
37
|
|
|
*/ |
38
|
|
|
public function startAuthenticationAction(Request $request, $procedureId) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->assertSecondFactorEnabled('u2f'); |
41
|
|
|
|
42
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA']); |
43
|
|
|
|
44
|
|
|
$logger = $this->get('ra.procedure_logger')->forProcedure($procedureId); |
45
|
|
|
$logger->notice('Suggesting RA start U2F authentication'); |
46
|
|
|
|
47
|
|
View Code Duplication |
if (!$this->getVettingService()->hasProcedure($procedureId)) { |
|
|
|
|
48
|
|
|
$logger->notice(sprintf('Vetting procedure "%s" not found', $procedureId)); |
49
|
|
|
throw $this->createNotFoundException(sprintf('Vetting procedure "%s" not found', $procedureId)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return ['procedureId' => $procedureId]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @Template |
57
|
|
|
* @param Request $request |
58
|
|
|
* @param string $procedureId |
59
|
|
|
* @return array|Response |
60
|
|
|
*/ |
61
|
|
|
public function authenticationAction(Request $request, $procedureId) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->assertSecondFactorEnabled('u2f'); |
64
|
|
|
|
65
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA']); |
66
|
|
|
|
67
|
|
|
$logger = $this->get('ra.procedure_logger')->forProcedure($procedureId); |
68
|
|
|
$logger->notice('Requested U2F Verfication'); |
69
|
|
|
|
70
|
|
View Code Duplication |
if (!$this->getVettingService()->hasProcedure($procedureId)) { |
|
|
|
|
71
|
|
|
$logger->notice(sprintf('Vetting procedure "%s" not found', $procedureId)); |
72
|
|
|
throw new NotFoundHttpException(sprintf('Vetting procedure "%s" not found', $procedureId)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$service = $this->getVettingService(); |
76
|
|
|
$session = $this->get('ra.session.u2f'); |
77
|
|
|
|
78
|
|
|
$result = $service->createU2fSignRequest($procedureId); |
79
|
|
|
|
80
|
|
|
if (!$result->wasSuccessful()) { |
81
|
|
|
$this->addFlash('error', 'ra.vetting.u2f.alert.error'); |
82
|
|
|
|
83
|
|
|
return ['authenticationFailed' => true, 'procedureId' => $procedureId]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$signRequest = $result->getSignRequest(); |
87
|
|
|
$signResponse = new SignResponse(); |
88
|
|
|
|
89
|
|
|
$formAction = $this->generateUrl('ra_vetting_u2f_prove_possession', ['procedureId' => $procedureId]); |
90
|
|
|
$form = $this->createForm( |
91
|
|
|
VerifyDeviceAuthenticationType::class, |
92
|
|
|
$signResponse, |
93
|
|
|
['sign_request' => $signRequest, 'action' => $formAction,] |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$session->set('request', $signRequest); |
97
|
|
|
|
98
|
|
|
return ['form' => $form->createView()]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @Template |
103
|
|
|
*/ |
104
|
|
|
public function provePossessionAction(Request $request, $procedureId) |
105
|
|
|
{ |
106
|
|
|
$this->assertSecondFactorEnabled('u2f'); |
107
|
|
|
|
108
|
|
|
$session = $this->get('ra.session.u2f'); |
109
|
|
|
|
110
|
|
|
/** @var RegisterRequest $signRequest */ |
111
|
|
|
$signRequest = $session->get('request'); |
112
|
|
|
$signResponse = new SignResponse(); |
113
|
|
|
|
114
|
|
|
$formAction = $this->generateUrl('ra_vetting_u2f_prove_possession', ['procedureId' => $procedureId]); |
115
|
|
|
$form = $this |
116
|
|
|
->createForm( |
117
|
|
|
VerifyDeviceAuthenticationType::class, |
118
|
|
|
$signResponse, |
119
|
|
|
['sign_request' => $signRequest, 'action' => $formAction] |
120
|
|
|
) |
121
|
|
|
->handleRequest($request); |
122
|
|
|
|
123
|
|
|
if (!$form->isSubmitted() || !$form->isValid()) { |
124
|
|
|
return $this->render('SurfnetStepupRaRaBundle:Vetting/U2f:authentication.html.twig', [ |
125
|
|
|
'authenticationFailed' => true, |
126
|
|
|
'procedureId' => $procedureId, |
127
|
|
|
]); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$service = $this->getVettingService(); |
131
|
|
|
$result = $service->verifyU2fAuthentication($procedureId, $signRequest, $signResponse); |
132
|
|
|
|
133
|
|
|
if ($result->wasSuccessful()) { |
134
|
|
|
return $this->redirectToRoute('ra_vetting_verify_identity', ['procedureId' => $procedureId]); |
135
|
|
|
} elseif ($result->didDeviceReportAnyError()) { |
136
|
|
|
$this->addFlash('error', 'ra.vetting.u2f.alert.device_reported_an_error'); |
137
|
|
|
return ['authenticationFailed' => true, 'procedureId' => $procedureId]; |
138
|
|
|
} else { |
139
|
|
|
$this->addFlash('error', 'ra.vetting.u2f.alert.error'); |
140
|
|
|
return ['authenticationFailed' => true, 'procedureId' => $procedureId]; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return VettingService |
146
|
|
|
*/ |
147
|
|
|
private function getVettingService() |
148
|
|
|
{ |
149
|
|
|
return $this->get('ra.service.vetting'); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.