Skip to content

Commit 33a5815

Browse files
committed
Re-Namespaced the repo
1 parent 16cf859 commit 33a5815

7 files changed

+33
-31
lines changed

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,27 @@ TODO the descriptions
8484
### Registration Process Flow
8585

8686
1. User navigates to a 2nd factor authentication page in your application.
87+
8788
... TODO add the rest of the registration process flow ...
8889

8990
### Authentication Process Flow
9091

9192
1. User navigates to their login page as they usually would, submits username and password.
92-
2. Server received POST request authentication data, normal username + password validation occurs
93-
3. On successful authentication, the application checks 2nd factor authentication is required. We're going to presume it is, otherwise the user would just be logged in at this stage.
94-
4. Application gets the user's registered signatures from the application datastore: `$registrations`.
95-
5. Application makes a `$U2F->makeAuthentication($registrations)` call, the method returns an array of `SignRequest` objects: `$signRequest`.
96-
6. Application JSON encodes the array and passes the data to the view
97-
7. When the browser loads the page the JavaScript fires the `u2f.sign(sign_requests, function(data){ // Callback logic })` function
98-
8. The view will use JavaScript / Browser to poll the host machine's ports for a FIDO U2F device
99-
9. Once the HID has been found the JavaScript / Browser will send the sign request with data.
100-
10. The HID will prompt the user to authorise the sign request
101-
11. On success the HID returns authentication data
102-
12. The JavaScript receives the HID's returned data and passes it to the server
103-
13. The application takes the returned data passes it to the `$U2F->authenticate($signRequest, $registrations, $incomingData)` method
104-
14. If the method returns a registration and doesn't throw an Exception, authentication is complete.
105-
15. Set the user's session, inform the user of the success, and redirect them.
93+
1. Server received POST request authentication data, normal username + password validation occurs
94+
1. On successful authentication, the application checks 2nd factor authentication is required. We're going to presume it is, otherwise the user would just be logged in at this stage.
95+
1. Application gets the user's registered signatures from the application datastore: `$registrations`.
96+
1. Application gets its ID, usually the domain the application is accessible from: `$appId`
97+
1. Application makes a `U2F::makeAuthentication($registrations, $appId)` call, the method returns an array of `SignRequest` objects: `$authenticationRequest`.
98+
1. Application JSON encodes the array and passes the data to the view
99+
1. When the browser loads the page the JavaScript fires the `u2f.sign(authenticationRequest, function(data){ // Callback logic })` function
100+
1. The view will use JavaScript / Browser to poll the host machine's ports for a FIDO U2F device
101+
1. Once the HID has been found the JavaScript / Browser will send the sign request with data.
102+
1. The HID will prompt the user to authorise the sign request
103+
1. On success the HID returns authentication data
104+
1. The JavaScript receives the HID's returned data and passes it to the server
105+
1. The application takes the returned data passes it to the `U2F::authenticate($authenticationRequest, $registrations, $authenticationResponse)` method
106+
1. If the method returns a registration and doesn't throw an Exception, authentication is complete.
107+
1. Set the user's session, inform the user of the success, and redirect them.
106108

107109
## Example Code
108110

@@ -137,7 +139,7 @@ You'll only ever need to use this method call once per installation and only in
137139
<?php
138140

139141
require('vendor/autoload.php');
140-
use Samyoul\U2F;
142+
use Samyoul\U2F\U2FServer\U2FServer as U2F;
141143

142144
var_dump(U2F::checkOpenSSLVersion());
143145
```
@@ -155,7 +157,7 @@ We assume that user has successfully authenticated and wishes to register.
155157
<?php
156158

157159
require('vendor/autoload.php');
158-
use Samyoul\U2F;
160+
use Samyoul\U2F\U2FServer\U2FServer as U2F;
159161

160162
session_start();
161163

@@ -237,7 +239,7 @@ This is the last stage of registration. Validate the registration response data
237239
<?php
238240
239241
require('vendor/autoload.php');
240-
use Samyoul\U2F;
242+
use Samyoul\U2F\U2FServer\U2FServer as U2F;
241243
242244
session_start();
243245
@@ -279,7 +281,7 @@ We assume that user has successfully authenticated and has previously registered
279281
<?php
280282
281283
require('vendor/autoload.php');
282-
use Samyoul\U2F;
284+
use Samyoul\U2F\U2FServer\U2FServer as U2F;
283285
284286
session_start();
285287
@@ -364,7 +366,7 @@ This is the last stage of authentication. Validate the authentication response d
364366
<?php
365367

366368
require('vendor/autoload.php');
367-
use Samyoul\U2F;
369+
use Samyoul\U2F\U2FServer\U2FServer as U2F;
368370

369371
session_start();
370372

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"ext-openssl":"*"
1313
},
1414
"autoload": {
15-
"classmap": ["src/"]
15+
"psr-4": { "Samyoul\\U2F\\U2FServer\\": ["src/"] }
1616
}
1717
}

src/Registration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 14:59
77
*/
88

9-
namespace Samyoul;
9+
namespace Samyoul\U2F\U2FServer;
1010

1111

1212
class Registration

src/RegistrationRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* Date: 09/12/2016
66
* Time: 14:48
77
*/
8-
namespace Samyoul;
8+
namespace Samyoul\U2F\U2FServer;
99

1010

1111
class RegistrationRequest
1212
{
1313
/** Protocol version */
14-
protected $version = U2F::VERSION;
14+
protected $version = U2FServer::VERSION;
1515

1616
/** Registration challenge */
1717
protected $challenge;

src/SignRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* Time: 15:14
77
*/
88

9-
namespace Samyoul;
9+
namespace Samyoul\U2F\U2FServer;
1010

1111

1212
class SignRequest
1313
{
1414
/** Protocol version */
15-
protected $version = U2F::VERSION;
15+
protected $version = U2FServer::VERSION;
1616

1717
/** Authentication challenge */
1818
protected $challenge;

src/U2FException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 14:51
77
*/
88

9-
namespace Samyoul;
9+
namespace Samyoul\U2F\U2FServer;
1010

1111

1212
class U2FException extends \Exception

src/U2F.php renamed to src/U2FServer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Date: 09/12/2016
66
* Time: 14:40
77
*/
8-
namespace Samyoul;
8+
namespace Samyoul\U2F\U2FServer;
99

10-
class U2F
10+
class U2FServer
1111
{
1212
/** Constant for the version of the u2f protocol */
1313
const VERSION = "U2F_V2";
@@ -111,8 +111,8 @@ public static function register(RegistrationRequest $request, $response, $attest
111111
// Begin validating and building the registration
112112
$registration = new Registration();
113113
$offset = 1;
114-
$pubKey = substr($rawRegistration, $offset, U2F::PUBKEY_LEN);
115-
$offset += U2F::PUBKEY_LEN;
114+
$pubKey = substr($rawRegistration, $offset, static::PUBKEY_LEN);
115+
$offset += static::PUBKEY_LEN;
116116

117117
// Validate and set the public key
118118
if(static::publicKeyToPem($pubKey) === null) {
@@ -367,7 +367,7 @@ private static function base64u_decode($data)
367367
*/
368368
private static function publicKeyToPem($key)
369369
{
370-
if(strlen($key) !== U2F::PUBKEY_LEN || $key[0] !== "\x04") {
370+
if(strlen($key) !== static::PUBKEY_LEN || $key[0] !== "\x04") {
371371
return null;
372372
}
373373

0 commit comments

Comments
 (0)