Skip to content

Commit b04c3e6

Browse files
committed
AUT-2709 Collect response time and request duration after a failed OCSP request
1 parent 8e797fb commit b04c3e6

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,18 @@ private RevocationInfo request(OcspService ocspService, X509Certificate subjectC
280280

281281
LOG.debug("Sending OCSP request");
282282
Instant requestTime = Instant.now();
283-
response = requireNonNull(getOcspClient().request(ocspResponderUri, request)); // TODO: This should trigger fallback?
284-
responseTime = Instant.now();
285-
requestDuration = Duration.between(requestTime, responseTime);
283+
try {
284+
response = requireNonNull(getOcspClient().request(ocspResponderUri, request));
285+
responseTime = Instant.now();
286+
requestDuration = Duration.between(requestTime, responseTime);
287+
} catch (OCSPClientException e) {
288+
responseTime = Instant.now();
289+
requestDuration = Duration.between(requestTime, responseTime);
290+
RevocationInfo revocationInfo = getRevocationInfo(ocspResponderUri, e, request, null, requestDuration, responseTime);
291+
revocationInfo.ocspResponseAttributes().put(RevocationInfo.KEY_OCSP_RESPONSE, e.getResponseBody());
292+
revocationInfo.ocspResponseAttributes().put(RevocationInfo.KEY_HTTP_STATUS_CODE, e.getStatusCode());
293+
throw new ResilientUserCertificateOCSPCheckFailedException(new ValidationInfo(subjectCertificate, List.of(revocationInfo)));
294+
}
286295
if (response.getStatus() != OCSPResponseStatus.SUCCESSFUL) {
287296
ResilientUserCertificateOCSPCheckFailedException exception = new ResilientUserCertificateOCSPCheckFailedException("Response status: " + ocspStatusToString(response.getStatus()));
288297
RevocationInfo revocationInfo = new RevocationInfo(ocspService.getAccessLocation(), new HashMap<>(Map.ofEntries(
@@ -333,12 +342,10 @@ private RevocationInfo request(OcspService ocspService, X509Certificate subjectC
333342
// (a definitive OCSP answer, not a transient failure) and no fallback is attempted.
334343
RevocationInfo revocationInfo = getRevocationInfo(ocspResponderUri, e, request, response, requestDuration, responseTime);
335344
throw new ResilientUserCertificateRevokedException(new ValidationInfo(subjectCertificate, List.of(revocationInfo)));
336-
} catch (OCSPClientException e) {
337-
RevocationInfo revocationInfo = getRevocationInfo(ocspResponderUri, e, request, null, null, null);
338-
revocationInfo.ocspResponseAttributes().put(RevocationInfo.KEY_OCSP_RESPONSE, e.getResponseBody());
339-
revocationInfo.ocspResponseAttributes().put(RevocationInfo.KEY_HTTP_STATUS_CODE, e.getStatusCode());
340-
throw new ResilientUserCertificateOCSPCheckFailedException(new ValidationInfo(subjectCertificate, List.of(revocationInfo)));
341345
} catch (Exception e) {
346+
if (e instanceof ResilientUserCertificateOCSPCheckFailedException exception) {
347+
throw exception;
348+
}
342349
RevocationInfo revocationInfo = getRevocationInfo(ocspResponderUri, e, request, response, requestDuration, responseTime);
343350
throw new ResilientUserCertificateOCSPCheckFailedException(new ValidationInfo(subjectCertificate, List.of(revocationInfo)));
344351
}

0 commit comments

Comments
 (0)