Skip to content

Add resilient OCSP certificate revocation checker#99

Open
madislm wants to merge 24 commits intoweb-eid:WE2-1030-use-platform-ocspfrom
madislm:AUT-2514
Open

Add resilient OCSP certificate revocation checker#99
madislm wants to merge 24 commits intoweb-eid:WE2-1030-use-platform-ocspfrom
madislm:AUT-2514

Conversation

@madislm
Copy link
Copy Markdown

@madislm madislm commented Feb 2, 2026

AUT-2514

Signed-off-by: Madis Jaagup Laurson madisjaagup.laurson@nortal.com

@madislm madislm force-pushed the AUT-2514 branch 2 times, most recently from 0e6161a to e927de2 Compare February 2, 2026 09:16
@madislm madislm force-pushed the AUT-2514 branch 5 times, most recently from e96286a to a324e96 Compare February 10, 2026 08:29
@mrts mrts force-pushed the WE2-1030-use-platform-ocsp branch from 10a405b to 74e7af2 Compare February 20, 2026 16:55
@madislm madislm force-pushed the AUT-2514 branch 2 times, most recently from 9cdcc89 to ef4ae35 Compare February 27, 2026 09:35
@mrts mrts force-pushed the WE2-1030-use-platform-ocsp branch from 74e7af2 to f55d636 Compare March 6, 2026 18:37
Comment thread src/main/java/eu/webeid/ocsp/service/FallbackOcspService.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/service/OcspService.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/OcspCertificateRevocationChecker.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/protocol/OcspResponseValidator.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/protocol/IssuerCommonName.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/protocol/IssuerCommonName.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/exceptions/OCSPClientException.java Outdated
Comment thread src/main/java/eu/webeid/ocsp/exceptions/OCSPClientException.java Outdated

@Override
public Optional<FallbackOcspService> getFallbackService() {
return Optional.of(fallbackOcspService);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallbackOcspService can be null, so

Suggested change
return Optional.of(fallbackOcspService);
return Optional.ofNullable(fallbackOcspService);

Optional.of(null) throws NPE while Optional.ofNullable(null) returns Optional.empty().

}
this.doesSupportNonce = doesSupportNonce;
this.nextFallbackConfiguration = nextFallbackConfiguration;
this.issuerDN = issuerDN;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert non-null check here as well, issuerDN can be misconfigured to null:

Suggested change
this.issuerDN = issuerDN;
this.issuerDN = Objects.requireNonNull(issuerDN, "issuerDN");

Comment on lines +59 to +60
this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors);
this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter name to requireNonNull:

Suggested change
this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors);
this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore);
this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors, "trustedCACertificateAnchors");
this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore, "trustedCACertificateCertStore");

Without it you will get a plain NPE with no message, with it a much more clear

java.lang.NullPointerException: trustedCACertificateAnchors

package eu.webeid.ocsp;

import eu.webeid.ocsp.client.OcspClient;
import eu.webeid.ocsp.client.OcspClient;import eu.webeid.ocsp.exceptions.OCSPClientException;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format error, please reformat.

@@ -26,7 +26,11 @@

public record RevocationInfo(URI ocspResponderUri, Map<String, Object> ocspResponseAttributes) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make ocspResponseAttributes immutable with Map.copyOf()?

Also List<RevocationInfo> revocationInfoList should be immutable in ValidationInfo with List.copyOf().

Comment on lines +11 to +18
public static Optional<X500Name> getIssuerDistinguishedName(X509Certificate certificate) {
Objects.requireNonNull(certificate, "certificate");
String issuerDN = certificate.getIssuerX500Principal().getName();
if (issuerDN.isEmpty()) {
return Optional.empty();
}
return Optional.of(new X500Name(issuerDN));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, getIssuerX500Principal() does not return null for a valid X509Certificate, so Optional is probably not justified.

A cleaner helper that does not rely on string parsing would be:

Suggested change
public static Optional<X500Name> getIssuerDistinguishedName(X509Certificate certificate) {
Objects.requireNonNull(certificate, "certificate");
String issuerDN = certificate.getIssuerX500Principal().getName();
if (issuerDN.isEmpty()) {
return Optional.empty();
}
return Optional.of(new X500Name(issuerDN));
}
public static X500Name getIssuerDistinguishedName(X509Certificate certificate) {
Objects.requireNonNull(certificate, "certificate");
return X500Name.getInstance(certificate.getIssuerX500Principal().getEncoded());
}

Comment on lines +296 to +305
ResilientUserCertificateOCSPCheckFailedException exception = new ResilientUserCertificateOCSPCheckFailedException("Response status: " + ocspStatusToString(response.getStatus()));
RevocationInfo revocationInfo = new RevocationInfo(ocspService.getAccessLocation(), new HashMap<>(Map.ofEntries(
Map.entry(RevocationInfo.KEY_OCSP_ERROR, exception),
Map.entry(RevocationInfo.KEY_OCSP_REQUEST, request),
Map.entry(RevocationInfo.KEY_OCSP_RESPONSE, response),
Map.entry(RevocationInfo.KEY_REQUEST_DURATION, requestDuration),
Map.entry(RevocationInfo.KEY_OCSP_RESPONSE_TIME, responseTime)
)));
exception.setValidationInfo(new ValidationInfo(subjectCertificate, List.of(revocationInfo)));
throw exception;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other error cases below, the code could be simplified and made immutable-friendlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants