Skip to content

Commit 6d023f2

Browse files
committed
AUT-2618 Separate issuer certificates from OCSP responder certificates
1 parent 3c27b2a commit 6d023f2

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
package eu.webeid.ocsp.service;
2424

2525
import eu.webeid.ocsp.exceptions.OCSPCertificateException;
26+
import eu.webeid.ocsp.protocol.OcspResponseValidator;
27+
import eu.webeid.security.certificate.CertificateValidator;
2628
import eu.webeid.security.exceptions.AuthTokenException;
29+
import eu.webeid.security.validator.revocationcheck.RevocationMode;
2730
import org.bouncycastle.cert.X509CertificateHolder;
2831
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
2932

3033
import java.net.URI;
34+
import java.security.cert.CertStore;
3135
import java.security.cert.CertificateException;
36+
import java.security.cert.TrustAnchor;
3237
import java.security.cert.X509Certificate;
3338
import java.util.Date;
39+
import java.util.Set;
3440

3541

3642
import static eu.webeid.security.certificate.CertificateValidator.requireCertificateIsValidOnDate;
@@ -42,6 +48,8 @@ public class FallbackOcspService implements OcspService {
4248
private final boolean supportsNonce;
4349
private final X509Certificate trustedResponderCertificate;
4450
private final FallbackOcspService nextFallback;
51+
private final Set<TrustAnchor> trustedCACertificateAnchors;
52+
private final CertStore trustedCACertificateCertStore;
4553

4654
public FallbackOcspService(FallbackOcspServiceConfiguration configuration) {
4755
this.url = configuration.getAccessLocation();
@@ -50,6 +58,8 @@ public FallbackOcspService(FallbackOcspServiceConfiguration configuration) {
5058
this.nextFallback = configuration.getNextFallbackConfiguration() != null
5159
? new FallbackOcspService(configuration.getNextFallbackConfiguration())
5260
: null;
61+
this.trustedCACertificateAnchors = configuration.getTrustedCACertificateAnchors();
62+
this.trustedCACertificateCertStore = configuration.getTrustedCACertificateCertStore();
5363
}
5464

5565
@Override
@@ -66,13 +76,26 @@ public URI getAccessLocation() {
6676
public void validateResponderCertificate(X509CertificateHolder cert, Date now) throws AuthTokenException {
6777
try {
6878
final X509Certificate responderCertificate = certificateConverter.getCertificate(cert);
69-
// Certificate pinning is implemented simply by comparing the certificates or their public keys,
70-
// see https://owasp.org/www-community/controls/Certificate_and_Public_Key_Pinning.
71-
if (!trustedResponderCertificate.equals(responderCertificate)) {
72-
throw new OCSPCertificateException("Responder certificate from the OCSP response is not equal to " +
73-
"the configured fallback OCSP responder certificate");
74-
}
7579
requireCertificateIsValidOnDate(responderCertificate, now, "Fallback OCSP responder");
80+
if (trustedResponderCertificate != null) {
81+
// Certificate pinning is implemented simply by comparing the certificates or their public keys,
82+
// see https://owasp.org/www-community/controls/Certificate_and_Public_Key_Pinning.
83+
if (!trustedResponderCertificate.equals(responderCertificate)) {
84+
throw new OCSPCertificateException("Responder certificate from the OCSP response is not equal to " +
85+
"the configured fallback OCSP responder certificate");
86+
}
87+
return;
88+
}
89+
OcspResponseValidator.validateHasSigningExtension(responderCertificate);
90+
CertificateValidator.validateCertificateTrustAndRevocation(
91+
responderCertificate,
92+
trustedCACertificateAnchors,
93+
trustedCACertificateCertStore,
94+
now,
95+
RevocationMode.DISABLED,
96+
null,
97+
null
98+
);
7699
} catch (CertificateException e) {
77100
throw new OCSPCertificateException("X509CertificateHolder conversion to X509Certificate failed", e);
78101
}

src/main/java/eu/webeid/ocsp/service/FallbackOcspServiceConfiguration.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,37 @@
2626
import eu.webeid.ocsp.protocol.OcspResponseValidator;
2727

2828
import java.net.URI;
29+
import java.security.cert.CertStore;
30+
import java.security.cert.TrustAnchor;
2931
import java.security.cert.X509Certificate;
3032
import java.util.Objects;
33+
import java.util.Set;
3134

3235
public class FallbackOcspServiceConfiguration {
3336

3437
private final URI accessLocation;
3538
private final X509Certificate responderCertificate;
3639
private final boolean doesSupportNonce;
3740
private final FallbackOcspServiceConfiguration nextFallbackConfiguration;
41+
private final String issuerCN;
42+
private final Set<TrustAnchor> trustedCACertificateAnchors;
43+
private final CertStore trustedCACertificateCertStore;
3844

3945
public FallbackOcspServiceConfiguration(URI accessLocation, X509Certificate responderCertificate,
4046
boolean doesSupportNonce,
41-
FallbackOcspServiceConfiguration nextFallbackConfiguration) throws OCSPCertificateException {
47+
FallbackOcspServiceConfiguration nextFallbackConfiguration,
48+
String issuerCN, Set<TrustAnchor> trustedCACertificateAnchors,
49+
CertStore trustedCACertificateCertStore) throws OCSPCertificateException {
4250
this.accessLocation = Objects.requireNonNull(accessLocation, "Fallback OCSP service access location");
43-
this.responderCertificate = Objects.requireNonNull(responderCertificate, "Fallback OCSP responder certificate");
44-
OcspResponseValidator.validateHasSigningExtension(responderCertificate);
51+
this.responderCertificate = responderCertificate;
52+
if (responderCertificate != null) {
53+
OcspResponseValidator.validateHasSigningExtension(responderCertificate);
54+
}
4555
this.doesSupportNonce = doesSupportNonce;
4656
this.nextFallbackConfiguration = nextFallbackConfiguration;
57+
this.issuerCN = issuerCN;
58+
this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors);
59+
this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore);
4760
}
4861

4962
public URI getAccessLocation() {
@@ -61,4 +74,16 @@ public boolean doesSupportNonce() {
6174
public FallbackOcspServiceConfiguration getNextFallbackConfiguration() {
6275
return nextFallbackConfiguration;
6376
}
77+
78+
public String getIssuerCN() {
79+
return issuerCN;
80+
}
81+
82+
public Set<TrustAnchor> getTrustedCACertificateAnchors() {
83+
return trustedCACertificateAnchors;
84+
}
85+
86+
public CertStore getTrustedCACertificateCertStore() {
87+
return trustedCACertificateCertStore;
88+
}
6489
}

src/main/java/eu/webeid/ocsp/service/OcspServiceProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public OcspServiceProvider(DesignatedOcspServiceConfiguration designatedOcspServ
5151
this.aiaOcspServiceConfiguration = Objects.requireNonNull(aiaOcspServiceConfiguration, "aiaOcspServiceConfiguration");
5252
if (fallbackOcspServiceConfigurations != null) {
5353
for (FallbackOcspServiceConfiguration configuration : fallbackOcspServiceConfigurations) {
54-
String issuerCN = getIssuerCommonName(configuration.getResponderCertificate()).orElseThrow(() ->
55-
new RuntimeException("Certificate does not contain issuer CN"));
56-
fallbackOcspServiceMap.put(issuerCN, new FallbackOcspService(configuration));
54+
fallbackOcspServiceMap.put(configuration.getIssuerCN(), new FallbackOcspService(configuration));
5755
}
5856
}
5957
}

0 commit comments

Comments
 (0)