Skip to content

Commit 92ba66a

Browse files
committed
Modernize readme
1 parent b3d85d3 commit 92ba66a

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

README.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ Rollerworks SplitToken Component
33

44
SplitToken provides a Token-Based Authentication Protocol without Side-Channels.
55

6-
This technique is based of [Split Tokens: Token-Based Authentication Protocols without Side-Channels](https://paragonie.com/blog/2017/02/split-tokens-token-based-authentication-protocols-without-side-channels).
6+
This technique is based of [Split Tokens: Token-Based Authentication Protocols without Side-Channels].
7+
Which was first proposed by Paragon Initiative Enterprises.
78

89
SplitToken-Based Authentication is best used for password resetting or one-time
9-
single-logon.
10+
single-logon.
1011

11-
While possible, this technique is not recommended as a replacement for
12+
While possible, this technique is not recommended as a replacement for
1213
OAuth or Json Web Tokens.
1314

1415
## Introduction
@@ -22,45 +23,35 @@ of two parts: The **selector** (used in the query) and the **verifier**
2223

2324
* The verifier works as a password and is only provided to the user,
2425
the database only holds a salted (cryptographic) hash of the verifier.
25-
26+
2627
The length of this value is heavily dependent on the used hashing algorithm
2728
and should not be hardcoded.
28-
29-
The full token is provided to the user or recipient and functions as a combined
29+
30+
The full token is provided to the user or recipient and functions as a combined
3031
identifier (selector) and password (verifier).
3132

3233
**Caution: You NEVER store the full token as-is!** You only store the selector,
3334
and a (cryptographic) hash of the verifier.
3435

35-
## Requirements
36-
37-
PHP 7.2 with the (lib)sodium extension enabled.
38-
3936
## Installation
4037

41-
To install this package, add `rollerworks/split-token` to your composer.json
38+
To install this package, add `rollerworks/split-token` to your composer.json:
4239

4340
```bash
4441
$ php composer.phar require rollerworks/split-token
4542
```
4643

47-
Now, Composer will automatically download all required files, and install them
48-
for you.
44+
Now, [Composer][composer] will automatically download all required files,
45+
and install them for you.
4946

50-
**Caution:** There is no stable version of this library yet, while no major changes
51-
are expected you are advised to upgrade as soon as possible when a new version is
52-
released.
47+
## Requirements
5348

54-
Update your `composer.json` file manually to require the latest version
55-
(avoid using the `dev-master`).
49+
PHP 8.1 with the sodium extension enabled (default since PHP 8).
5650

5751
## Basic Usage
5852

5953
```php
6054
<?php
61-
62-
require 'vendor/autoload.php';
63-
6455
use Rollerworks\Component\SplitToken\Argon2SplitTokenFactory;
6556

6657
// First, create the factory to generate a new SplitToken.
@@ -84,7 +75,7 @@ $token = $splitTokenFactory->generate();
8475
//
8576
//
8677
// AGAIN, DO NOT STORE "THIS" VALUE IN THE DATABASE! Store the selector and verifier-hash instead.
87-
//
78+
//
8879
$authToken = $token->token(); // Returns a \ParagonIE\HiddenString\HiddenString object
8980

9081
// Indicate when the token must expire. Note that you need to clear the token from storage yourself.
@@ -95,7 +86,7 @@ $authToken->expireAt(new \DateTimeImmutable('+1 hour'));
9586
// Now to store the token cast the SplitToken to a SplitTokenValueHolder object.
9687
//
9788
// Unlike SplitToken this class is final and doesn't hold the full-token string.
98-
//
89+
//
9990
// Additionally you store the token with metadata (array only),
10091
// See the linked manual below for more information.
10192
$holder = $token->toValueHolder();
@@ -107,7 +98,7 @@ $holder = $token->toValueHolder();
10798
// recovery_selector = $holder->selector(),
10899
// recovery_verifier = $holder->verifierHash(),
109100
// recovery_expires_at = $holder->expiresAt(),
110-
// recovery_metadata = serialize($holder->metadata()),
101+
// recovery_metadata = json_encode($holder->metadata()),
111102
// recovery_timestamp = NOW()
112103
// WHERE user_id = ...
113104

@@ -121,18 +112,18 @@ $holder = $token->toValueHolder();
121112
$token = $splitTokenFactory->fromString($_GET['token']);
122113

123114
// $result = SELECT user_id, recover_verifier, recovery_expires_at, recovery_metadata WHERE recover_selector = $token->selector()
124-
$holder = new SplitTokenValueHolder($token->selector(), $result['recovery_verifier'], $result['recovery_expires_at'], unserialize($result['recovery_metadata'], ['allowed_classes' => false]));
115+
$holder = new SplitTokenValueHolder($token->selector(), $result['recovery_verifier'], $result['recovery_expires_at'], json_decode($result['recovery_metadata'], true));
125116

126117
if ($token->matches($holder)) {
127118
echo 'OK, you have access';
128119
} else {
129120
// Note: Make sure to remove the token from storage.
130-
121+
131122
echo 'NO, I cannot let you do this John.';
132123
}
133124
```
134125

135-
Once a result is found using the selector, the stored verifier-hash is used to
126+
Once a result is found using the selector, the stored verifier-hash is used to
136127
compute a matching hash of the provided verifier. And the values are compared
137128
in constant-time to protect against side-channel attacks.
138129

@@ -147,7 +138,7 @@ in constant-time to protect against side-channel attacks.
147138
Because of security reasons, a `SplitToken` only throws generic runtime
148139
exceptions for wrong usage, but no detailed exceptions about invalid input.
149140

150-
In the case of an error the memory allocation of the verifier and full token
141+
In the case of an error the memory allocation of the verifier and full token
151142
is zeroed to prevent leakage during a core dump or unhandled exception.
152143

153144
## Versioning
@@ -178,3 +169,8 @@ The Split Token idea was first proposed by Paragon Initiative Enterprises.
178169

179170
The Source Code of this package is subject to the terms of the
180171
Mozilla Public License, version 2.0 ([MPLv2.0 License](LICENSE)).
172+
173+
Which can be safely used with any other license including MIT
174+
and GNU GPL.
175+
176+
[Split Tokens: Token-Based Authentication Protocols without Side-Channels]: https://paragonie.com/blog/2017/02/split-tokens-token-based-authentication-protocols-without-side-channels

0 commit comments

Comments
 (0)