You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+75-98Lines changed: 75 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,14 @@ A PHP implementation of the FIDO U2F authentication standard
4
4
5
5
## Introduction
6
6
7
-
This library is designed to allow easy integration of U2F hardware keys to an
8
-
existing user authentication scheme. It handles the parsing and validating all
9
-
of the raw message formats, and translates them into standard PHP objects.
7
+
This library is designed to allow easy integration of U2F hardware keys to an existing user authentication scheme.
8
+
It handles the parsing and validating all of the raw message formats, and translates them into standard PHP objects.
10
9
11
-
Note that use of the word "key" here refers to a USB "key" or dongle; however,
12
-
the device may connect with the browser over a different protocol (such as
13
-
Bluetooth or NFC). Unless otherwise stated, "key" should be interpreted to mean
14
-
"FIDO U2F Token".
10
+
Note that use of the word "key" here refers to a USB "key" or dongle; however, the device may connect with the browser over a different protocol (such as Bluetooth or NFC).
11
+
Unless otherwise stated, "key" should be interpreted to mean "FIDO U2F Token".
15
12
16
-
There are two main operations that you will need to understand for a successful
17
-
integration: registration and authentication. Registration is the act of
18
-
associating a key that the end-user is physically in posession of with their
19
-
existing account; authentication is where that key is used to cryptographically
20
-
sign a message from your application to verify posession of said key.
13
+
There are two main operations that you will need to understand for a successful integration: registration and authentication.
14
+
Registration is the act of associating a key that the end-user is physically in posession of with their existing account; authentication is where that key is used to cryptographically sign a message from your application to verify posession of said key.
21
15
22
16
Additional resources:
23
17
@@ -26,153 +20,136 @@ Additional resources:
26
20
27
21
## Usage
28
22
29
-
Usage will be described in three parts: setup, registration, and
30
-
authentication. The code in setup should be used before both registration and
31
-
authentication.
23
+
Usage will be described in three parts: setup, registration, and authentication.
24
+
The code in setup should be used before both registration and authentication.
32
25
33
-
The API is designed to "fail loudly"; that is, failures will throw an
34
-
exception, ensuring that return values are always the result of a successful
35
-
operation. This reduces the need for complex error checking and handling during
36
-
use, since the whole thing can be simply wrapped in a `try/catch` block and
37
-
assume that everything went well if no exceptions are caught.
26
+
The API is designed to "fail loudly"; that is, failures will throw an exception, ensuring that return values are always the result of a successful operation.
27
+
This reduces the need for complex error checking and handling during use, since the whole thing can be simply wrapped in a `try/catch` block and assume that everything went well if no exceptions are caught.
38
28
39
29
### Setup
40
30
41
-
All operations are performed by the U2F Server class, so it needs to be
42
-
instanciated and configured:
31
+
All operations are performed by the U2F Server class, so it needs to be instanciated and configured:
The trusted CAs are whitelisted vendors, and must be an array of absolute paths
50
-
to PEM-formatted CA certs (as strings). Some provider certificates are provided
51
-
in the `CACerts/` directory in the repository root; in a deployed project,
52
-
these should be available via `$PROJECT_ROOT/vendor/firehed/u2f/CACerts/*.pem`.
40
+
The trusted CAs are whitelisted vendors, and must be an array of absolute paths to PEM-formatted CA certs (as strings).
41
+
Some provider certificates are provided in the `CACerts/` directory in the repository root; in a deployed project, these should be available via `$PROJECT_ROOT/vendor/firehed/u2f/CACerts/*.pem`.
53
42
54
-
You may also choose to disable CA verification, by calling
55
-
`->disableCAVerification()` instead of `setTrustedCAs()`. This removes trust in
56
-
the hardware vendors, but ensures that as new vendors issue tokens, they will
57
-
be forward-compatible with your website.
43
+
You may also choose to disable CA verification, by calling `->disableCAVerification()` instead of `setTrustedCAs()`.
44
+
This removes trust in the hardware vendors, but ensures that as new vendors issue tokens, they will be forward-compatible with your website.
58
45
59
-
The URI provided to `setAppId()` must be the HTTPS domain component of your
60
-
website. See [FIDO U2F AppID and Facet Specification](https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-appid-and-facets.html#appid-example-1)
61
-
for additional information.
46
+
The URI provided to `setAppId()` must be the HTTPS domain component of your website. See [FIDO U2F AppID and Facet Specification](https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-appid-and-facets.html#appid-example-1) for additional information.
62
47
63
-
The client needs an U2F Javascript API implementation; the example code below
64
-
is based on [Google's implementation](https://github.com/google/u2f-ref-code/blob/master/u2f-gae-demo/war/js/u2f-api.js)
48
+
The client needs an U2F Javascript API implementation; the example code below is based on [Google's implementation](https://github.com/google/u2f-ref-code/blob/master/u2f-gae-demo/war/js/u2f-api.js)
65
49
66
50
### Registration
67
51
68
-
Registering a token to a user's account is a two-step process: generating
69
-
a challenge, and verifying the response to that challenge.
52
+
Registering a token to a user's account is a two-step process: generating a challenge, and verifying the response to that challenge.
70
53
71
54
#### Genrating the challenge
72
55
73
56
Start by generating a challenge:
74
57
75
-
$request = $server->generateRegisterRequest();
58
+
```php
59
+
$request = $server->generateRegisterRequest();
60
+
```
76
61
77
-
Store this object temporarily (probably in a session) since it is needed during
78
-
verification, and send it to the user as JSON.
62
+
Store this object temporarily (probably in a session) since it is needed during verification, and send it to the user as JSON.
79
63
80
-
If the user has already registered one or more keys, you must also generate
81
-
sign requests for the existing registrations:
64
+
If the user has already registered one or more keys, you must also generate sign requests for the existing registrations:
The `$registration` should be associated with the user (typically by persisting
108
-
to a database).
95
+
The `$registration` should be associated with the user (typically by persisting to a database).
109
96
110
-
Registrations SHOULD be persisted as a one-to-many relationship with the user,
111
-
since a user may own multiple keys and may want to associate all of them with
112
-
their account (e.g. a backup key is kept on a spouse's keychain). It is
113
-
RECOMMENDED to use `(user_id, $registration->getKeyHandleWeb())` as a unique
114
-
composite identifier.
97
+
Registrations SHOULD be persisted as a one-to-many relationship with the user, since a user may own multiple keys and may want to associate all of them with their account (e.g. a backup key is kept on a spouse's keychain). It is RECOMMENDED to use `(user_id, $registration->getKeyHandleWeb())` as a unique composite identifier.
115
98
116
-
At minimum, a persisted Registration must store the Key Handle, Counter, and
117
-
Public Key; implementations SHOULD also store the Attestation Certificate
99
+
At minimum, a persisted Registration must store the Key Handle, Counter, and Public Key; implementations SHOULD also store the Attestation Certificate
118
100
119
-
This is not a requirement of the specification, but leads to a better user
120
-
experience.
101
+
This is not a requirement of the specification, but leads to a better user experience.
121
102
122
103
### Authentication
123
104
124
-
Authentication is a similar process as registration: generate challenges to
125
-
sign for each of the user's registrations, and validate the response when
126
-
received.
105
+
Authentication is a similar process as registration: generate challenges to sign for each of the user's registrations, and validate the response when received.
If no exception is thrown, `$registration` will be a Registration object with
156
-
an updated `counter`; you MUST persist this updated counter to wherever the
157
-
registrations are stored. Failure to do so **is insecure** and exposes your
158
-
application to token cloning attacks.
138
+
If no exception is thrown, `$registration` will be a Registration object with an updated `counter`; you MUST persist this updated counter to wherever the registrations are stored.
139
+
Failure to do so **is insecure** and exposes your application to token cloning attacks.
159
140
160
141
## Demo
161
142
162
-
You may try all of this at https://u2f.ericstern.com, and see the corresponding
163
-
code at https://github.com/Firehed/u2f-php-examples
143
+
You may try all of this at https://u2f.ericstern.com, and see the corresponding code at https://github.com/Firehed/u2f-php-examples
164
144
165
-
The example code is only designed to show how the APIs interact with each
166
-
other, and intentionally leaves out best practices such as use of routers and
167
-
dependency inversion containers to keep the examples as simple as possible. See
168
-
its README for more information.
145
+
The example code is only designed to show how the APIs interact with each other, and intentionally leaves out best practices such as use of routers and dependency inversion containers to keep the examples as simple as possible.
146
+
See its README for more information.
169
147
170
148
## Tests
171
149
172
150
If you are using Arcanist, `arc unit` workflows will work as expected.
173
151
174
-
Otherwise, all tests are in the `tests/` directory and can be run with
175
-
`vendor/bin/phpunit tests/`.
152
+
Otherwise, all tests are in the `tests/` directory and can be run with `vendor/bin/phpunit tests/`.
0 commit comments