Skip to content

Commit

Permalink
Re-Namespaced the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyoul committed Dec 13, 2016
1 parent 16cf859 commit 33a5815
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,27 @@ TODO the descriptions
### Registration Process Flow

1. User navigates to a 2nd factor authentication page in your application.

... TODO add the rest of the registration process flow ...

### Authentication Process Flow

1. User navigates to their login page as they usually would, submits username and password.
2. Server received POST request authentication data, normal username + password validation occurs
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.
4. Application gets the user's registered signatures from the application datastore: `$registrations`.
5. Application makes a `$U2F->makeAuthentication($registrations)` call, the method returns an array of `SignRequest` objects: `$signRequest`.
6. Application JSON encodes the array and passes the data to the view
7. When the browser loads the page the JavaScript fires the `u2f.sign(sign_requests, function(data){ // Callback logic })` function
8. The view will use JavaScript / Browser to poll the host machine's ports for a FIDO U2F device
9. Once the HID has been found the JavaScript / Browser will send the sign request with data.
10. The HID will prompt the user to authorise the sign request
11. On success the HID returns authentication data
12. The JavaScript receives the HID's returned data and passes it to the server
13. The application takes the returned data passes it to the `$U2F->authenticate($signRequest, $registrations, $incomingData)` method
14. If the method returns a registration and doesn't throw an Exception, authentication is complete.
15. Set the user's session, inform the user of the success, and redirect them.
1. Server received POST request authentication data, normal username + password validation occurs
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.
1. Application gets the user's registered signatures from the application datastore: `$registrations`.
1. Application gets its ID, usually the domain the application is accessible from: `$appId`
1. Application makes a `U2F::makeAuthentication($registrations, $appId)` call, the method returns an array of `SignRequest` objects: `$authenticationRequest`.
1. Application JSON encodes the array and passes the data to the view
1. When the browser loads the page the JavaScript fires the `u2f.sign(authenticationRequest, function(data){ // Callback logic })` function
1. The view will use JavaScript / Browser to poll the host machine's ports for a FIDO U2F device
1. Once the HID has been found the JavaScript / Browser will send the sign request with data.
1. The HID will prompt the user to authorise the sign request
1. On success the HID returns authentication data
1. The JavaScript receives the HID's returned data and passes it to the server
1. The application takes the returned data passes it to the `U2F::authenticate($authenticationRequest, $registrations, $authenticationResponse)` method
1. If the method returns a registration and doesn't throw an Exception, authentication is complete.
1. Set the user's session, inform the user of the success, and redirect them.

## Example Code

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

require('vendor/autoload.php');
use Samyoul\U2F;
use Samyoul\U2F\U2FServer\U2FServer as U2F;

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

require('vendor/autoload.php');
use Samyoul\U2F;
use Samyoul\U2F\U2FServer\U2FServer as U2F;

session_start();

Expand Down Expand Up @@ -237,7 +239,7 @@ This is the last stage of registration. Validate the registration response data
<?php
require('vendor/autoload.php');
use Samyoul\U2F;
use Samyoul\U2F\U2FServer\U2FServer as U2F;
session_start();
Expand Down Expand Up @@ -279,7 +281,7 @@ We assume that user has successfully authenticated and has previously registered
<?php
require('vendor/autoload.php');
use Samyoul\U2F;
use Samyoul\U2F\U2FServer\U2FServer as U2F;
session_start();
Expand Down Expand Up @@ -364,7 +366,7 @@ This is the last stage of authentication. Validate the authentication response d
<?php

require('vendor/autoload.php');
use Samyoul\U2F;
use Samyoul\U2F\U2FServer\U2FServer as U2F;

session_start();

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"ext-openssl":"*"
},
"autoload": {
"classmap": ["src/"]
"psr-4": { "Samyoul\\U2F\\U2FServer\\": ["src/"] }
}
}
2 changes: 1 addition & 1 deletion src/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 14:59
*/

namespace Samyoul;
namespace Samyoul\U2F\U2FServer;


class Registration
Expand Down
4 changes: 2 additions & 2 deletions src/RegistrationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* Date: 09/12/2016
* Time: 14:48
*/
namespace Samyoul;
namespace Samyoul\U2F\U2FServer;


class RegistrationRequest
{
/** Protocol version */
protected $version = U2F::VERSION;
protected $version = U2FServer::VERSION;

/** Registration challenge */
protected $challenge;
Expand Down
4 changes: 2 additions & 2 deletions src/SignRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* Time: 15:14
*/

namespace Samyoul;
namespace Samyoul\U2F\U2FServer;


class SignRequest
{
/** Protocol version */
protected $version = U2F::VERSION;
protected $version = U2FServer::VERSION;

/** Authentication challenge */
protected $challenge;
Expand Down
2 changes: 1 addition & 1 deletion src/U2FException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 14:51
*/

namespace Samyoul;
namespace Samyoul\U2F\U2FServer;


class U2FException extends \Exception
Expand Down
10 changes: 5 additions & 5 deletions src/U2F.php → src/U2FServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Date: 09/12/2016
* Time: 14:40
*/
namespace Samyoul;
namespace Samyoul\U2F\U2FServer;

class U2F
class U2FServer
{
/** Constant for the version of the u2f protocol */
const VERSION = "U2F_V2";
Expand Down Expand Up @@ -111,8 +111,8 @@ public static function register(RegistrationRequest $request, $response, $attest
// Begin validating and building the registration
$registration = new Registration();
$offset = 1;
$pubKey = substr($rawRegistration, $offset, U2F::PUBKEY_LEN);
$offset += U2F::PUBKEY_LEN;
$pubKey = substr($rawRegistration, $offset, static::PUBKEY_LEN);
$offset += static::PUBKEY_LEN;

// Validate and set the public key
if(static::publicKeyToPem($pubKey) === null) {
Expand Down Expand Up @@ -367,7 +367,7 @@ private static function base64u_decode($data)
*/
private static function publicKeyToPem($key)
{
if(strlen($key) !== U2F::PUBKEY_LEN || $key[0] !== "\x04") {
if(strlen($key) !== static::PUBKEY_LEN || $key[0] !== "\x04") {
return null;
}

Expand Down

0 comments on commit 33a5815

Please sign in to comment.