Skip to content

Commit 17d74a0

Browse files
committed
AUT-2547 Add support for two fallbacks
1 parent 8da467c commit 17d74a0

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ public OcspService getService(X509Certificate certificate) throws AuthTokenExcep
7676
return new AiaOcspService(aiaOcspServiceConfiguration, certificate, fallbackOcspService);
7777
}
7878

79+
public FallbackOcspService getFallbackService(URI ocspServiceUri) {
80+
return fallbackOcspServiceMap.get(ocspServiceUri);
81+
}
7982
}

src/main/java/eu/webeid/resilientocsp/ResilientOcspCertificateRevocationChecker.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,29 @@ public List<RevocationInfo> validateCertificateNotRevoked(X509Certificate subjec
117117
circuitBreaker.getEventPublisher().onError(event -> createAndAddRevocationInfoToList(event.getThrowable(), revocationInfoList));
118118

119119
CheckedFunction0<RevocationInfo> primarySupplier = () -> request(ocspService, subjectCertificate, issuerCertificate, false);
120-
CheckedFunction0<RevocationInfo> fallbackSupplier = () -> request(ocspService.getFallbackService(), subjectCertificate, issuerCertificate, true);
120+
OcspService firstFallbackService = ocspService.getFallbackService();
121+
CheckedFunction0<RevocationInfo> firstFallbackSupplier = () -> request(firstFallbackService, subjectCertificate, issuerCertificate, true);
122+
OcspService secondFallbackService = getOcspServiceProvider().getFallbackService(firstFallbackService.getAccessLocation());
123+
CheckedFunction0<RevocationInfo> fallbackSupplier;
124+
if (secondFallbackService == null) {
125+
fallbackSupplier = firstFallbackSupplier;
126+
} else {
127+
CheckedFunction0<RevocationInfo> secondFallbackSupplier = () -> request(secondFallbackService, subjectCertificate, issuerCertificate, true);
128+
fallbackSupplier = () -> {
129+
try {
130+
return firstFallbackSupplier.apply();
131+
} catch (Exception e) {
132+
if (e instanceof ResilientUserCertificateOCSPCheckFailedException exception) {
133+
revocationInfoList.addAll((exception.getValidationInfo().revocationInfoList()));
134+
} else {
135+
revocationInfoList.add(new RevocationInfo(null, Map.ofEntries(
136+
Map.entry(RevocationInfo.KEY_OCSP_ERROR, e)
137+
)));
138+
}
139+
return secondFallbackSupplier.apply();
140+
}
141+
};
142+
}
121143
Decorators.DecorateCheckedSupplier<RevocationInfo> decorateCheckedSupplier = Decorators.ofCheckedSupplier(primarySupplier);
122144
if (retryRegistry != null) {
123145
Retry retry = retryRegistry.retry(ocspService.getAccessLocation().toASCIIString());

0 commit comments

Comments
 (0)