@@ -10,6 +10,5 @@ |
||
10 | 10 | * @class WebauthnException |
11 | 11 | * @package Platine\Webauthn\Exception |
12 | 12 | */ |
13 | -class WebauthnException extends Exception |
|
14 | -{ |
|
13 | +class WebauthnException extends Exception { |
|
15 | 14 | } |
@@ -169,9 +169,9 @@ |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * {@inheritdoc} |
|
173 | - * @return mixed |
|
174 | - */ |
|
172 | + * {@inheritdoc} |
|
173 | + * @return mixed |
|
174 | + */ |
|
175 | 175 | public function jsonSerialize() |
176 | 176 | { |
177 | 177 | return get_object_vars($this); |
@@ -48,22 +48,22 @@ |
||
48 | 48 | { |
49 | 49 | $enc = CborDecoder::decode($binary); |
50 | 50 | |
51 | - if (! is_array($enc) || ! array_key_exists('fmt', $enc) || ! is_string($enc['fmt'])) { |
|
51 | + if (!is_array($enc) || !array_key_exists('fmt', $enc) || !is_string($enc['fmt'])) { |
|
52 | 52 | throw new WebauthnException('Invalid attestation format provided'); |
53 | 53 | } |
54 | 54 | |
55 | - if (! array_key_exists('attStmt', $enc) || ! is_array($enc['attStmt'])) { |
|
55 | + if (!array_key_exists('attStmt', $enc) || !is_array($enc['attStmt'])) { |
|
56 | 56 | throw new WebauthnException('Invalid attestation format provided (attStmt not available)'); |
57 | 57 | } |
58 | 58 | |
59 | - if (! array_key_exists('authData', $enc) || ! $enc['authData'] instanceof ByteBuffer) { |
|
59 | + if (!array_key_exists('authData', $enc) || !$enc['authData'] instanceof ByteBuffer) { |
|
60 | 60 | throw new WebauthnException('Invalid attestation format provided (authData not available)'); |
61 | 61 | } |
62 | 62 | |
63 | 63 | $this->formatName = $enc['fmt']; |
64 | 64 | $this->authenticatorData = new AuthenticatorData($enc['authData']->getBinaryString()); |
65 | 65 | |
66 | - if (! in_array($this->formatName, $allowedFormats)) { |
|
66 | + if (!in_array($this->formatName, $allowedFormats)) { |
|
67 | 67 | throw new WebauthnException(sprintf( |
68 | 68 | 'Invalid attestation format [%s], allowed [%s]', |
69 | 69 | $this->formatName, |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | * @class AttestationData |
20 | 20 | * @package Platine\Webauthn\Attestation |
21 | 21 | */ |
22 | -class AttestationData implements JsonSerializable |
|
23 | -{ |
|
22 | +class AttestationData implements JsonSerializable { |
|
24 | 23 | /** |
25 | 24 | * The AuthenticatorData instance |
26 | 25 | * @var AuthenticatorData |
@@ -44,8 +43,7 @@ discard block |
||
44 | 43 | * @param string $binary |
45 | 44 | * @param array<string> $allowedFormats |
46 | 45 | */ |
47 | - public function __construct(string $binary, array $allowedFormats) |
|
48 | - { |
|
46 | + public function __construct(string $binary, array $allowedFormats) { |
|
49 | 47 | $enc = CborDecoder::decode($binary); |
50 | 48 | |
51 | 49 | if (! is_array($enc) || ! array_key_exists('fmt', $enc) || ! is_string($enc['fmt'])) { |
@@ -88,8 +86,7 @@ discard block |
||
88 | 86 | * |
89 | 87 | * @return BaseFormat|FidoU2F|None|Packed |
90 | 88 | */ |
91 | - public function getFormat() |
|
92 | - { |
|
89 | + public function getFormat() { |
|
93 | 90 | return $this->format; |
94 | 91 | } |
95 | 92 | |
@@ -172,8 +169,7 @@ discard block |
||
172 | 169 | * {@inheritdoc} |
173 | 170 | * @return mixed |
174 | 171 | */ |
175 | - public function jsonSerialize() |
|
176 | - { |
|
172 | + public function jsonSerialize() { |
|
177 | 173 | return get_object_vars($this); |
178 | 174 | } |
179 | 175 |
@@ -284,7 +284,7 @@ |
||
284 | 284 | |
285 | 285 | $extensionData = CborDecoder::decode($data); |
286 | 286 | |
287 | - if (! is_array($extensionData)) { |
|
287 | + if (!is_array($extensionData)) { |
|
288 | 288 | throw new WebauthnException('Invalid extension data'); |
289 | 289 | } |
290 | 290 |
@@ -15,8 +15,7 @@ discard block |
||
15 | 15 | * @class AuthenticatorData |
16 | 16 | * @package Platine\Webauthn\Attestation |
17 | 17 | */ |
18 | -class AuthenticatorData implements JsonSerializable |
|
19 | -{ |
|
18 | +class AuthenticatorData implements JsonSerializable { |
|
20 | 19 | public const EC2_TYPE = 2; |
21 | 20 | public const RSA_TYPE = 3; |
22 | 21 | |
@@ -60,8 +59,7 @@ discard block |
||
60 | 59 | * Create new instance |
61 | 60 | * @param string $binary |
62 | 61 | */ |
63 | - public function __construct(string $binary) |
|
64 | - { |
|
62 | + public function __construct(string $binary) { |
|
65 | 63 | if (strlen($binary) < 37) { |
66 | 64 | throw new WebauthnException('Invalid authenticator data provided'); |
67 | 65 | } |
@@ -225,8 +223,7 @@ discard block |
||
225 | 223 | * {@inheritdoc} |
226 | 224 | * @return mixed |
227 | 225 | */ |
228 | - public function jsonSerialize() |
|
229 | - { |
|
226 | + public function jsonSerialize() { |
|
230 | 227 | return get_object_vars($this); |
231 | 228 | } |
232 | 229 |
@@ -270,9 +270,9 @@ |
||
270 | 270 | |
271 | 271 | |
272 | 272 | /** |
273 | - * {@inheritdoc} |
|
274 | - * @return mixed |
|
275 | - */ |
|
273 | + * {@inheritdoc} |
|
274 | + * @return mixed |
|
275 | + */ |
|
276 | 276 | public function jsonSerialize() |
277 | 277 | { |
278 | 278 | return get_object_vars($this); |
@@ -11,8 +11,8 @@ |
||
11 | 11 | class None extends BaseFormat |
12 | 12 | { |
13 | 13 | /** |
14 | - * {@inheritdoc} |
|
15 | - */ |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | 16 | public function validateAttestation(string $clientData): bool |
17 | 17 | { |
18 | 18 | return true; |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * @class None |
9 | 9 | * @package Platine\Webauthn\Attestation\Format |
10 | 10 | */ |
11 | -class None extends BaseFormat |
|
12 | -{ |
|
11 | +class None extends BaseFormat { |
|
13 | 12 | /** |
14 | 13 | * {@inheritdoc} |
15 | 14 | */ |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | - * {@inheritdoc} |
|
83 | - */ |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | 84 | public function getCertificatePem(): string |
85 | 85 | { |
86 | 86 | $pem = '-----BEGIN CERTIFICATE-----' . "\n"; |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * {@inheritdoc} |
|
95 | - */ |
|
94 | + * {@inheritdoc} |
|
95 | + */ |
|
96 | 96 | public function validateAttestation(string $clientData): bool |
97 | 97 | { |
98 | 98 | $publicKey = openssl_pkey_get_public($this->getCertificatePem()); |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * {@inheritdoc} |
|
133 | - */ |
|
132 | + * {@inheritdoc} |
|
133 | + */ |
|
134 | 134 | public function validateRootCertificate(array $rootCertificates): bool |
135 | 135 | { |
136 | 136 | $chain = $this->createX5cChainFile(); |
@@ -56,21 +56,21 @@ |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | if ( |
59 | - ! array_key_exists('sig', $attestationStatement) || |
|
60 | - ! $attestationStatement['sig'] instanceof ByteBuffer |
|
59 | + !array_key_exists('sig', $attestationStatement) || |
|
60 | + !$attestationStatement['sig'] instanceof ByteBuffer |
|
61 | 61 | ) { |
62 | 62 | throw new WebauthnException('No signature found'); |
63 | 63 | } |
64 | 64 | |
65 | 65 | if ( |
66 | - ! array_key_exists('x5c', $attestationStatement) || |
|
67 | - ! is_array($attestationStatement['x5c']) || |
|
66 | + !array_key_exists('x5c', $attestationStatement) || |
|
67 | + !is_array($attestationStatement['x5c']) || |
|
68 | 68 | count($attestationStatement['x5c']) !== 1 |
69 | 69 | ) { |
70 | 70 | throw new WebauthnException('Invalid X5C certificate'); |
71 | 71 | } |
72 | 72 | |
73 | - if (! $attestationStatement['x5c'][0] instanceof ByteBuffer) { |
|
73 | + if (!$attestationStatement['x5c'][0] instanceof ByteBuffer) { |
|
74 | 74 | throw new WebauthnException('Invalid X5C certificate'); |
75 | 75 | } |
76 | 76 |
@@ -12,8 +12,7 @@ |
||
12 | 12 | * @class FidoU2F |
13 | 13 | * @package Platine\Webauthn\Attestation\Format |
14 | 14 | */ |
15 | -class FidoU2F extends BaseFormat |
|
16 | -{ |
|
15 | +class FidoU2F extends BaseFormat { |
|
17 | 16 | /** |
18 | 17 | * The algorithm used |
19 | 18 | * @var int |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | - * {@inheritdoc} |
|
92 | - */ |
|
91 | + * {@inheritdoc} |
|
92 | + */ |
|
93 | 93 | public function getCertificatePem(): ?string |
94 | 94 | { |
95 | 95 | if (empty($this->x5c)) { |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * {@inheritdoc} |
|
104 | - */ |
|
103 | + * {@inheritdoc} |
|
104 | + */ |
|
105 | 105 | public function validateAttestation(string $clientData): bool |
106 | 106 | { |
107 | 107 | if (! empty($this->x5c)) { |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | - * {@inheritdoc} |
|
116 | - */ |
|
115 | + * {@inheritdoc} |
|
116 | + */ |
|
117 | 117 | public function validateRootCertificate(array $rootCertificates): bool |
118 | 118 | { |
119 | 119 | if (empty($this->x5c)) { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | // check u2f data |
47 | 47 | $attestationStatement = $this->attestationData['attStmt']; |
48 | 48 | if ( |
49 | - ! array_key_exists('alg', $attestationStatement) || |
|
49 | + !array_key_exists('alg', $attestationStatement) || |
|
50 | 50 | $this->getCoseAlgorithm($attestationStatement['alg']) === null |
51 | 51 | ) { |
52 | 52 | throw new WebauthnException(sprintf( |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | if ( |
59 | - ! array_key_exists('sig', $attestationStatement) || |
|
60 | - ! $attestationStatement['sig'] instanceof ByteBuffer |
|
59 | + !array_key_exists('sig', $attestationStatement) || |
|
60 | + !$attestationStatement['sig'] instanceof ByteBuffer |
|
61 | 61 | ) { |
62 | 62 | throw new WebauthnException('No signature found'); |
63 | 63 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | ) { |
73 | 73 | // The attestation certificate attestnCert MUST be the first element in the array |
74 | 74 | $attestCert = array_shift($attestationStatement['x5c']); |
75 | - if (! $attestCert instanceof ByteBuffer) { |
|
75 | + if (!$attestCert instanceof ByteBuffer) { |
|
76 | 76 | throw new WebauthnException('Invalid X5C certificate'); |
77 | 77 | } |
78 | 78 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function validateAttestation(string $clientData): bool |
106 | 106 | { |
107 | - if (! empty($this->x5c)) { |
|
107 | + if (!empty($this->x5c)) { |
|
108 | 108 | return $this->validateOverX5C($clientData); |
109 | 109 | } |
110 | 110 |
@@ -12,8 +12,7 @@ |
||
12 | 12 | * @class Packed |
13 | 13 | * @package Platine\Webauthn\Attestation\Format |
14 | 14 | */ |
15 | -class Packed extends BaseFormat |
|
16 | -{ |
|
15 | +class Packed extends BaseFormat { |
|
17 | 16 | /** |
18 | 17 | * The algorithm used |
19 | 18 | * @var int |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | 'hash' => 'SHA1', |
189 | 189 | 'openssl' => OPENSSL_ALGO_SHA1, |
190 | 190 | 'cose' => [ |
191 | - -65535, // RS1 |
|
191 | + -65535, // RS1 |
|
192 | 192 | ], |
193 | 193 | ], |
194 | 194 | [ |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | 'openssl' => OPENSSL_ALGO_SHA256, |
197 | 197 | 'cose' => [ |
198 | 198 | -257, // RS256 |
199 | - -37, // PS256 |
|
200 | - -7, // ES256 |
|
201 | - 5, // HMAC256 |
|
199 | + -37, // PS256 |
|
200 | + -7, // ES256 |
|
201 | + 5, // HMAC256 |
|
202 | 202 | ], |
203 | 203 | ], |
204 | 204 | [ |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | 'openssl' => OPENSSL_ALGO_SHA384, |
207 | 207 | 'cose' => [ |
208 | 208 | -258, // RS384 |
209 | - -38, // PS384 |
|
210 | - -35, // ES384 |
|
211 | - 6, // HMAC384 |
|
209 | + -38, // PS384 |
|
210 | + -35, // ES384 |
|
211 | + 6, // HMAC384 |
|
212 | 212 | ], |
213 | 213 | ], |
214 | 214 | [ |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | 'openssl' => OPENSSL_ALGO_SHA512, |
217 | 217 | 'cose' => [ |
218 | 218 | -259, // RS512 |
219 | - -39, // PS512 |
|
220 | - -36, // ES512 |
|
221 | - 7, // HMAC512 |
|
219 | + -39, // PS512 |
|
220 | + -36, // ES512 |
|
221 | + 7, // HMAC512 |
|
222 | 222 | ], |
223 | 223 | ], |
224 | 224 | ]; |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | * @class BaseFormat |
12 | 12 | * @package Platine\Webauthn\Attestation\Format |
13 | 13 | */ |
14 | -abstract class BaseFormat implements JsonSerializable |
|
15 | -{ |
|
14 | +abstract class BaseFormat implements JsonSerializable { |
|
16 | 15 | /** |
17 | 16 | * The attestation object data |
18 | 17 | * @var array<string, mixed> |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | /** |
54 | 53 | * Destructor |
55 | 54 | */ |
56 | - public function __destruct() |
|
57 | - { |
|
55 | + public function __destruct() { |
|
58 | 56 | // delete X.509 chain certificate file after use |
59 | 57 | if ($this->x5cTempFile !== null && is_file($this->x5cTempFile)) { |
60 | 58 | unlink($this->x5cTempFile); |
@@ -112,8 +110,7 @@ discard block |
||
112 | 110 | * {@inheritdoc} |
113 | 111 | * @return mixed |
114 | 112 | */ |
115 | - public function jsonSerialize() |
|
116 | - { |
|
113 | + public function jsonSerialize() { |
|
117 | 114 | return get_object_vars($this); |
118 | 115 | } |
119 | 116 |
@@ -169,9 +169,9 @@ |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * {@inheritdoc} |
|
173 | - * @return mixed |
|
174 | - */ |
|
172 | + * {@inheritdoc} |
|
173 | + * @return mixed |
|
174 | + */ |
|
175 | 175 | public function jsonSerialize() |
176 | 176 | { |
177 | 177 | return get_object_vars($this); |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * {@inheritdoc} |
|
136 | - */ |
|
135 | + * {@inheritdoc} |
|
136 | + */ |
|
137 | 137 | public function getCertificatePem(): ?string |
138 | 138 | { |
139 | 139 | if (empty($this->x5c)) { |
@@ -144,16 +144,16 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * {@inheritdoc} |
|
148 | - */ |
|
147 | + * {@inheritdoc} |
|
148 | + */ |
|
149 | 149 | public function validateAttestation(string $clientData): bool |
150 | 150 | { |
151 | 151 | return $this->validateOverX5C($clientData); |
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * {@inheritdoc} |
|
156 | - */ |
|
155 | + * {@inheritdoc} |
|
156 | + */ |
|
157 | 157 | public function validateRootCertificate(array $rootCertificates): bool |
158 | 158 | { |
159 | 159 | if (empty($this->x5c)) { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | $dataToVerify = $this->authenticatorData->getBinary(); |
207 | 207 | $dataToVerify .= $clientData; |
208 | 208 | |
209 | - // Verify that magic is set to TPM_GENERATED_VALUE. |
|
209 | + // Verify that magic is set to TPM_GENERATED_VALUE. |
|
210 | 210 | if ($this->certInfo->getBytes(0, 4) !== self::TPM_GENERATED_VALUE) { |
211 | 211 | throw new WebauthnException('TPM magic value not the same TPM_GENERATED_VALUE'); |
212 | 212 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $attestationStatement = $this->attestationData['attStmt']; |
63 | 63 | |
64 | 64 | if ( |
65 | - ! array_key_exists('ver', $attestationStatement) || |
|
65 | + !array_key_exists('ver', $attestationStatement) || |
|
66 | 66 | $attestationStatement['ver'] !== '2.0' |
67 | 67 | ) { |
68 | 68 | throw new WebauthnException(sprintf( |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | if ( |
75 | - ! array_key_exists('alg', $attestationStatement) || |
|
75 | + !array_key_exists('alg', $attestationStatement) || |
|
76 | 76 | $this->getCoseAlgorithm($attestationStatement['alg']) === null |
77 | 77 | ) { |
78 | 78 | throw new WebauthnException(sprintf( |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | if ( |
85 | - ! array_key_exists('sig', $attestationStatement) || |
|
86 | - ! $attestationStatement['sig'] instanceof ByteBuffer |
|
85 | + !array_key_exists('sig', $attestationStatement) || |
|
86 | + !$attestationStatement['sig'] instanceof ByteBuffer |
|
87 | 87 | ) { |
88 | 88 | throw new WebauthnException('No signature found'); |
89 | 89 | } |
90 | 90 | |
91 | 91 | if ( |
92 | - ! array_key_exists('certInfo', $attestationStatement) || |
|
93 | - ! $attestationStatement['certInfo'] instanceof ByteBuffer |
|
92 | + !array_key_exists('certInfo', $attestationStatement) || |
|
93 | + !$attestationStatement['certInfo'] instanceof ByteBuffer |
|
94 | 94 | ) { |
95 | 95 | throw new WebauthnException('No certificate information found'); |
96 | 96 | } |
97 | 97 | |
98 | 98 | if ( |
99 | - ! array_key_exists('pubArea', $attestationStatement) || |
|
100 | - ! $attestationStatement['pubArea'] instanceof ByteBuffer |
|
99 | + !array_key_exists('pubArea', $attestationStatement) || |
|
100 | + !$attestationStatement['pubArea'] instanceof ByteBuffer |
|
101 | 101 | ) { |
102 | 102 | throw new WebauthnException('No public area information found'); |
103 | 103 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ) { |
115 | 115 | // The attestation certificate attestnCert MUST be the first element in the array |
116 | 116 | $attestCert = array_shift($attestationStatement['x5c']); |
117 | - if (! $attestCert instanceof ByteBuffer) { |
|
117 | + if (!$attestCert instanceof ByteBuffer) { |
|
118 | 118 | throw new WebauthnException('Invalid X5C certificate'); |
119 | 119 | } |
120 | 120 |
@@ -12,8 +12,7 @@ |
||
12 | 12 | * @class Tpm |
13 | 13 | * @package Platine\Webauthn\Attestation\Format |
14 | 14 | */ |
15 | -class Tpm extends BaseFormat |
|
16 | -{ |
|
15 | +class Tpm extends BaseFormat { |
|
17 | 16 | public const TPM_GENERATED_VALUE = "\xFF\x54\x43\x47"; |
18 | 17 | public const TPM_ST_ATTEST_CERTIFY = "\x80\x17"; |
19 | 18 | /** |
@@ -10,8 +10,7 @@ |
||
10 | 10 | * @class WebauthnConfiguration |
11 | 11 | * @package Platine\Webauthn |
12 | 12 | */ |
13 | -class WebauthnConfiguration extends AbstractConfiguration |
|
14 | -{ |
|
13 | +class WebauthnConfiguration extends AbstractConfiguration { |
|
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
17 | 16 | */ |