Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions authtoken-validation/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>

Check failure on line 1 in authtoken-validation/pom.xml

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

authtoken-validation/pom.xml has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'

Check failure on line 1 in authtoken-validation/pom.xml

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

authtoken-validation/pom.xml has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>eu.webeid.security</groupId>
<artifactId>web-eid-authtoken-validation</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>authtoken-validation</artifactId>
<packaging>jar</packaging>
<name>authtoken-validation</name>
<description>Web eID authentication token validation library for Java</description>

<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Generate test jar, so test helpers and resources are shared with other modules -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.webeid.ocsp.service;

Check failure on line 1 in authtoken-validation/src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

authtoken-validation/src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'

Check failure on line 1 in authtoken-validation/src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

authtoken-validation/src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'

import java.time.Duration;

public interface FallbackOcspService extends OcspService {
Duration getMaxThisUpdateAge();

Duration getMaxNextUpdateAge();

FallbackOcspService getNextFallback();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: Estonian Information System Authority
// SPDX-License-Identifier: MIT

package eu.webeid.ocsp.service;

import eu.webeid.security.exceptions.AuthTokenException;

import java.security.cert.X509Certificate;

public interface OcspServiceProvider {
OcspService getService(X509Certificate certificate, X509Certificate issuerCertificate) throws AuthTokenException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

package eu.webeid.security.validator;

import eu.webeid.ocsp.exceptions.UserCertificateRevokedException;
import eu.webeid.security.authtoken.WebEidAuthToken;
import eu.webeid.security.certificate.CertificateData;
import eu.webeid.security.exceptions.CertificateRevokedException;
import eu.webeid.security.testutil.AuthTokenValidators;
import eu.webeid.security.util.DateAndTime;
import eu.webeid.security.validator.revocationcheck.CertificateRevocationChecker;
Expand Down Expand Up @@ -50,7 +50,9 @@ void tearDown() {
@Test
void whenRevocationCheckFails_thenSignatureIsNotValidated() throws Exception {
CertificateRevocationChecker checker = mock(CertificateRevocationChecker.class);
when(checker.validateCertificateNotRevoked(any(), any())).thenThrow(new UserCertificateRevokedException());
CertificateRevokedException exception = new CertificateRevokedException(mock(X509Certificate.class), null);
when(checker.validateCertificateNotRevoked(any(), any()))
.thenThrow(exception);
AuthTokenValidator validator = AuthTokenValidators.getDefaultAuthTokenValidatorBuilder()
.withCertificateRevocationChecker(checker)
.build();
Expand All @@ -59,7 +61,7 @@ void whenRevocationCheckFails_thenSignatureIsNotValidated() throws Exception {
// An invalid challenge nonce would fail signature validation, so getting the revocation
// failure instead shows that revocation is checked first.
assertThatThrownBy(() -> validator.validate(token, "invalidToken"))
.isInstanceOf(UserCertificateRevokedException.class);
.isInstanceOf(CertificateRevokedException.class);
}

@Test
Expand Down
61 changes: 9 additions & 52 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>authtoken-validation</artifactId>
<artifactId>web-eid-authtoken-validation</artifactId>
<groupId>eu.webeid.security</groupId>
<version>4.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>authtoken-validation</name>
<packaging>pom</packaging>
<name>web-eid-authtoken-validation</name>
<description>Web eID authentication token validation library for Java</description>

<modules>
<module>authtoken-validation</module>
<module>web-eid-ocsp</module>
<module>web-eid-resilient-ocsp</module>
</modules>

<properties>
<java.version>17</java.version>
<jjwt.version>0.13.0</jjwt.version>
Expand Down Expand Up @@ -44,60 +50,11 @@
</properties>

<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-all</artifactId>
<version>${resilience4j.version}</version>
<exclusions>
<exclusion>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-bulkhead</artifactId>
</exclusion>
<exclusion>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-cache</artifactId>
</exclusion>
<exclusion>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-ratelimiter</artifactId>
</exclusion>
<exclusion>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-timelimiter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-vavr</artifactId>
<version>${resilience4j.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
48 changes: 48 additions & 0 deletions web-eid-ocsp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>

Check failure on line 1 in web-eid-ocsp/pom.xml

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

web-eid-ocsp/pom.xml has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'

Check failure on line 1 in web-eid-ocsp/pom.xml

View workflow job for this annotation

GitHub Actions / Check copyright headers / Check copyright headers

web-eid-ocsp/pom.xml has no copyright header matching 'SPDX-FileCopyrightText|Copyright|free software'
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.webeid.security</groupId>
<artifactId>web-eid-authtoken-validation</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>web-eid-ocsp</artifactId>

<dependencies>
<dependency>
<groupId>eu.webeid.security</groupId>
<artifactId>authtoken-validation</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>eu.webeid.security</groupId>
<artifactId>authtoken-validation</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Generate test jar, so test helpers and resources are shared with other modules -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import eu.webeid.ocsp.OcspCertificateRevocationChecker;
import eu.webeid.ocsp.client.OcspClientImpl;
import eu.webeid.ocsp.service.AiaOcspServiceConfiguration;
import eu.webeid.ocsp.service.OcspServiceProvider;
import eu.webeid.ocsp.service.OcspServiceProviderImpl;
import eu.webeid.security.certificate.CertificateValidator;
import eu.webeid.security.validator.AuthTokenValidator;
import eu.webeid.security.validator.AuthTokenValidatorBuilder;
Expand All @@ -86,7 +87,7 @@ AiaOcspServiceConfiguration aiaConfiguration = new AiaOcspServiceConfiguration(
OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE,
true // Require the Key Usage extension in responder certificates.
);
OcspServiceProvider services = new OcspServiceProvider(null, aiaConfiguration);
OcspServiceProvider services = new OcspServiceProviderImpl(null, aiaConfiguration);
OcspCertificateRevocationChecker checker = new OcspCertificateRevocationChecker(
OcspClientImpl.build(Duration.ofSeconds(5)),
services,
Expand Down Expand Up @@ -128,7 +129,7 @@ DesignatedOcspServiceConfiguration designated = new DesignatedOcspServiceConfigu
OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE,
true // Require the Key Usage extension in responder certificates.
);
OcspServiceProvider services = new OcspServiceProvider(designated, aiaConfiguration);
OcspServiceProvider services = new OcspServiceProviderImpl(designated, aiaConfiguration);
```

The provider selects the designated service only when the validated direct issuer certificate equals one of its configured `supportedIssuers`. Supply the same encoded issuer certificates that validation may select as direct issuers; a reissued CA certificate with the same name and key does not match. On a mismatch, the provider uses the certificate's AIA OCSP URL. The designated responder certificate is pinned locally and need not be issued by the CAs it serves.
Expand Down Expand Up @@ -162,7 +163,7 @@ FallbackOcspServiceConfiguration fallback = new FallbackOcspServiceConfiguration
OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE,
true // Require the Key Usage extension in responder certificates.
);
OcspServiceProvider services = new OcspServiceProvider(null, aiaConfiguration, List.of(fallback));
OcspServiceProvider services = new OcspServiceProviderImpl(null, aiaConfiguration, List.of(fallback));
ResilientOcspCertificateRevocationChecker checker = new ResilientOcspCertificateRevocationChecker(
OcspClientImpl.build(Duration.ofSeconds(5)),
services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
import java.util.Map;
import java.util.Objects;

public class OcspServiceProvider {
public class OcspServiceProviderImpl implements OcspServiceProvider {

private final DesignatedOcspService designatedOcspService;
private final AiaOcspServiceConfiguration aiaOcspServiceConfiguration;
private final Map<X509Certificate, FallbackOcspService> fallbackOcspServiceMap;

public OcspServiceProvider(DesignatedOcspServiceConfiguration designatedOcspServiceConfiguration, AiaOcspServiceConfiguration aiaOcspServiceConfiguration) {
public OcspServiceProviderImpl(DesignatedOcspServiceConfiguration designatedOcspServiceConfiguration, AiaOcspServiceConfiguration aiaOcspServiceConfiguration) {
this(designatedOcspServiceConfiguration, aiaOcspServiceConfiguration, null);
}

public OcspServiceProvider(DesignatedOcspServiceConfiguration designatedOcspServiceConfiguration, AiaOcspServiceConfiguration aiaOcspServiceConfiguration, Collection<FallbackOcspServiceConfiguration> fallbackOcspServiceConfigurations) {
public OcspServiceProviderImpl(DesignatedOcspServiceConfiguration designatedOcspServiceConfiguration, AiaOcspServiceConfiguration aiaOcspServiceConfiguration, Collection<FallbackOcspServiceConfiguration> fallbackOcspServiceConfigurations) {
designatedOcspService = designatedOcspServiceConfiguration != null ?
new DesignatedOcspService(designatedOcspServiceConfiguration)
: null;
Expand Down Expand Up @@ -52,6 +52,7 @@ private static Map<X509Certificate, FallbackOcspService> buildFallbackOcspServic
* @return either the designated or AIA OCSP service instance
* @throws UserCertificateOCSPException when the AIA OCSP responder URL cannot be resolved from the certificate
*/
@Override
public OcspService getService(X509Certificate certificate, X509Certificate issuerCertificate) throws UserCertificateOCSPException {
if (designatedOcspService != null && designatedOcspService.supportsIssuer(issuerCertificate)) {
return designatedOcspService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import eu.webeid.ocsp.exceptions.UserCertificateOCSPCheckFailedException;
import eu.webeid.ocsp.service.AiaOcspServiceConfiguration;
import eu.webeid.ocsp.service.DesignatedOcspServiceConfiguration;
import eu.webeid.ocsp.service.OcspServiceProvider;
import eu.webeid.ocsp.service.OcspServiceProviderImpl;
import eu.webeid.security.certificate.CertificateValidator;
import eu.webeid.security.exceptions.CertificateRevocationCheckFailedException;
import eu.webeid.security.exceptions.CertificateRevokedException;
Expand Down Expand Up @@ -256,7 +256,7 @@ private OcspCertificateRevocationChecker customChecker(DesignatedOcspServiceConf
List<X509Certificate> intermediates) throws Exception {
return new OcspCertificateRevocationChecker(
OcspClientImpl.build(Duration.ofSeconds(2)),
new OcspServiceProvider(designated, new AiaOcspServiceConfiguration(Set.of(),
new OcspServiceProviderImpl(designated, new AiaOcspServiceConfiguration(Set.of(),
CertificateValidator.buildTrustAnchorsFromCertificates(anchors),
CertificateValidator.buildCertStoreFromCertificates(intermediates),
OcspCertificateRevocationChecker.DEFAULT_THIS_UPDATE_AGE, OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE, true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public class OcspServiceMaker {
}

public static OcspServiceProvider getAiaOcspServiceProvider() throws JceException {
return new OcspServiceProvider(null, getAiaOcspServiceConfiguration());
return new OcspServiceProviderImpl(null, getAiaOcspServiceConfiguration());
}

public static OcspServiceProvider getAiaOcspServiceProviderWithEsteid2018NonceDisabled() throws JceException {
return new OcspServiceProvider(null, getAiaOcspServiceConfiguration(false));
return new OcspServiceProviderImpl(null, getAiaOcspServiceConfiguration(false));
}

public static OcspServiceProvider getDesignatedOcspServiceProvider() throws CertificateException, IOException, OCSPCertificateException, JceException {
return new OcspServiceProvider(getDesignatedOcspServiceConfiguration(), getAiaOcspServiceConfiguration());
return new OcspServiceProviderImpl(getDesignatedOcspServiceConfiguration(), getAiaOcspServiceConfiguration());
}

public static OcspServiceProvider getDesignatedOcspServiceProvider(boolean doesSupportNonce) throws CertificateException, IOException, JceException, OCSPCertificateException {
return new OcspServiceProvider(getDesignatedOcspServiceConfiguration(doesSupportNonce), getAiaOcspServiceConfiguration());
return new OcspServiceProviderImpl(getDesignatedOcspServiceConfiguration(doesSupportNonce), getAiaOcspServiceConfiguration());
}

public static OcspServiceProvider getDesignatedOcspServiceProvider(String ocspServiceAccessLocation) throws CertificateException, IOException, OCSPCertificateException, JceException {
return getDesignatedOcspServiceProvider(true, ocspServiceAccessLocation);
}

public static OcspServiceProvider getDesignatedOcspServiceProvider(boolean doesSupportNonce, String ocspServiceAccessLocation) throws CertificateException, IOException, OCSPCertificateException, JceException {
return new OcspServiceProvider(getDesignatedOcspServiceConfiguration(doesSupportNonce, ocspServiceAccessLocation), getAiaOcspServiceConfiguration());
return new OcspServiceProviderImpl(getDesignatedOcspServiceConfiguration(doesSupportNonce, ocspServiceAccessLocation), getAiaOcspServiceConfiguration());
}

private static AiaOcspServiceConfiguration getAiaOcspServiceConfiguration() throws JceException {
Expand Down
Loading
Loading