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

Commit 34362c7

Browse files
committed
revert jsonnodes
1 parent 49ff58f commit 34362c7

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

ch-covidcertificate-backend-transformation/ch-covidcertificate-backend-transformation-model/src/main/java/ch/admin/bag/covidcertificate/backend/transformation/model/VerificationResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class VerificationResponse {
1313
private INVALID invalidState;
1414
private DccHolder hcertDecoded;
1515

16-
public VerificationState getSuccessState() {
16+
public SUCCESS getSuccessState() {
1717
return successState;
1818
}
1919

ch-covidcertificate-backend-transformation/ch-covidcertificate-backend-transformation-ws/src/main/java/ch/admin/bag/covidcertificate/backend/transformation/ws/client/VerificationCheckClient.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import ch.admin.bag.covidcertificate.backend.transformation.model.VerificationResponse;
55
import ch.admin.bag.covidcertificate.sdk.core.models.healthcert.DccHolder;
66
import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckSignatureState;
7-
8-
import com.fasterxml.jackson.annotation.JsonValue;
97
import com.fasterxml.jackson.databind.DeserializationFeature;
10-
import com.fasterxml.jackson.databind.JsonNode;
118
import com.fasterxml.jackson.databind.ObjectMapper;
129
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
1310
import com.fasterxml.jackson.module.kotlin.KotlinModule;
@@ -43,7 +40,7 @@ public VerificationCheckClient(String baseurl, String verifyEndpoint) {
4340
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
4441
}
4542

46-
private JsonNode verify(HCertPayload hCertPayload) throws InterruptedException {
43+
private VerificationResponse verify(HCertPayload hCertPayload) throws InterruptedException {
4744
final String hCert;
4845
try {
4946
hCert = objectMapper.writeValueAsString(hCertPayload);
@@ -54,10 +51,13 @@ private JsonNode verify(HCertPayload hCertPayload) throws InterruptedException {
5451
.build();
5552
final HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
5653
if (response.statusCode() != HttpStatus.OK.value()) {
57-
logger.info("Certificate couldn't be decoded: HTTP {}: {}", response.statusCode(), response.body());
54+
logger.info(
55+
"Certificate couldn't be decoded: HTTP {}: {}",
56+
response.statusCode(),
57+
response.body());
5858
return null;
5959
}
60-
return objectMapper.readTree(response.body());
60+
return objectMapper.readValue(response.body(), VerificationResponse.class);
6161
} catch (URISyntaxException | IOException e) {
6262
logger.error("Couldn't verify certificate", e);
6363
return null;
@@ -73,30 +73,12 @@ private JsonNode verify(HCertPayload hCertPayload) throws InterruptedException {
7373
* @param hCertPayload payload as sent with the original request
7474
* @return the decoded certificate if it decodeable and valid, null otherwise
7575
*/
76-
public JsonNode isValid(HCertPayload hCertPayload) throws InterruptedException {
76+
public VerificationResponse isValid(HCertPayload hCertPayload) throws InterruptedException {
7777
final var verificationResponse = verify(hCertPayload);
78-
if (verificationResponse != null && verificationResponse.get("successState")!= null) {
79-
return verificationResponse.get("hcertDecoded");
78+
if (verificationResponse != null && verificationResponse.getSuccessState() != null) {
79+
return verificationResponse;
8080
} else {
8181
return null;
8282
}
8383
}
84-
85-
// /**
86-
// * Decode a client HCert and verify its signature
87-
// *
88-
// * @param hCertPayload payload as sent with the original request
89-
// * @return the decoded certificate if it decodeable and its signature is valid, null otherwise
90-
// */
91-
// public DccHolder isValidSig(HCertPayload hCertPayload) throws InterruptedException {
92-
// final var verificationResponse = verify(hCertPayload);
93-
// if (verificationResponse != null
94-
// && (verificationResponse.getSuccessState() != null
95-
// || (verificationResponse.getInvalidState() != null
96-
// && verificationResponse.getInvalidState().getSignatureState()
97-
// instanceof CheckSignatureState.SUCCESS))) {
98-
// return verificationResponse.getHcertDecoded();
99-
// }
100-
// return null;
101-
// }
10284
}

ch-covidcertificate-backend-transformation/ch-covidcertificate-backend-transformation-ws/src/main/java/ch/admin/bag/covidcertificate/backend/transformation/ws/controller/TransformationController.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
import ch.ubique.openapi.docannotations.Documentation;
2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import java.io.IOException;
24-
import java.net.URISyntaxException;
2524
import java.time.Duration;
2625
import java.time.Instant;
27-
26+
import java.time.ZoneId;
2827
import javax.validation.Valid;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
@@ -84,34 +83,38 @@ public TransformationController(
8483
@PostMapping(path = "/certificateLight")
8584
public @ResponseBody ResponseEntity<CertLightPayload> getCertLight(
8685
@Valid @RequestBody HCertPayload hCertPayload)
87-
throws IOException, URISyntaxException, InterruptedException {
86+
throws IOException, InterruptedException {
8887
// Decode and verify hcert
89-
final var dccHolder = verificationCheckClient.isValid(hCertPayload);
88+
final var validationResponse = verificationCheckClient.isValid(hCertPayload);
89+
final var dccHolder = validationResponse.getHcertDecoded();
9090
if (dccHolder == null) {
9191
return ResponseEntity.badRequest().build();
9292
}
9393

9494
// Create payload for qr light endpoint
95-
var euCert = dccHolder.get("euDGC");
96-
var name = euCert.get("nam");
95+
var euCert = dccHolder.getEuDGC();
96+
var name = euCert.getPerson();
9797

9898
var person = new Person();
99-
person.setFn(name.get("familyName").asText());
100-
person.setGn(name.get("givenName").asText());
101-
person.setFnt(name.get("standardizedFamilyName").asText());
102-
person.setGnt(name.get("standardizedGivenName").asText());
99+
person.setFn(name.getFamilyName());
100+
person.setGn(name.getGivenName());
101+
person.setFnt(name.getStandardizedFamilyName());
102+
person.setGnt(name.getStandardizedGivenName());
103103

104104
var transformPayload = new TransformPayload();
105105
transformPayload.setNam(person);
106-
transformPayload.setDob(euCert.get("dob").asText());
107-
var exp = Instant.ofEpochSecond((int)dccHolder.get("expirationTime").asDouble());
108-
var nowPlus48 = Instant.now().plus(Duration.ofHours(48));
109-
if(nowPlus48.toEpochMilli() < exp.toEpochMilli()) {
110-
transformPayload.setExp(nowPlus48.toEpochMilli());
111-
} else {
112-
transformPayload.setExp(exp.toEpochMilli());
113-
}
114-
106+
transformPayload.setDob(euCert.getDateOfBirth());
107+
108+
var exp =
109+
validationResponse
110+
.getSuccessState()
111+
.getValidityRange()
112+
.getValidUntil()
113+
.atZone(ZoneId.systemDefault())
114+
.toInstant()
115+
.toEpochMilli();
116+
var nowPlus48 = Instant.now().plus(Duration.ofHours(48)).toEpochMilli();
117+
transformPayload.setExp((exp < nowPlus48) ? exp : nowPlus48);
115118

116119
// Get and forward light certificate
117120
var transformResponse =

0 commit comments

Comments
 (0)