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

Commit

Permalink
Merge pull request #180 from admin-ch/release/4.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gstoehld authored Oct 13, 2022
2 parents 2b8e5ee + da3d156 commit 4a2bf8d
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"EU/1/21/1624",
"VLA2001",
"Convidecia"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"EU/1/21/1624",
"VLA2001",
"Convidecia"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let COVOVAX = "Covovax";
let CORV_T = "BBIBP-CorV_T";
let CORONAVAC_T = "CoronaVac_T";
let COVAXIN_T = "Covaxin_T";
let VALNEVA = "VLA2001";
let VALNEVA_LEGACY = "VLA2001";
let VALNEVA = "EU/1/21/1624";
let CONVIDECIA = "Convidecia";

let ALL_VACCINES = [
Expand All @@ -35,6 +36,7 @@ let ALL_VACCINES = [
CORONAVAC_T,
COVAXIN_T,
VALNEVA,
VALNEVA_LEGACY,
CONVIDECIA
];

Expand All @@ -55,6 +57,7 @@ let TWO_DOSE_VACCINES = [
CORV_T,
CORONAVAC_T,
COVAXIN_T,
VALNEVA_LEGACY,
VALNEVA
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"EU/1/21/1624",
"VLA2001",
"Convidecia"
]
Expand Down Expand Up @@ -840,7 +841,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down Expand Up @@ -967,7 +969,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"EU/1/21/1624",
"VLA2001",
"Convidecia"
]
Expand Down Expand Up @@ -1220,7 +1221,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down Expand Up @@ -1384,7 +1386,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
}
Expand Down Expand Up @@ -2626,7 +2629,8 @@
"BBIBP-CorV_T",
"CoronaVac_T",
"Covaxin_T",
"VLA2001"
"VLA2001",
"EU/1/21/1624"
]
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ch.admin.bag.covidcertificate.backend.verifier.model.DbRevokedCert;
import ch.admin.bag.covidcertificate.backend.verifier.model.RevocationResponse;
import ch.ubique.openapi.docannotations.Documentation;
import java.nio.file.Files;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -30,6 +31,12 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.HttpStatusCodeException;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.InputStream;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;

@Controller
@RequestMapping("trust/v2")
@Documentation(description = "Endpoint to obtain the list of revoked certificates")
Expand All @@ -39,11 +46,28 @@ public class RevocationListControllerV2 {

private static final String NEXT_SINCE_HEADER = "X-Next-Since";
private static final String UP_TO_DATE_HEADER = "up-to-date";
private final byte[] revocationDb;
private final String revocationDbNextSince;

private final RevokedCertDataService revokedCertDataService;

public RevocationListControllerV2(RevokedCertDataService revokedCertDataService) {
this.revokedCertDataService = revokedCertDataService;
ClassPathResource dbFile =
new ClassPathResource("revocations.sqlite");
byte[] revocationDb;
String revocationDbNextSince;
try{
revocationDb = dbFile.getInputStream().readAllBytes();
revocationDbNextSince = new ObjectMapper()
.readTree(new ClassPathResource("revocation_metadata.json").getInputStream()).get("nextSince").asText();
}catch(IOException e){
logger.warn("Could not read revocation SQLite DB");
revocationDb = null;
revocationDbNextSince = null;
}
this.revocationDb = revocationDb;
this.revocationDbNextSince = revocationDbNextSince;
}

@Documentation(
Expand All @@ -68,6 +92,22 @@ public RevocationListControllerV2(RevokedCertDataService revokedCertDataService)
.body(new RevocationResponse(revokedUvcis));
}

@Documentation(
description = "get (pruned) database of revocations",
responses = {"200 => current database as of last deployment"},
responseHeaders = {
"X-Next-Since:`since` to set for next request:string"
})
@CrossOrigin(origins = {"https://editor.swagger.io"})
@GetMapping(value = "/revocationDb")
public @ResponseBody ResponseEntity<byte[]> getRevocationDb() throws IOException{
if(revocationDb == null){
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok().header(NEXT_SINCE_HEADER, revocationDbNextSince).body(revocationDb);
}


private HttpHeaders getRevokedCertsHeaders(List<DbRevokedCert> revokedCerts, Instant now) {
HttpHeaders headers =
CacheUtil.createExpiresHeader(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
import json
import io
import time

isFinished = False
since = "0"
certs = []
validDuration = 0

while isFinished == False:
try:
response = requests.get(
url="https://www.cc.bit.admin.ch/trust/v2/revocationList",
params= {"since": since} if since != "0" else {} ,
headers={
"Accept": "application/json",
"Authorization": "Bearer 0795dc8b-d8d0-4313-abf2-510b12d50939",
},
)
jsonResponse = response.json()
certs.extend(jsonResponse["revokedCerts"])
validDuration = jsonResponse["validDuration"]
since = response.headers["X-Next-Since"]
isFinished = response.headers["Up-To-Date"] == "true"
except requests.exceptions.RequestException:
print('HTTP Request failed')

with open('revocations.csv', 'w') as file:
file.write('\n'.join(certs))


data = {
"validDuration": validDuration,
"lastDownload": round(time.time() * 1000),
"nextSince": since
}

with open('revocation_metadata.json', 'w') as f:
json.dump(data, f)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"validDuration": 172800000, "lastDownload": 1665473995987, "nextSince": "11843609"}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@
"version": "1.8"
},
"VLA2001": {
"display": "VLA2001",
"display": "VLA2001 (deprecated)",
"lang": "en",
"active": true,
"active": false,
"system": "http://ec.europa.eu/temp/vaccineproductname",
"version": "1.8"
},
Expand Down Expand Up @@ -281,6 +281,13 @@
"active": true,
"system": "http://ec.europa.eu/temp/vaccineproductname",
"version": "1.10"
},
"EU/1/21/1624": {
"display": "COVID-19 Vaccine Valneva",
"lang": "en",
"active": true,
"system": "https://ec.europa.eu/health/documents/community-register/html/",
"version": ""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testUnsortedListEtag() {

@Test
public void testFileHash() throws Exception {
String expected = "W/\"26ae209fb88525d3cdbb7fdaf0ffe6a26aa00089\"";
String expected = "W/\"efafab6552384bc2e12194c9456af0b4cdc0e208\"";
String sha1 = EtagUtil.getSha1HashForFiles(true, PATH_TO_VERIFICATION_RULES);
assertEquals(expected, sha1);
assertNotEquals(
Expand All @@ -48,7 +48,7 @@ public void testFileHash() throws Exception {

@Test
public void testFileHashMultiple() throws Exception {
String expected = "W/\"94261230f884b347f2edc72de643ef8e5be383bc\"";
String expected = "W/\"a6404df46692b7286374fe329d5cb5183a7c79c7\"";
List<String> pathsToValueSets =
List.of(
"classpath:valuesets/test-manf.json",
Expand Down
12 changes: 12 additions & 0 deletions update_resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -xeu
cd "$(dirname "$0")" || exit
python3 ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/resources/dump_revocations.py
sqlite3 revocations.sqlite "CREATE TABLE revocations ( uvci text NOT NULL );" ".mode csv" ".import revocations.csv revocations"
sqlite3 revocations.sqlite "CREATE TABLE \"metadata\" (\"validDuration\" integer NOT NULL DEFAULT '0',\"lastDownload\" integer NOT NULL DEFAULT '0',\"nextSince\" text);"
sqlite3 revocations.sqlite "INSERT INTO \"metadata\" (validDuration, lastDownload, nextSince) VALUES ($(cat revocation_metadata.json | jq .validDuration), $(cat revocation_metadata.json | jq .lastDownload), $(cat revocation_metadata.json | jq .nextSince));"
rm revocations.csv
mv revocations.sqlite ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/resources/
mv revocation_metadata.json ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/resources/

./ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-valuesets/src/main/resources/test_rules.sh

0 comments on commit 4a2bf8d

Please sign in to comment.