Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This outdated and not supported anymore. Please see to the documentation of the last release.
Webauthn defines an API enabling the creation and use of strong, attested, scoped, public key-based credentials by web applications, for the purpose of strongly authenticating users.
This framework contains PHP libraries and Symfony bundle to allow developpers to integrate that authentication mechanism into their web applications.
Attestation Types
Empty
Basic
Self
Private CA
Elliptic Curve Direct Anonymous Attestation (ECDAA)
Attestation Formats
FIDO U2F
Packed
TPM
Android Key
Android Safetynet
Token Binding support
Cose Algorithms
RS1, RS256, RS384, RS512
PS256, PS384, PS512
ES256, ES256K, ES384, ES512
ED25519
Extensions
Supported (not fully tested)
appid extension
The compliance of the framework is ensured by running unit and functional tests during its development.
It is also tested using the official FIDO Alliance testing tools. The status of the compliance tests are reported in this issue. At the time of writing (end of Oct. 2019), the main features and algorithms are supported. Full compliance with the Webatuhn specification is expected by the end of Nov. 2019.
In any case, the framework can already compatible with all authenticators except the one that use ECDAA Attestation format. As this format is very rare at that time, this framework can safely be used in production.
After the registration of an authenticator, you will get a Public Key Credential Source object. It contains all the credential data needed to perform user authentication and much more.
Each Credential Source is managed using the Public Key Credential Source Repository.
The library does not provide any concrete implementation. It is up to you to create it depending on your application constraints. This only constraint is that your repository class must implement the interface Webauthn\PublicKeyCredentialSourceRepository
.
Please don’t use this example in production! It will store credential source objects in a temporary folder.
_Y_ou must add custom Doctrine types to convert plain PHP objects into your ORM. Please have a look at this folder to find examples.
If you use Symfony, this repository already exists and custom Doctrine types are automatically registered.
This framework contains several sub-packages that you don’t necessarily need. It is highly recommended to install what you need and not the whole framework.
The prefered way to install the library you need is to use composer:
Hereafter the dependency tree:
web-auth/webauthn-lib
: this is the core library. This package can be used in any PHP project or within any popular framework (Laravel, CakePHP…)
web-auth/webauthn-symfony-bundle
: this is a Symfony bundle that ease the integration of this authentication mechanism in your Symfony project.
web-auth/conformance-toolset
: this component helps you to verify your application is compliant with the specification. It is meant to be used with the FIDO Alliance Tools. You usually don’t need it.
The core library also depends on web-auth/cose-lib
and web-auth/metadata-service
. What are these dependencies?
web-auth/cose-lib
contains several cipher algorithms and COSE key support to verify the digital signatures sent by the authenticators during the creation and authentication ceremonies. These algorithms are compliant with the RFC8152. This library can be used by any other PHP projects. At the moment only signature algorithms are available, but it is planned to add encryption algorithms
web-auth/metadata-service
provides classes to support the Fido Alliance Metadata Service. If you plan to use Attestation Statements during the creation ceremony, this service is mandatory. Please note that Attestation Statements decreases the user privacy as they may leak data that allow to identify a specific user. The use of Attestation Statements and this service are generally not recommended unless you REALLY need this information. This library can also be used by any other PHP projects.
The Relying Party (or rp
) corresponds to the application that will ask for the user to interact with the authenticator.
The library provides a simple class to handle the rp information: Webauthn\PublicKeyCredentialRpEntity
.
This $rpEntity
object will be useful for the next steps.
The ID can be null
, the domain or sub-domain of your application.
Even if it is optional, we highly recommend to set the application ID. If absent, the current domain will be used
The scheme, userinfo, port, path, user… are not allowed.
Example: www.sub.domain.com
, sub.domain.com
, domain.com
but not com
, www.sub.domain.com:1337
, https://domain.com:443
, sub.domain.com/index
, https://user:password@www.domain.com
.
Your application may also have a logo. You can indicate this logo as third argument. Please note that for safety reason this icon is a priori authenticated URL i.e. an image that uses the data
scheme.
The Webauthn specification does not set any limit for the length of the third argument.
The icon may be ignored by browsers, especially if its length is greater than 128 bytes.
Now we want to register a new authenticator and attach it to a user. This step can be done during the creation of a new user account or if the user already exists and you want to add another authenticator.
You can attach several authenticators to a user account. It is recommended in case of lost devices or if the user get access on your application using multiple platforms (smartphone, laptop…).
To register a new authenticator, you need to generate and send a set of options to it. These options defined in a Webauthn\PublicKeyCredentialCreationOptions
object.
To generate that object, you just need to call the methodgeneratePublicKeyCredentialCreationOptions
of the $server
object. This method requires a Webauthn\PublicKeyCredentialUserEntity
object that represents the user entity to be associated with this new authenticator.
Now send the options to the authenticator using your favorite Javascript framework, library or the example availbale in the Javascript page.
The Public Key Credential Creation Options object (variable $publicKeyCredentialCreationOptions
) can be serialized into JSON.
The variable $publicKeyCredentialCreationOptions
and $userEntity
have to be stored somewhere. These are needed during the next step. Usually these values are set in the session or solutions like Redis.
When the authenticator send you the computed response (i.e. the user touched the button, fingerprint reader, submitted the PIN…), you can load it and check it.
The authenticator response looks similar to the following example:
The library needs PSR-7 requests. In the example below, we use nyholm/psr7-server
to get that request.
In the Webauthn context, ther are two ceremonies:
The attestation ceremony: it corresponds to the registration of a new authenticator,
The assertion ceremony: it is used for the authentication of a user.
For both ceremonies, there are two steps to permform:
The creation of options: these options are sent to the authenticator and indicate what to do and how.
The response of the authenticator: after the user interacted with the authenticator, the authenticator compute a response that have to be verified.
Depending on the options and the capabilities of the authenticator, the user interaction may differ. It can be a simple touch on a button or a complete authentication using biometric means (PIN code, fingerprint, facial recognition…).
A User Entity object represents a user in the Webauthn context. It has the following constraints:
The user ID must be unique and must be a string,
The username must be unique,
Hereafter a minimalist example of user entity:
The username can be composed of any displayable characters, including emojies. Username "😝🥰😔" is perfectly valid.
For privacy reasons, it is not recommended to use the e-mail as username.
As for the rp
Entity, the User Entity may have an icon. This icon must also be secured.
The Webauthn specification does not set any limit for the length of the icon.
The icon may be ignored by browsers, especially if its length is greater than 128 bytes.
The User Entity Repository manages all Webauthn users of your application.
There is no interface to implement or abstract class to extend so that it should be easy to integrate it in your application. You may already have a user repository.
Whatever the database you use(MySQL, pgSQL…), it is not necessary to create relationships between your users and the Credential Sources.
Hereafter an example of a User Entity repository. In this example we suppose you already have methods to find users using their username or ID.
To be written
Symfony is a very popular framework and an official bundle is provided in the package web-auth/webauthn-symfony-bundle
.
If you use Laravel, you may be intersted in this project: https://github.com/asbiin/laravel-webauthn
If you are using Symfony Flex then the bundle will automatically be installed. Otherwise you need to add it in your AppKernel.php
file:
At the moment, only Doctrine is supported, however there is no technical constraint to allow other data storage systems.
The minimal configuration requires the user repository and the pk credential source repository.
Now you may want to:
To authenticate your users, you need to create a PublicKeyCredentialRequestOptions
object. You can create this object using the .... Similarly to the authentication registration process, there is another approach.
The bundle provides a factory and manages profiles to ease the creation of the options. The factory is available as a public service: Webauthn\Bundle\Service\PublicKeyCredentialRequestOptionsFactory
. To use it, you must first create a least one profile in your configuration file.
No other option is needed to create a profile!
With this profile, now we can create options with the following code lines:
As mentioned earlier, it is preferable to indicate the Relying Party ID. By default it is set to null
i.e. the current domain is used.
By default, the length of the challenge is 32 bytes. You may need to select a smaller or higher length. This length can be configured for each profile:
The default timeout is set to 60 seconds (60 000 milliseconds). You can change this value as follow:
By default, the authenticator will verify the user if it is possible. You can enforce or disable the user verification using this option.
The mechanism for generating public key credentials, as well as requesting and generating Authentication assertions, can be extended to suit particular use cases. Each case is addressed by defining a registration extension.
The example below is tatolly fictive. Some extensions are defined in the specification but the supports depends on the authenticators and on the relying parties.
To authenticate your users, you can follow the steps described on the previous page. But as Symfony offers a firewall, you may prefer to use it instead of writing a new authentication process and get all advantages of this firewall.
First of all, you must install the dedicated bundle: symfony/security-bundle
.
Next, you must create a request profile as showed here.
Then, you must have a PSR-7 message factory service. We recommend the use of nyholm/psr7
, but feel free to use any other compatible library.
The PSR-7 Message Factory shall be available as a service.
That's it! You can now protect any route as usual.
Prior to the authentication of the user, you must get a PublicKey Credential Request Options object. To do so, send a POST request to /login/options
.
The body of this request is a JSON object that must contain a username
member with the name of the user being authenticated.
It is mandatory to set the Content-Type header to application/json
.
In case of success, you receive a valid PublicKeyCredentialRequestOptions
object and your user will be asked to interact with its security devices.
The default path is /login/options
. You can change it if needed:
When the user touched the security device, you will receive a response from it. You just have to send a POST request to /login
.
The body of this request is the response of the security device.
It is mandatory to set the Content-Type header to application/json
.
The default path is /assertion/result
. You can change that path is needed:
Your user can now be authenticated and retrieved as usual.
You can customize the responses returned by the firewall by using a custom handler. This could be useful when using an access token manager (e.g. LexikJWTAuthenticationBundle) or to modify the responses.
There are 3 types of responses and handlers:
Request options,
Authentication Success,
Authentication Failure,
This handler is called when a client sends a valid POST request to the options_path
. The default Request Options Handler is Webauthn\Bundle\Security\Handler\DefaultRequestOptionsHandler
. It returns a JSON Response with the Public Key Credential Request Options objects in its body.
Your custom handler have to implement the interface Webauthn\Bundle\Security\Handler\RequestOptionsHandler
and be declared as a service.
When done, you can set your new service in the firewall configuration:
This handler is called when a client sends a valid assertion from the authenticator. The default handler is Webauthn\Bundle\Security\Handler\DefaultSuccessHandler
.
Your custom handler have to implement the interface Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface
and be declared as a container service.
When done, you can set your new service in the firewall configuration:
This handler is called when an error occurred during the authentication process. The default handler is Webauthn\Bundle\Security\Handler\DefaultFailureHandler
.
Your custom handler have to implement the interface Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface
and be declared as a container service.
When done, you can set your new service in the firewall configuration:
Webauthn authentication is a 2 steps round trip authentication:
Request options issuance
Authenticator assertion verification
It is needed to store the request options and the user entity associated to it to verify the authenticator assertions.
By default, the firewall uses Webauthn\Bundle\Security\Storage\SessionStorage
. This storage system stores the data in a session.
If this behaviour does not fit on your needs (e.g. you want to use a database, REDIS…), you can implement a custom data storage for that purpose. Your custom storage system have to implement Webauthn\Bundle\Security\Storage\RequestOptionsStorage
and declared as a container service.
When done, you can set your new service in the firewall configuration:
The security token returned by the firewall sets some attributes depending on the assertion and the capabilities of the authenticator. The attributes are:
IS_USER_PRESENT
: the user was present during the authentication ceremony. This attribute is usually set to true
by Webauthn authenticators,
IS_USER_VERIFIED
: the user was verified by the authenticator. Verification may be performed by several means including biometrics ones (fingerprint, iris, facial recognition…).
You can then set constraints to the access controls.
The easiest way to create a Webauthn Server is to use the class Webauthn\Server
.
That’s it!
You can now register a new authenticator or authenticate your users.
To authenticate you user, you need to send a Webauthn\PublicKeyCredentialRequestOptions
object. using your $server
object, call the method generatePublicKeyCredentialRequestOptions
In general, to authenticate your user you will ask them for their username first. With this username and your user repository, you will find the associated Webauthn\PublicKeyCredentialUserEntity
.
And with the user entity you will get all associated Public Key Credential Source objects. The credential list is used to build the Public Key Credential Request Options.
Now send the options to the authenticator using your favorite Javascript framework, library or the example availbale in the Javascript page.
When the authenticator send you the computed response (i.e. the user touched the button, fingerprint reader, submitted the PIN…), you can load it and check it.
The authenticator response looks similar to the following example:
The library needs PSR-7 requests. In the example below, we use nyholm/psr7-server
to get that request.
You will interact with the authenticators through an HTML page and Javascript using the Webauthn API.
No script is provided with the library because it could become hard to manage all types of scripts and application specificity. However, you will find on this page two JS scripts: the first one for the registration of an authenticator (Attestation Ceremony). The other one for the user authentication (Assertion Ceremony).
Feel free to adapt these script for your application (React, Vue…).
Disclaimer: you should not ask for the Attestation Statement unless you are working on an application that requires a high level of trust (e.g. Banking/Financial Company, Government Agency...).
During the Attestation Ceremony (i.e. the registration of the authenticator), you can ask for the Attestation Statement of the authenticator. The Attestation Statements have one of the following types:
None (none
): no Attestation Statement is provided
Basic Attestation (basic
): Authenticator’s attestation key pair is specific to an authenticator model.
Surrogate Basic Attestation (or Self Attestation - self
): Authenticators that have no specific attestation key use the credential private key to create the attestation signature
Attestation CA (AttCA
): Authenticators are based on a Trusted Platform Module (TPM). They can generate multiple attestation identity key pairs (AIK) and requests an Attestation CA to issue an AIK certificate for each.
Elliptic Curve based Direct Anonymous Attestation (ECDAA
): Authenticator receives direct anonymous attestation (DAA) credentials from a single DAA-Issuer. These DAA credentials are used along with blinding to sign the attested credential data.
The Metadata Statements are issued by the manufacturers of the authenticators. These statements contain details about the authenticators (supported algorithms, biometric capabilities...) and all the necessary information to verify the Attestation Statements generated during the attestation ceremony.
There are several possible sources to get theses Metadata Statements. The main source is the FIDO Alliance Metadata Service that allows to fetch statements on-demand, but some of them may be provided by other means.
The FIDO Alliance Metadata Service provides a limited number of Metadata Statements. It is mandatory to get the statement from the manufacturer of your authenticators otherwise the Attestation Statement won't be verified and the Attestation Ceremony will fail.
First of all, you must prepare an Attestation Metadata Repository. This service will manage all Metadata Statements depending on there sources (local storage or distant service).
Your Metadata Statement Repository must implement the interface Webauthn\MetadataService\MetadataStatementRepository
that has a unique method findOneByAAGUID(string $aaguid)
.
The library web-auth/metadata-service
provides a concrete class with basic support for local and distant statements with caching system: Webauthn\MetadataService\SimpleMetadataStatementRepository
The example above is very limited and will only allow authenticators manufactured by Yubico to be registered. Make sure to add more sources of Metadata Statements to accept authenticators from other manufacturers.
When the repository is ready, you must inject it to your server.
To be written
With Symfony, every source of Metadata Statement is configured in the application configuration. It will be automatically injected to the services.
By default, no Attestation Statement is asked to the Authenticators (type = none
). To change this behavior, you just have to set the corresponding parameter in the Webauthn\PublicKeyCredentialCreationOptions
object.
There are 3 conveyance modes available using PHP constants provided by the class Webauthn\PublicKeyCredentialCreationOptions
:
ATTESTATION_CONVEYANCE_PREFERENCE_NONE
: the Relying Party is not interested in authenticator attestation (default)
ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT
: the Relying Party prefers an attestation conveyance yielding verifiable attestation statements, but allows the client to decide how to obtain such attestation statements.
ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT
: the Relying Party wants to receive the attestation statement as generated by the authenticator.
As described in the previous pages, you need to create a PublicKeyCredentialCreationOptions
object to register new authenticators. You can create this object using the .... But there is another way to do that.
The bundle provides a factory and manages profiles to ease the creation of the options. The factory is available as a public service: Webauthn\Bundle\Service\PublicKeyCredentialCreationOptionsFactory
. To use it, you must first create a least one profile in your configuration file.
The name
is mandatory ; other options are null
by default.
The option id is highly recommended. See this page for acceptable values.
With this profile, now we can create options with the following code lines:
By default, the length of the challenge is 32 bytes. You may need to select a smaller or higher length. This length can be configured for each profile:
The default timeout is set to 60 seconds (60 000 milliseconds). You can change this value as follow:
This set of options allows you to select authenticators depending on their capabilities. The values are described in the advanced concepts of the protocol.
This option indicates the algorithms allowed for your application. By default, a large list of algorithms is defined, but you can add custom algorithms or reduce the list.
The order is important. Preferred algorithms go first.
It is not recommended to change the default list unless you exactly know what you are doing.
If you need the attestation of the authenticator, you can specify the preference regarding attestation conveyance during credential generation.
Please note that the metadata service is mandatory to use this option.
The use of Attestation Statements is generally not recommended unless you REALLY need this information.
The mechanism for generating public key credentials, as well as requesting and generating Authentication assertions, can be extended to suit particular use cases. Each case is addressed by defining a registration extension.
The example below is tatolly fictive. Some extensions are defined in the specification but the supports depends on the authenticators and on the relying parties.
To be written
Browsers may support the Token Binding protocol (see RFC 8471). This protocol defines a way to bind a token (the Responses in the Webauthn context) to the underlying TLS layer.
When receiving a Webauthn Response, the property tokenBinding in the CollectedClientData object have one of the following value:
null
: the token binding is not supported by the browser
"supported"
: the browser supports token binding, but no negociation was performed during the communication
"present"
: the browser supports token binding and is present in the response. The token binding ID is provided.
This feature is not yet implemented in the library, but you can decide how the library will react in case of the presence of the token binding ID.
The library provides two concrete classes for the moment:
Webauthn\TokenBinding\IgnoreTokenBindingHandler
: the library will ignore the token binding,
Webauthn\TokenBinding\TokenBindingNotSupportedHandler
: the library will throw an exception if the token binding is present.
You can change this behavior by creating your own implementation. The handler must implement the interface Webauthn\TokenBinding\TokenBindingHandler
.
To Be Written
To Be Written
To Be Written
By default, any type of authenticator can be used by your users and interact with you application. In certain circumstances, you may need to select specific authenticators e.g. when user verification is required.
The Webauthn API and this library are allow you to define a set of options to disallow the registration of authenticators that do not fulfill with the conditions.
The class Webauthn\AuthenticatorSelectionCriteria is designed for this purpose. It is used when generating the Webauthn\PublicKeyCredentialCreationOptions object.
You can indicate if the authenticator must be attached to the client (platform authenticator i.e. it is usually not removable from the client device) or must be detached (roaming authenticator).
Possible values are:
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE
: there is no requirement (default value),
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_PLATFORM
: the authenticator must be attached,
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM
: must be a roaming authenticator.
A primary use case for platform authenticators is to register a particular client device as a "trusted device" for future authentication. This gives the user the convenience benefit of not needing a roaming authenticator, e.g., the user will not have to dig around in their pocket for their key fob or phone.
When this criteria is set to true
, a Public Key Credential Source will be stored in the authenticator, client or client device. Such storage requires an authenticator capable to store such resident credential.
This criteria is needed if you want to authenticate users without username.
User verification may be instigated through various authorization gesture modalities: a touch plus PIN code, password entry, or biometric recognition (presenting a fingerprint).The intent is to be able to distinguish individual users.
Possible values are:
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE
: the authenticator should verify the user if possible (default value),
AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_REQUIRED
: the authenticator must verify the user,
AuthenticatorSelectionCriteria::USER_VERIFICATION_DISCOURAGED
: the authenticator must NOT try to verify the user. This option may be set in the interest of minimizing disruption to the user interaction flow.
To be written
To be written
With Webauthn, it is possible to authenticate a user without username. This behavior implies several constraints:
During the registration of the authenticator, a Resident Key must have been asked,
The user verification is required,
The list of allowed authenticators must be empty
In case of failure, you should continue with the standard authentication process i.e. by asking the username of the user.
Selection criterias for the registration of the authenticator:
The Request Options:
With Doctrine, you have to indicate how to store the Credential Source objects. Hereafter an example an entity. In this example we add an entity id
and a custom field created_at
. We also indicate the repository as we will have a custom one.
As the ID must have a fixed length and because the credentialId
field of Webauthn\PublicKeyCredentialSource
haven’t such requirement and is a binary string, we need to declare our own id
field.
To ease the integration into your application, the bundle provides a concrete class that you can extend.
In this following example, we extend that class and add a method to get all credentials for a specific user handle. Feel free to add your own methods.
We must override the method saveCredentialSource because we may receive Webauthn\PublicKeyCredentialSource
objects instead of App\Entity\PublicKeyCredentialSource
.
This repository should be declared as a Symfony service.
With Symfony 4, this is usually done automatically
In a Symfony application context, you usually have to manage several user entities. Thus, in the following example, the user entity class will extend the required calls and implements the interface provided by the Symfony Security component.
Feel free to add the necessary setters as well as other fields you need (creation date, last update at…).
Please note that the ID of the user IS NOT generated by Doctrine and must be a string. We highly recommend you to use UUIDs.
The following example uses Doctrine to create, persist or perform queries using the User objects created above.
This repository should be declared as a Symfony service.
With Symfony 4, this is usually done automatically
An Authenticator s a cryptographic entity used generate a public key credential and registered by a Relying Party (i.e. an application). This public key is used to authenticate by potentially verifying a user in the form of an authentication assertion and other data.
Authenticators may have additional features such as PIN code or biometric sensors (fingerprint, facial recognition…) that offer user verification.
The authenticator may have different forms. The most common form is a USB device the user plugs into its computer. It can be a paired Bluetooth device or a card with NFC capabilities.
The authenticator can also be software based and integrated in an Operating System ; for example the smartphone using Android or a laptop with Windows 10 can act as an authenticator.