|
@@ -15,10 +15,31 @@ pub async fn handle(db: &Db, req: Request<Body>) -> Result<Response<Body>, Infal
|
|
.body(Body::from("Allow POST"))
|
|
.body(Body::from("Allow POST"))
|
|
.unwrap()),
|
|
.unwrap()),
|
|
_ => match (req.method(), req.uri().path()) {
|
|
_ => match (req.method(), req.uri().path()) {
|
|
|
|
+ #[cfg(feature = "simulation")]
|
|
|
|
+ (&Method::POST, "/nrkey") => Ok::<_, Infallible>({
|
|
|
|
+ // We need a way for simulated users to get the keys to
|
|
|
|
+ // encrypt their negative reports. As Troll Patrol may
|
|
|
|
+ // not be directly accessible when users are submitting
|
|
|
|
+ // negative reports, in practice we expect that these
|
|
|
|
+ // keys will be made available elsewhere.
|
|
|
|
+ let bytes = body::to_bytes(req.into_body()).await.unwrap();
|
|
|
|
+ // Expect the body to contain the date for the key the
|
|
|
|
+ // user requests.
|
|
|
|
+ let date: u32 = match serde_json::from_slice(&bytes) {
|
|
|
|
+ Ok(date) => date,
|
|
|
|
+ Err(e) => {
|
|
|
|
+ let response = json!({"error": e.to_string()});
|
|
|
|
+ let val = serde_json::to_string(&response).unwrap();
|
|
|
|
+ return Ok(prepare_header(val));
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ let pubkey = get_negative_report_public_key(&db, date);
|
|
|
|
+ prepare_header(serde_json::to_string(&pubkey).unwrap())
|
|
|
|
+ }),
|
|
(&Method::POST, "/negativereport") => Ok::<_, Infallible>({
|
|
(&Method::POST, "/negativereport") => Ok::<_, Infallible>({
|
|
let bytes = body::to_bytes(req.into_body()).await.unwrap();
|
|
let bytes = body::to_bytes(req.into_body()).await.unwrap();
|
|
// We cannot depend on the transport layer providing E2EE, so
|
|
// We cannot depend on the transport layer providing E2EE, so
|
|
- // positive reports should be separately encrypted.
|
|
|
|
|
|
+ // negative reports should be separately encrypted.
|
|
let enr: EncryptedNegativeReport = match bincode::deserialize(&bytes) {
|
|
let enr: EncryptedNegativeReport = match bincode::deserialize(&bytes) {
|
|
Ok(enr) => enr,
|
|
Ok(enr) => enr,
|
|
Err(e) => {
|
|
Err(e) => {
|