Download the PHP package web-eid/web-eid-authtoken-validation-php without Composer

On this page you can find all versions of the php package web-eid/web-eid-authtoken-validation-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package web-eid-authtoken-validation-php

web-eid-authtoken-validation-php

European Regional Development Fund

web-eid-authtoken-validation-php is a PHP library for issuing challenge nonces and validating Web eID authentication tokens during secure authentication with electronic ID (eID) smart cards in web applications.

The logic of this repository is based on the Java library. We also draw inspiration from the PHP library created by Petr Muzikant and used some of his code.

More information about the Web eID project is available on the project website.

Quickstart

Complete the steps below to add support for secure authentication with eID cards to your PHP web application back end. Instructions for the front end are available here.

A PHP web application that uses Composer to manage packages is needed for running this quickstart.

1. Add the library to your project

Install using Composer to include the Web eID authentication token validation library in your project:

Logging

For logging, you have to create LoggerInterface and use it on AuthTokenValidatorBuilder initialization.

Example logger interface with Monolog:

Read more about LoggerInterface and take a look from examples directory.

2. Configure the challenge nonce store

The validation library needs to generate authentication challenge nonces and store them for later validation in the challenge nonce store. Overview of challenge nonce usage is provided in the Web eID system architecture document. The challenge nonce generator will be used in the REST endpoint that issues challenges.

PHP Session is been used for storing the challenge nonce.

3. Add trusted certificate authority certificates

You must explicitly specify which intermediate certificate authorities (CAs) are trusted to issue the eID authentication and OCSP responder certificates. CA certificates can be loaded from resources.

First, copy the trusted certificates, for example ESTEID2018.der.cer, to certificates/ folder, then load the certificates as follows:

4. Configure the authentication token validator

Once the prerequisites have been met, the authentication token validator itself can be configured. The mandatory parameters are the website origin and trusted certificate authorities. The authentication token validator will be used in the login processing component of your web application authentication framework

5. Add a REST endpoint for issuing challenge nonces

A REST endpoint that issues challenge nonces is required for authentication. The endpoint must support GET requests.

In the following example, we are using the AltoRouter to implement the endpoint

6. Implement authentication

Authentication consists of calling the validate() method of the authentication token validator. The internal implementation of the validation process is described in more detail below and in the Web eID system architecture document.

See the complete example from the examples directory.

Table of contents

Introduction

The Web eID authentication token validation library for PHP contains the implementation of the Web eID authentication token validation process in its entirety to ensure that the authentication token sent by the Web eID browser extension contains valid, consistent data that has not been modified by a third party. It also implements secure challenge nonce generation as required by the Web eID authentication protocol. It is easy to configure and integrate into your authentication service.

The authentication protocol, authentication token format, validation requirements and challenge nonce usage is described in more detail in the Web eID system architecture document.

Authentication token validation

The authentication token validation process consists of two stages:

The website back end must lookup the challenge nonce from its local store using an identifier specific to the browser session, to guarantee that the authentication token was received from the same browser to which the corresponding challenge nonce was issued. The website back end must guarantee that the challenge nonce lifetime is limited and that its expiration is checked, and that it can be used only once by removing it from the store during validation.

Basic usage

As described in section 4. Configure the authentication token validator, the mandatory authentication token validator configuration parameters are the website origin and trusted certificate authorities.

Origin must be the URL serving the web application. Origin URL must be in the form of "https://" <hostname> [ ":" <port> ] as defined in MDN and not contain path or query components. Note that the origin URL must not end with a slash /.

The trusted certificate authority certificates are used to validate that the user certificate from the authentication token and the OCSP responder certificate is signed by a trusted certificate authority. Intermediate CA certificates must be used instead of the root CA certificates so that revoked CA certificates can be removed. Trusted certificate authority certificates configuration is described in more detail in section 3. Add trusted certificate authority certificates.

Before validation, the previously issued challenge nonce must be looked up from the store using an identifier specific to the browser session. The challenge nonce must be passed to the validate() method in the corresponding parameter. Setting up the challenge nonce store is described in more detail in section 2. Configure the challenge nonce store.

The authentication token validator configuration and construction is described in more detail in section 4. Configure the authentication token validator. Once the validator object has been constructed, it can be used for validating authentication tokens as follows:

The validate() method returns the validated user certificate object if validation is successful or throws an exception as described in section Possible validation errors below if validation fails. The CertificateData class and ucwords function can be used for extracting user information from the user certificate object:

Extended configuration

The following additional configuration options are available in AuthTokenValidatorBuilder:

Extended configuration example:

Certificates' Authority Information Access (AIA) extension

Unless a designated OCSP responder service is in use, it is required that the AIA extension that contains the certificate’s OCSP responder access location is present in the user certificate. The AIA OCSP URL will be used to check the certificate revocation status with OCSP.

Note that there may be limitations to using AIA URLs as the services behind these URLs provide different security and SLA guarantees than dedicated OCSP responder services. In case you need a SLA guarantee, use a designated OCSP responder service.

Possible validation errors

The validate() method of AuthTokenValidator returns the validated user certificate object if validation is successful or throws an exception if validation fails. All exceptions that can occur during validation derive from AuthTokenException, the list of available exceptions is available here. Each exception file contains a documentation comment that describes under which conditions the exception is thrown.

Stateful and stateless authentication

In the code examples above we use the PHP Session based authentication mechanism, where a cookie that contains the user session ID is set during successful login and session data is stored at sever side. Cookie-based authentication must be protected against cross-site request forgery (CSRF) attacks and extra measures must be taken to secure the cookies by serving them only over HTTPS and setting the HttpOnly, Secure and SameSite attributes.

A common alternative to stateful authentication is stateless authentication with JSON Web Tokens (JWT) or secure cookie sessions where the session data resides at the client side browser and is either signed or encrypted. Secure cookie sessions are described in RFC 6896 and in the following article about secure cookie-based Spring Security sessions. Usage of both an anonymous session and a cache is required to store the challenge nonce and the time it was issued before the user is authenticated. The anonymous session must be used for protection against forged login attacks by guaranteeing that the authentication token is received from the same browser to which the corresponding challenge nonce was issued. The cache must be used for protection against replay attacks by guaranteeing that each authentication token can be used exactly once.

Challenge nonce generation

The authentication protocol requires support for generating challenge nonces, large random numbers that can be used only once, and storing them for later use during token validation. The validation library uses the random_bytes (or openssl_random_pseudo_bytes) PHP built-in function as the secure random source and the ChallengeNonceStore interface for storing issued challenge nonces.

The authentication protocol requires a REST endpoint that issues challenge nonces as described in section 5. Add a REST endpoint for issuing challenge nonces.

Nonce usage is described in more detail in the Web eID system architecture document.

Basic usage

As described in section 2. Configure the nonce generator, the are no mandatory configuration parameters for the challenge nonce generator. It uses PHP Session as default storage.

The challenge nonce store is used to save the nonce value along with the nonce expiry time. It must be possible to look up the challenge nonce data structure from the store using an identifier specific to the browser session. The values from the store are used by the token validator as described in the section Authentication token validation > Basic usage that also contains recommendations for store usage and configuration.

The nonce generator configuration and construction is described in more detail in section 3. Configure the nonce generator. Once the generator object has been constructed, it can be used for generating nonces as follows:

The generateAndStoreNonce() method both generates the nonce and saves it in the store.

Extended configuration

The following additional configuration options are available in ChallengeNonceGeneratorBuilder:

Extended configuration example:

Example implementation

Take the files from the examples folder and change the tokenValidator site origin.

Execute the following composer commands:

Please note, that there are no certificate files included in this example. You can find certificates from here

Dependency versioning policy

Starting from version 1.2.0 we adopt a flexible versioning policy for phpseclib and guzzlehttp, and specify the dependency version as x.y.*. This approach allows our library integrators to quickly incorporate security patches and minor updates from dependencies.

Why we include composer.lock

While it is common practice for applications to include a composer.lock file to lock down the specific versions of dependencies used, this is less common for libraries. However, we have chosen to include composer.lock in our repository to clearly indicate the exact versions of dependencies we have tested against.

Although our library is designed to work with any minor version of dependencies within the specified range, the composer.lock file ensures that integrators are aware of the specific version we consider stable and secure. The provided composer.lock is intended to be used as a reference, not as a strict requirement.

Code formatting

We are using Prettier for code formatting. To install Prettier, use following command:

Run command for code formatting:

Testing

Run phpunit in the root directory to run all unit tests.


All versions of web-eid-authtoken-validation-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
phpseclib/phpseclib Version 3.0.*
guzzlehttp/psr7 Version 2.6.*
web-eid/ocsp-php Version 1.1.*
psr/log Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package web-eid/web-eid-authtoken-validation-php contains the following files

Loading the files please wait ....