|
@@ -3,11 +3,12 @@
|
|
|
|
|
|
use crate::{get_date, CONFIG, COUNTRY_CODES};
|
|
|
|
|
|
-use curve25519_dalek::Scalar;
|
|
|
+use curve25519_dalek::{RistrettoPoint, Scalar};
|
|
|
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
|
|
use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey};
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
use sha1::{Digest, Sha1};
|
|
|
+use sha2::Sha512;
|
|
|
use std::option::Option;
|
|
|
|
|
|
#[derive(Debug)]
|
|
@@ -16,6 +17,7 @@ pub enum PositiveReportError {
|
|
|
FailedToDeserialize, // couldn't deserialize to SerializablePositiveReport
|
|
|
InvalidBridgeToken,
|
|
|
InvalidCountryCode,
|
|
|
+ InvalidLoxProof,
|
|
|
MissingBridgeToken,
|
|
|
MissingCountryCode,
|
|
|
}
|
|
@@ -130,7 +132,9 @@ impl PositiveReport {
|
|
|
}
|
|
|
}
|
|
|
// Verify knowledge of bucket ID
|
|
|
- let H = self.lox_proof.H;
|
|
|
+ let H = RistrettoPoint::hash_from_bytes::<Sha512>(
|
|
|
+ format!("{}{}", lox_pr::H_GENERATOR_STRING, self.lox_proof.date).as_bytes(),
|
|
|
+ );
|
|
|
let BP = self.lox_proof.BP;
|
|
|
if bucket * H != BP {
|
|
|
return false;
|
|
@@ -162,9 +166,13 @@ impl SerializablePositiveReport {
|
|
|
if !COUNTRY_CODES.contains(self.country.as_str()) {
|
|
|
return Err(PositiveReportError::InvalidCountryCode);
|
|
|
}
|
|
|
- if self.date > get_date().into() {
|
|
|
+ let date: u32 = get_date().into();
|
|
|
+ if self.date > date {
|
|
|
return Err(PositiveReportError::DateInFuture);
|
|
|
}
|
|
|
+ if self.lox_proof.date != date {
|
|
|
+ return Err(PositiveReportError::InvalidLoxProof);
|
|
|
+ }
|
|
|
let bridge_token = if self.bridge_token.is_none() {
|
|
|
None
|
|
|
} else {
|