Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
make next since header check null safe and add backwards compatibilit…
Browse files Browse the repository at this point in the history
…y for v1/revocationList
  • Loading branch information
ubhaller authored and martinalig committed Aug 20, 2021
1 parent c0d2c39 commit 690c860
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ private Jwks getDSCs() throws URISyntaxException {
ResponseEntity<Jwks> response =
rt.exchange(getRequestEntity(dscEndpoint, params), Jwks.class);
jwkList.addAll(response.getBody().getCerts());
params.put(SINCE_PARAM, response.getHeaders().get(NEXT_SINCE_HEADER).get(0));
done = upToDateHeaderIsTrue(response.getHeaders());

HttpHeaders headers = response.getHeaders();
List<String> nextSince = headers.get(NEXT_SINCE_HEADER);
if (nextSince != null && !nextSince.isEmpty()) {
params.put(SINCE_PARAM, nextSince.get(0));
done = upToDateHeaderIsTrue(headers);
} else { // fallback. exit loop if no next since header sent
done = true;
}

it++;
} while (!done && it < MAX_REQUESTS);
logger.info("downloaded {} DSCs", jwkList.size());
Expand Down Expand Up @@ -157,13 +165,20 @@ private RevokedCertificates getRevokedCerts() throws URISyntaxException {
boolean done = upToDateHeaderIsTrue(response.getHeaders());
int it = 1;
while (!done && it < MAX_REQUESTS) {
params.put(SINCE_PARAM, response.getHeaders().get(NEXT_SINCE_HEADER).get(0));
response =
rt.exchange(
getRequestEntity(revocationEndpoint, params),
RevokedCertificates.class);
addRevokedCerts(revokedCerts, response.getBody());
done = upToDateHeaderIsTrue(response.getHeaders());
HttpHeaders headers = response.getHeaders();
List<String> nextSince = headers.get(NEXT_SINCE_HEADER);
if (nextSince != null && !nextSince.isEmpty()) {
params.put(SINCE_PARAM, nextSince.get(0));
response =
rt.exchange(
getRequestEntity(revocationEndpoint, params),
RevokedCertificates.class);
addRevokedCerts(revokedCerts, response.getBody());
done = upToDateHeaderIsTrue(headers);
} else { // fallback. exit loop if no next since header sent
done = true;
}

it++;
}

Expand All @@ -172,7 +187,9 @@ private RevokedCertificates getRevokedCerts() throws URISyntaxException {
}

private void addRevokedCerts(RevokedCertificates revokedCerts, RevokedCertificates toAdd) {
revokedCerts.getRevokedCerts().addAll(toAdd.getRevokedCerts());
if (revokedCerts != null && toAdd != null) {
revokedCerts.getRevokedCerts().addAll(toAdd.getRevokedCerts());
}
}

/**
Expand Down

0 comments on commit 690c860

Please sign in to comment.