Skip to content

Commit 3d36d51

Browse files
NFC-66 Example readme updates (review)
Signed-off-by: Sander Kondratjev <sander.kondratjev@nortal.com>
1 parent fd9eeef commit 3d36d51

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class SessionBackedChallengeNonceStore implements ChallengeNonceStore {
7979

8080
## 3. Configure the challenge nonce generator
8181

82-
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](https://github.com/web-eid/web-eid-system-architecture-doc#authentication-1). The challenge nonce generator will be used in the REST endpoint that issues challenges; it is thread-safe and should be scoped as a singleton.
82+
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](https://github.com/web-eid/web-eid-system-architecture-doc#authentication-1). The challenge nonce generator will be used in the filter that issues challenges; it is thread-safe and should be scoped as a singleton.
8383

8484
Configure the challenge nonce generator as follows:
8585

@@ -99,7 +99,7 @@ import eu.webeid.security.challenge.ChallengeNonceStore;
9999

100100
## 4. Add trusted certificate authority certificates
101101

102-
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 either the truststore file, resources or any stream source. We use the [`CertificateLoader`](https://github.com/web-eid/web-eid-authtoken-validation-java/blob/main/src/main/java/eu/webeid/security/certificate/CertificateLoader.java) helper class to load CA certificates from resources here, but consider using [the truststore file](./blob/example/main/src/main/java/eu/webeid/example/config/ValidationConfiguration.java#L104-L123) instead.
102+
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 either the truststore file, resources or any stream source. We use the [`CertificateLoader`](src/main/java/eu/webeid/security/certificate/CertificateLoader.java) helper class to load CA certificates from resources here, but consider loading the truststore file (see [loadTrustedCACertificatesFromTrustStore](example/main/src/main/java/eu/webeid/example/config/ValidationConfiguration.java#L104-L123)) instead.
103103

104104
First, copy the trusted certificates, for example `ESTEID2018.cer`, to `resources/cacerts/`, then load the certificates as follows:
105105

@@ -136,7 +136,7 @@ import eu.webeid.security.validator.AuthTokenValidatorBuilder;
136136

137137
## 6. Add a filter for issuing challenge nonces
138138

139-
Request Filters that issue challenge nonces for regular Web eID and Web eID for Mobile authentication flows are required for authentication.
139+
Request Filters that issue challenge nonces for regular Web eID and Web eID for Mobile authentication flows are required for authentication.
140140
The filters must support POST requests.
141141

142142
The `WebEidChallengeNonceFilter` handles `/auth/challenge` requests and issues a new nonce for regular Web eID authentication flow.
@@ -204,7 +204,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request,
204204
}
205205
```
206206

207-
Both filters are registered in the Spring Security filter chain in ApplicationConfiguration
207+
Both filters are registered in the Spring Security filter chain in ApplicationConfiguration.
208208
See the full implementation [here](example/src/main/java/eu/webeid/example/config/ApplicationConfiguration.java):
209209
```java
210210
http
@@ -222,11 +222,11 @@ Authentication consists of calling the `validate()` method of the authentication
222222

223223
When using [Spring Security](https://spring.io/guides/topicals/spring-security-architecture) with standard cookie-based authentication,
224224

225-
- implement a custom authentication provider that uses the authentication token validator for authentication as shown [here](example/blob/main/src/main/java/eu/webeid/example/security/WebEidAuthenticationProvider.java),
226-
- implement an AJAX authentication processing filter that extracts the authentication token and passes it to the authentication manager as shown [here](example/blob/main/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java),
227-
- configure the authentication provider and authentication processing filter in the application configuration as shown [here](example/blob/main/src/main/java/eu/webeid/example/config/ApplicationConfiguration.java).
225+
- implement a custom authentication provider that uses the authentication token validator for authentication as shown [here](example/src/main/java/eu/webeid/example/security/WebEidAuthenticationProvider.java),
226+
- implement an AJAX authentication processing filter that extracts the authentication token and passes it to the authentication manager as shown [here](example/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java),
227+
- configure the authentication provider and authentication processing filter in the application configuration as shown [here](example/src/main/java/eu/webeid/example/config/ApplicationConfiguration.java).
228228

229-
The gist of the validation is [in the `authenticate()` method](example/blob/main/src/main/java/eu/webeid/example/security/WebEidAuthenticationProvider.java#L74-L76) of the authentication provider:
229+
The gist of the validation is [in the `authenticate()` method](example/src/main/java/eu/webeid/example/security/WebEidAuthenticationProvider.java#L74-L76) of the authentication provider:
230230

231231
```java
232232
try {
@@ -235,7 +235,7 @@ try {
235235
final var signingCertificate = requireSigningCert && !CollectionUtils.isEmpty(authToken.getUnverifiedSigningCertificates())
236236
? authToken.getUnverifiedSigningCertificates().getFirst() // NOTE: Handling multiple signing certificates is out of scope of this example.
237237
: null;
238-
return WebEidAuthentication.fromCertificate(userCertificate, signingCertificate, authorities);
238+
return WebEidAuthentication.fromCertificate(userCertificate, signingCertificate, authorities);
239239
} catch (AuthTokenException e) {
240240
...
241241
```
@@ -259,7 +259,7 @@ try {
259259
260260
# Introduction
261261
262-
The Web eID authentication token validation library for Java 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.
262+
The Web eID authentication token validation library for Java 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 or mobile application 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.
263263
264264
The authentication protocol, authentication token format, validation requirements and challenge nonce usage is described in more detail in the [Web eID system architecture document](https://github.com/web-eid/web-eid-system-architecture-doc#authentication-1).
265265
@@ -358,10 +358,11 @@ The authentication token validation process consists of two stages:
358358
359359
- First, **user certificate validation**: the validator parses the token and extracts the user certificate from the *unverifiedCertificate* field. Then it checks the certificate expiration, purpose and policies. Next it checks that the certificate is signed by a trusted CA and checks the certificate status with OCSP.
360360
- Second, **token signature validation**: the validator validates that the token signature was created using the provided user certificate by reconstructing the signed data `hash(origin)+hash(challenge)` and using the public key from the certificate to verify the signature in the `signature` field. If the signature verification succeeds, then the origin and challenge nonce have been implicitly and correctly verified without the need to implement any additional security checks.
361-
- Additional validation for **Web eID authentication tokens (format v1.1)**:
362-
- **Subject match check**: The subject of the signing certificate must match the subject of the authentication certificate.
363-
This ensures both certificates belong to the same user.
364-
- **Signing certificate validation**: Expiration, key usage, and policies are checked. The certificate must be signed by a trusted certificate authority. OCSP is used to verify the revocation status.
361+
- Additional validation for **Web eID authentication tokens (format v1.1)**: the token must contain the `unverifiedSigningCertificates` field with at least one signing certificate entry. Each entry's `supportedSignatureAlgorithms` are validated against the set of allowed cryptographic algorithms, hash functions, and padding schemes. For each signing certificate, the following checks are performed:
362+
- The subject must match the subject of the authentication certificate, ensuring both certificates belong to the same user.
363+
- The issuing authority must match that of the authentication certificate, verified via the Authority Key Identifier (AKI) extension.
364+
- The certificate must not be expired.
365+
- The certificate must contain the non-repudiation key usage bit required for digital signatures.
365366

366367
The website back end must look up 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.
367368

@@ -449,7 +450,7 @@ The authentication protocol requires support for generating challenge nonces, la
449450
450451
The `-Djava.security.egd=file:/dev/./urandom` command line argument is added to `pom.xml` to avoid the risk of having the code execution blocked unexpectedly during random generation. Without this, the JVM uses `/dev/random`, which can block, to seed the `SecureRandom` class.
451452
452-
The authentication protocol requires a REST endpoint that issues challenge nonces as described in section *[6. Add a REST endpoint for issuing challenge nonces](#6-add-a-rest-endpoint-for-issuing-challenge-nonces)*.
453+
The authentication protocol requires a filter that issues challenge nonces as described in section *[6. Add a filter for issuing challenge nonces](#6-add-a-filter-for-issuing-challenge-nonces)*.
453454
454455
Nonce usage is described in more detail in the [Web eID system architecture document](https://github.com/web-eid/web-eid-system-architecture-doc#authentication-1).
455456
@@ -469,18 +470,18 @@ The `generateAndStoreNonce()` method both generates the nonce and saves it in th
469470
470471
## Extended configuration
471472
472-
The following additional configuration options are available in `NonceGeneratorBuilder`:
473+
The following additional configuration options are available in `ChallengeNonceGeneratorBuilder`:
473474
474475
- `withNonceTtl(Duration duration)` – overrides the default challenge nonce time-to-live duration. When the time-to-live passes, the nonce is considered to be expired. Default challenge nonce time-to-live is 5 minutes.
475476
- `withSecureRandom(SecureRandom)` - allows to specify a custom `SecureRandom` instance.
476477
477478
Extended configuration example:
478479
```java
479-
NonceGenerator generator = new NonceGeneratorBuilder()
480-
.withChallengeNonceStore(store)
481-
.withNonceTtl(Duration.ofMinutes(5))
482-
.withSecureRandom(customSecureRandom)
483-
.build();
480+
ChallengeNonceGenerator generator = new ChallengeNonceGeneratorBuilder()
481+
.withChallengeNonceStore(store)
482+
.withNonceTtl(Duration.ofMinutes(5))
483+
.withSecureRandom(customSecureRandom)
484+
.build();
484485
```
485486
486487
# Differences between version 1 and version 2
@@ -495,10 +496,9 @@ The Web eID authentication protocol defines two token formats currently supporte
495496
496497
- **Format v1.0** – Used in desktop Web eID authentication flows with traditional smart card readers.
497498
498-
- **Format v1.1** – An extended token format introduced for broader device compatibility and improved interoperability.
499-
In addition to the fields present in v1.0, it includes:
500-
- `unverifiedSigningCertificates` – an array of signing certificate entries. Each entry contains:
501-
- `certificate` – a base64-encoded DER-encoded signing certificate;
502-
- `supportedSignatureAlgorithms` – a list of supported signature algorithms associated with that certificate;
499+
- **Format v1.1** – An extended authentication token format that allows including signing certificate information in the authentication response.
500+
- `unverifiedSigningCertificates` – an array of signing certificate entries. Each entry contains:
501+
- `certificate` – a base64-encoded DER-encoded signing certificate;
502+
- `supportedSignatureAlgorithms` – a list of supported signature algorithms associated with that certificate;
503503
504504
Both token formats follow the same validation principles, differing only in the structure of embedded certificates and the additional verification steps required for v1.1.

0 commit comments

Comments
 (0)