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\Stepup\Identity\Event; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\DateTime\DateTime; |
22
|
|
|
use Surfnet\Stepup\Identity\AuditLog\Metadata; |
23
|
|
|
use Surfnet\Stepup\Identity\Value\CommonName; |
24
|
|
|
use Surfnet\Stepup\Identity\Value\Email; |
25
|
|
|
use Surfnet\Stepup\Identity\Value\EmailVerificationWindow; |
|
|
|
|
26
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
27
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
28
|
|
|
use Surfnet\Stepup\Identity\Value\Locale; |
|
|
|
|
29
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorId; |
30
|
|
|
use Surfnet\Stepup\Identity\Value\YubikeyPublicId; |
31
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
32
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
33
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface; |
34
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
35
|
|
|
|
36
|
|
|
class YubikeyPossessionProvenEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var string[] |
40
|
|
|
*/ |
41
|
|
|
private array $allowlist = [ |
42
|
|
|
'identity_id', |
43
|
|
|
'identity_institution', |
44
|
|
|
'second_factor_id', |
45
|
|
|
'preferred_locale', |
46
|
|
|
'second_factor_identifier', |
47
|
|
|
'second_factor_type', |
48
|
|
|
'email', |
49
|
|
|
'common_name', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var DateTime |
54
|
|
|
*/ |
55
|
|
|
public DateTime $emailVerificationRequestedAt; |
56
|
|
|
|
57
|
|
|
/** |
|
|
|
|
58
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
59
|
|
|
*/ |
60
|
|
|
public function __construct( |
61
|
|
|
IdentityId $identityId, |
62
|
|
|
Institution $institution, |
63
|
|
|
public SecondFactorId $secondFactorId, |
64
|
|
|
/** |
65
|
|
|
* The Yubikey's public ID. |
66
|
|
|
*/ |
67
|
|
|
public YubikeyPublicId $yubikeyPublicId, |
68
|
|
|
public bool $emailVerificationRequired, |
69
|
|
|
public EmailVerificationWindow $emailVerificationWindow, |
70
|
|
|
public string $emailVerificationNonce, |
71
|
|
|
public CommonName $commonName, |
72
|
|
|
public Email $email, |
73
|
|
|
/** |
74
|
|
|
* @var Locale Eg. "en_GB" |
75
|
|
|
*/ |
76
|
|
|
public Locale $preferredLocale, |
77
|
|
|
) { |
78
|
|
|
parent::__construct($identityId, $institution); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getAuditLogMetadata(): Metadata |
82
|
|
|
{ |
83
|
|
|
$metadata = new Metadata(); |
84
|
|
|
$metadata->identityId = $this->identityId; |
85
|
|
|
$metadata->identityInstitution = $this->identityInstitution; |
86
|
|
|
$metadata->secondFactorId = $this->secondFactorId; |
87
|
|
|
$metadata->secondFactorType = new SecondFactorType('yubikey'); |
88
|
|
|
$metadata->secondFactorIdentifier = $this->yubikeyPublicId; |
89
|
|
|
|
90
|
|
|
return $metadata; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public static function deserialize(array $data): self |
94
|
|
|
{ |
95
|
|
|
if (!isset($data['email_verification_required'])) { |
96
|
|
|
$data['email_verification_required'] = true; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return new self( |
100
|
|
|
new IdentityId($data['identity_id']), |
101
|
|
|
new Institution($data['identity_institution']), |
102
|
|
|
new SecondFactorId($data['second_factor_id']), |
103
|
|
|
YubikeyPublicId::unknown(), |
104
|
|
|
$data['email_verification_required'], |
105
|
|
|
EmailVerificationWindow::deserialize($data['email_verification_window']), |
106
|
|
|
$data['email_verification_nonce'], |
107
|
|
|
CommonName::unknown(), |
108
|
|
|
Email::unknown(), |
109
|
|
|
new Locale($data['preferred_locale']), |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* The data ending up in the event_stream, be careful not to include sensitive data here! |
115
|
|
|
* |
116
|
|
|
* @return array<string, mixed> |
117
|
|
|
*/ |
118
|
|
|
public function serialize(): array |
119
|
|
|
{ |
120
|
|
|
return [ |
121
|
|
|
'identity_id' => (string)$this->identityId, |
122
|
|
|
'identity_institution' => (string)$this->identityInstitution, |
123
|
|
|
'second_factor_id' => (string)$this->secondFactorId, |
124
|
|
|
'email_verification_required' => $this->emailVerificationRequired, |
125
|
|
|
'email_verification_window' => $this->emailVerificationWindow->serialize(), |
126
|
|
|
'email_verification_nonce' => $this->emailVerificationNonce, |
127
|
|
|
'preferred_locale' => (string)$this->preferredLocale, |
128
|
|
|
]; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getSensitiveData(): SensitiveData |
132
|
|
|
{ |
133
|
|
|
return (new SensitiveData) |
134
|
|
|
->withCommonName($this->commonName) |
135
|
|
|
->withEmail($this->email) |
136
|
|
|
->withSecondFactorIdentifier($this->yubikeyPublicId, new SecondFactorType('yubikey')); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setSensitiveData(SensitiveData $sensitiveData): void |
140
|
|
|
{ |
141
|
|
|
$this->email = $sensitiveData->getEmail(); |
142
|
|
|
$this->commonName = $sensitiveData->getCommonName(); |
143
|
|
|
$yubikeyPublicId = $sensitiveData->getSecondFactorIdentifier(); |
144
|
|
|
assert($yubikeyPublicId instanceof YubikeyPublicId); |
145
|
|
|
$this->yubikeyPublicId = $yubikeyPublicId; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function obtainUserData(): array |
149
|
|
|
{ |
150
|
|
|
$serializedPublicUserData = $this->serialize(); |
151
|
|
|
$serializedSensitiveUserData = $this->getSensitiveData()->serialize(); |
152
|
|
|
return array_merge($serializedPublicUserData, $serializedSensitiveUserData); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string[] |
157
|
|
|
*/ |
158
|
|
|
public function getAllowlist(): array |
159
|
|
|
{ |
160
|
|
|
return $this->allowlist; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|