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

Commit e1ed7d6

Browse files
committed
dummy success state needs to be a wallet success state. lint
1 parent 5cb161b commit e1ed7d6

File tree

1 file changed

+48
-38
lines changed
  • ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification

1 file changed

+48
-38
lines changed

ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/verification/VerificationService.java

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckRevocationState;
1616
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckSignatureState;
1717
import ch.admin.bag.covidcertificate.sdk.core.models.state.DecodeState;
18-
import ch.admin.bag.covidcertificate.sdk.core.models.state.ModeValidity;
19-
import ch.admin.bag.covidcertificate.sdk.core.models.state.ModeValidityState;
20-
import ch.admin.bag.covidcertificate.sdk.core.models.state.SuccessState.VerifierSuccessState;
2118
import ch.admin.bag.covidcertificate.sdk.core.models.state.SuccessState.WalletSuccessState;
2219
import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState;
2320
import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState.ERROR;
@@ -73,7 +70,9 @@ public class VerificationService {
7370

7471
private final RestTemplate rt;
7572

76-
private static final VerificationState DUMMY_SUCCESS_STATE = new VerificationState.SUCCESS(new VerifierSuccessState(new ModeValidity("", ModeValidityState.UNKNOWN)), false);
73+
private static final VerificationState DUMMY_SUCCESS_STATE =
74+
new VerificationState.SUCCESS(
75+
new WalletSuccessState(false, null, new ArrayList<>(), null, null), false);
7776

7877
@Value("${verifier.baseurl}")
7978
private String verifierBaseUrl;
@@ -89,6 +88,7 @@ public class VerificationService {
8988

9089
@Value("${verifier.api-key:}")
9190
private String apiKey;
91+
9292
private static final String SHOW_RENEW_BANNER = "showRenewBanner";
9393

9494
public VerificationService(RestTemplate rt) {
@@ -110,7 +110,8 @@ public void updateTrustListConfig() {
110110
this.trustListConfig.setTrustList(new TrustList(jwks, revokedCerts, nationalRules));
111111
this.trustListConfig.setRevokedCertificatesRepository(revokedCerts);
112112
this.trustListConfig.setLastSync(Instant.now());
113-
this.trustListConfig.setRenewalTrustList(new TrustList(jwksCh, revokedCerts, nationalRules));
113+
this.trustListConfig.setRenewalTrustList(
114+
new TrustList(jwksCh, revokedCerts, nationalRules));
114115
logger.info("done updating trust list config");
115116
} catch (Exception e) {
116117
logger.error("failed to update trust list config", e);
@@ -124,13 +125,13 @@ public void updateTrustListConfig() {
124125
* @return a JWKs object as required by the SDK-core mapped from a list of ClientCerts
125126
*/
126127
private Jwks getDSCs(String country) throws URISyntaxException {
127-
if(country == null) {
128+
if (country == null) {
128129
logger.info("Updating list of DSCs for all countries");
129-
}else{
130+
} else {
130131
logger.info("Updating list of DSCs for {}", country);
131132
}
132133
Map<String, String> params = getKeyUpdatesParams();
133-
if(country != null){
134+
if (country != null) {
134135
params.put("country", country);
135136
}
136137
List<Jwk> jwkList = new ArrayList<>();
@@ -140,7 +141,7 @@ private Jwks getDSCs(String country) throws URISyntaxException {
140141
final ResponseEntity<Jwks> response =
141142
rt.exchange(getRequestEntity(dscEndpoint, params), Jwks.class);
142143
var body = response.getBody();
143-
if(body != null){
144+
if (body != null) {
144145
jwkList.addAll(body.getCerts());
145146
}
146147

@@ -191,7 +192,7 @@ private RevokedCertificatesRepository getRevokedCerts() throws URISyntaxExceptio
191192
rt.exchange(
192193
getRequestEntity(revocationEndpoint, params), RevokedCertificates.class);
193194
RevokedCertificates revokedCerts = response.getBody();
194-
if(revokedCerts == null){
195+
if (revokedCerts == null) {
195196
logger.error("Failed to get revoked certificates");
196197
throw new NullPointerException("Failed to get revoked certificates");
197198
}
@@ -207,11 +208,11 @@ private RevokedCertificatesRepository getRevokedCerts() throws URISyntaxExceptio
207208
rt.exchange(
208209
getRequestEntity(revocationEndpoint, params),
209210
RevokedCertificates.class);
210-
if(response.getBody() != null) {
211+
if (response.getBody() != null) {
211212
var body = response.getBody();
212-
if(body != null){
213+
if (body != null) {
213214
repo.addCertificates(body.getRevokedCerts());
214-
}else{
215+
} else {
215216
logger.error("Failed to fetch some of the revoked certificates");
216217
}
217218
}
@@ -222,7 +223,7 @@ private RevokedCertificatesRepository getRevokedCerts() throws URISyntaxExceptio
222223

223224
it++;
224225
}
225-
logger.info("downloaded {} revoked certificates", revokedCerts.getRevokedCerts().size());
226+
logger.info("downloaded {} revoked certificates", revokedCerts.getRevokedCerts().size());
226227

227228
return repo;
228229
}
@@ -239,7 +240,7 @@ private RuleSet getNationalRules() throws URISyntaxException {
239240
getRequestEntity(rulesEndpoint, new HashMap<>()),
240241
IntermediateRuleSet.class)
241242
.getBody();
242-
if(intermediateRuleSet == null){
243+
if (intermediateRuleSet == null) {
243244
logger.error("Failed to fetch national rules");
244245
throw new NullPointerException("intermediateRuleSet is null");
245246
}
@@ -267,7 +268,12 @@ private RuleSet getNationalRules() throws URISyntaxException {
267268
.map(rule -> new DisplayRule(rule.getId(), rule.getLogic()))
268269
.collect(Collectors.toList());
269270
ModeRules intermediateModeRules = intermediateRuleSet.getModeRules();
270-
ch.admin.bag.covidcertificate.sdk.core.models.trustlist.ModeRules sdkModeRules = new ch.admin.bag.covidcertificate.sdk.core.models.trustlist.ModeRules(intermediateModeRules.getActiveModes(), intermediateModeRules.getWalletActiveModes(), intermediateModeRules.getVerifierActiveModes(), intermediateModeRules.getLogic());
271+
ch.admin.bag.covidcertificate.sdk.core.models.trustlist.ModeRules sdkModeRules =
272+
new ch.admin.bag.covidcertificate.sdk.core.models.trustlist.ModeRules(
273+
intermediateModeRules.getActiveModes(),
274+
intermediateModeRules.getWalletActiveModes(),
275+
intermediateModeRules.getVerifierActiveModes(),
276+
intermediateModeRules.getLogic());
271277
logger.info("downloaded {} rules", rules.size());
272278

273279
return new RuleSet(
@@ -322,45 +328,49 @@ public VerificationState verifyDccAllModes(CertificateHolder certificateHolder)
322328
: getOutdatedTrustListState(state);
323329
}
324330

325-
public VerificationState verifyDccSingleMode(CertificateHolder certificateHolder, String mode){
331+
public VerificationState verifyDccSingleMode(CertificateHolder certificateHolder, String mode) {
326332
TrustList trustList = trustListConfig.getTrustList();
327333
VerificationState state =
328-
VerifyWrapper.verifyVerifier(certificateVerifier, certificateHolder, trustList, mode);
334+
VerifyWrapper.verifyVerifier(
335+
certificateVerifier, certificateHolder, trustList, mode);
329336
return !trustListConfig.isOutdated() || state instanceof VerificationState.ERROR
330337
? state
331338
: getOutdatedTrustListState(state);
332339
}
333340

334-
335-
336-
337-
public VerificationState verifyDccForRenewal(CertificateHolder certificateHolder){
341+
public VerificationState verifyDccForRenewal(CertificateHolder certificateHolder) {
338342
TrustList trustList = trustListConfig.getRenewalTrustList();
339343
VerificationState state =
340344
VerifyWrapper.verifyWallet(certificateVerifier, certificateHolder, trustList);
341345
String renewBanner = null;
342-
if(state instanceof ERROR || state instanceof LOADING){
346+
if (state instanceof ERROR || state instanceof LOADING) {
343347
return state;
344-
}else if(state instanceof SUCCESS){
345-
renewBanner = ((WalletSuccessState)((SUCCESS) state).getSuccessState()).getShowRenewBanner();
348+
} else if (state instanceof SUCCESS) {
349+
renewBanner =
350+
((WalletSuccessState) ((SUCCESS) state).getSuccessState()).getShowRenewBanner();
346351
} else if (state instanceof INVALID) {
347352
renewBanner = ((INVALID) state).getShowRenewBanner();
348353
}
349-
if(!SHOW_RENEW_BANNER.equals(renewBanner)){
354+
if (!SHOW_RENEW_BANNER.equals(renewBanner)) {
350355
return new INVALID(null, null, null, null, null);
351356
}
352-
//Certain verification failures are accepted in the renewal case as long as it's not revoked
353-
if(state instanceof INVALID && (((INVALID) state).getRevocationState() instanceof CheckRevocationState.SUCCESS)){
357+
// Certain verification failures are accepted in the renewal case as long as it's not
358+
// revoked
359+
if (state instanceof INVALID
360+
&& (((INVALID) state).getRevocationState()
361+
instanceof CheckRevocationState.SUCCESS)) {
354362
var signatureState = ((INVALID) state).getSignatureState();
355363

356-
//As long as the signature is ok, we can ignore rule failures
357-
if(signatureState instanceof CheckSignatureState.SUCCESS){
364+
// As long as the signature is ok, we can ignore rule failures
365+
if (signatureState instanceof CheckSignatureState.SUCCESS) {
358366
state = DUMMY_SUCCESS_STATE;
359-
//If the signature has expired but is otherwise ok, the cert is also approved for renewal
360-
}else if(signatureState instanceof CheckSignatureState.INVALID){
367+
// If the signature has expired but is otherwise ok, the cert is also approved for
368+
// renewal
369+
} else if (signatureState instanceof CheckSignatureState.INVALID) {
361370
var invalidState = (CheckSignatureState.INVALID) signatureState;
362-
if(invalidState.getSignatureErrorCode().equals(
363-
ErrorCodes.SIGNATURE_TIMESTAMP_EXPIRED)){
371+
if (invalidState
372+
.getSignatureErrorCode()
373+
.equals(ErrorCodes.SIGNATURE_TIMESTAMP_EXPIRED)) {
364374
state = DUMMY_SUCCESS_STATE;
365375
}
366376
}
@@ -402,15 +412,15 @@ private VerificationState getOutdatedTrustListState(VerificationState originalSt
402412
new CheckRevocationState.INVALID(TRUST_LIST_OUTDATED),
403413
new CheckNationalRulesState.INVALID(
404414
NationalRulesError.UNKNOWN_RULE_FAILED, false, TRUST_LIST_OUTDATED, ""),
405-
null, "");
415+
null,
416+
"");
406417
}
407418

408-
public List<ActiveModes> getWalletVerificationModes(){
419+
public List<ActiveModes> getWalletVerificationModes() {
409420
return trustListConfig.getTrustList().getRuleSet().getModeRules().getActiveModes();
410421
}
411422

412-
public List<ActiveModes> getVerifierVerificationModes(){
423+
public List<ActiveModes> getVerifierVerificationModes() {
413424
return trustListConfig.getTrustList().getRuleSet().getModeRules().getVerifierActiveModes();
414425
}
415-
416426
}

0 commit comments

Comments
 (0)